Streaming playback / loading of incbin'd ogg

BlitzMax Forums/BlitzMax Programming/Streaming playback / loading of incbin'd ogg

Raz(Posted 2012) [#1]
Hi there,

can I stream the playback of an incbin'd ogg file, or at the very least stream the loading of an incbin'd ogg file ready for it to be played?

Ta!
-Chris

Last edited 2012


GfK(Posted 2012) [#2]
What I do with MaxMod2 (which is three years out of date now but still works if you get a version of MinGW it'll play nice with), is load the OGG file into a bank, and stream it from there. That way there's no ongoing hard drive access, and the only resources you use are a bank the size of the OGG file, plus a little extra for the playback buffer.

I'm sure MaxMod2 does allow you to play a streamed OGG direct with incbin, but the above method is much more sensible.


Raz(Posted 2012) [#3]
Hi Gfk, so does that mean... let's say you have 5 ogg tracks. You load them all in to banks at the start and then play them when required?

Is that much different from me just loading all 5 tracks with LoadSound at the start and then just accessing them as required?


xlsior(Posted 2012) [#4]
IIRC using LoadSound will decompress the .ogg into memory while it's loaded, which takes up -significantly-more RAM plus it will freeze the program while it decompresses the entire file all at once.


Raz(Posted 2012) [#5]
Got ya, thank you :)


Raz(Posted 2012) [#6]
Because I am building a blitzmax app from Monkey generated code, I would ideally not include other modules at this time but...

I've loaded the ogg files in to banks and I now want to call LoadSound() by supplying the bank. Is that possible?

Kinda like...

Global BankedTrack1:TBank = LoadBank("inc::data/music/1.ogg")

Function PlayTrack1()
    PlaySample(LoadSound(GET_BANK_CONTENTS), MUSIC_CHANNEL, flags)
EndFunction



GfK(Posted 2012) [#7]
Just pass the bank handle to LoadSound().

mySound:TSound = LoadSound(bankedTack1)



Raz(Posted 2012) [#8]
Ahh good, I was doing the right thing.

I'm still getting around a 2 second pause as LoadSound is called, which I wasn't expecting really seeing as the sound should be getting loaded from memory (instead of accessing the EXE on the hard drive).

Last edited 2012


GfK(Posted 2012) [#9]
You will, Loadsound loads and decompresses the entire file so the bigger it is, the longer it takes. It's the decompression that takes the time, not the actual loading of the file.


Raz(Posted 2012) [#10]
Got ya, cheers GfK, so basically to avoid the load pause, I need to either load all oggs as TSounds in to memory, or use MaxMod to stream the ogg files directly.


Raz(Posted 2012) [#11]
(p.s. how do YOU stream an ogg from a bank? ;)


GfK(Posted 2012) [#12]
I use MaxMod2 which (without looking at my code) I think has a PlayMusic(bankHandle) function which does it automagically. Don't get me wrong, MaxMod2 is great, it just doesn't seem to like certain versions of MinGW (build 8 from nuwen.net is fine with it).

http://code.google.com/p/maxmod/


Raz(Posted 2012) [#13]
Woop! Just got the very same thing sorted.

To get MaxMod2 working I had to...

copy MinGW/lib/libdsound.a to BlitzMax/lib/

and add the line

#include <stdio.h>


to the very top of blitzmax\mod\maxmod2.mod\maxmod2.mod\code

Sorted! :D


Danny(Posted 2012) [#14]
What I do is right after loading a sound is: set the volume to zero, play the sound and stop it immediately -on the next line!

Using this I can force all the loading (AND decompression!) time to the start (loading) stage of my app - and so prevent it freezing at whatever point I might actually want to play a given sound..

Danny.


GfK(Posted 2012) [#15]
Why? All of the decompression is done during LoadSound anyway so by playing then stopping the sound, you're not actually achieving anything.