Streaming Audio

BlitzMax Forums/BlitzMax Programming/Streaming Audio

GfK(Posted 2008) [#1]
What options are currently available?

I just looked at MaxMod2 Beta 4 but it seems to crackle horribly when other stuff (i.e. Firefox) is running. I tried MaxMod 1.25 and that was the same.

I don't want to have to pay out for something like FMOD or BASS to do this. The cost is one issue, figuring out how to do it is another.

[edit] Just noticed that MaxMod 1.25 seems to work fine with DirectSound, but is this a safe/reliable driver to use? OpenAL is v crackly.


GaryV(Posted 2008) [#2]
AUDIERE

http://audiere.sourceforge.net/

It works great


GfK(Posted 2008) [#3]
Is this what you're using?


GaryV(Posted 2008) [#4]
Yes, but I am using it with another language. (So far with BM, I have only done apps.) It also seems to work well on the Vista systems I have tested it on.


GfK(Posted 2008) [#5]
Ah. No idea at all how to get that going in Blitzmax. :/


ImaginaryHuman(Posted 2008) [#6]
Is there a way to allocate a large memory bank (big enough for your audio file), spawn a new thread that loads the audio into the bank space, while another thread (or main thread) plays the audio? The only thing non-streaming about it would be that you are using more memory than just some buffer, you'd need space for the whole audio in ram - but if the playing is slower than the file access speed it should be okay? That would at least let you play from the start - but then, I'm not sure that you can play the audio that's in a bank?


GfK(Posted 2008) [#7]
Is there a way to allocate a large memory bank (big enough for your audio file), spawn a new thread that loads the audio into the bank space, while another thread (or main thread) plays the audio? The only thing non-streaming about it would be that you are using more memory than just some buffer, you'd need space for the whole audio in ram
Isn't that the same as just using LoadSound?

Or are you suggesting that there's some way of loading an OGG file into a bank, and decompressing it piece by piece into smaller buffers and playing it from there?


Perturbatio(Posted 2008) [#8]
Ah. No idea at all how to get that going in Blitzmax. :/


It's simple really, just mention this thread to Brucey ;)


ImaginaryHuman(Posted 2008) [#9]
I guess I wasn't thinking about the impact of decompression. Basically I thought that you could start the file loading in a separate thread and then start playing it before it's finished loading. But that's going to require two things: a) A way to load the audio data into a memory bank or area of allocated memory, and b) a way to play the audio located at that address - which will probably involve decompression.

I presume long pieces of ogg music are not all copied to the sound card at once, but are spooled off as needed by the driver or something, since they are mainly stored in main ram? And I presume that the ogg decompressor mainly thinks about a local area of the ogg datastream when trying to decompress the next chunk of audio? If that's the case - if the decompression proceeds through the file more or less sequentially, then it could be decompressing while the file data is loading, and if can do that it could be playing it. Just a matter of whether there are sufficient commands to load into memory and play at the same time.

e.g. Can you do LoadSound() in one thread and have it start loading the audio file, but not finish loading, while another thread calls PlaySound() with the same audio data? Does LoadSound need to finish first to pass the handle back for PlaySound to use, or is there some other way to do it?

Another option, and this is perhaps best left to BRL, is for them to modify LoadSound so that it spawns a thread to do the loading, detaches the thread, then returns with the handle to the object so that you can call PlaySound right away while it's still loading.

Another question though, how long does it actually take to load the piece of audio that you're trying to load? A few seconds? Isn't the loading of it something that can be done while some splash screen or menu is being operated or something?


REDi(Posted 2008) [#10]

MaxMod2 Beta 4 but it seems to crackle horribly when other stuff (i.e. Firefox) is running.



Hmm I'll look into that, is this on your slow test machine?
As you probably noticed I swapped to using RtAudio instead of writing all the audio drivers myself, hopefully I'll be able to increase the buffer size for dsound and make it more stable, we sorted it okay for my original dsound driver so it should be no big deal.

Is there a way to allocate a large memory bank (big enough for your audio file), spawn a new thread that loads the audio into the bank space, while another thread (or main thread) plays the audio?


MaxMod2 already allows you to stream the audio into memory, there is a demo app in the examples folder, the problem is none of the audio drivers allow you to play from existing data (they all duplicate the audio data before playing it).

So to combat this I've been writing another audio driver (hence the delay) that handles streaming and playing sound through a single audio output. This plays the audio samples direct from the TAudioSample object, allowing us to stream the loading and play the audio at the same time :)

The new driver also adds some nice extras like loop points for channels, changing the play cursors position (seeking) on a channel, ect.

BTW if anybody has any ideas/requests, I'm all ears.


GfK(Posted 2008) [#11]
Hmm I'll look into that, is this on your slow test machine?
No. Tested on two systems:

1. Athlon XP3000+ 2.16GHz, 1.5GB RAM, Vista Home Premium
2. Intel Dual Core @ 2x1.4GHz, 2GB RAM, Vista Home Premium

I noticed another problem with Maxmod.

If I use CreateAudioStream with the 'paused' flag set to True, its ignored when using OpenAL and the track starts playing immediately, yet it works OK when using DirectSound.

I think this 'RTAudio' thing may be part if not all of the problem with the crackling thing. I used maxmod (1.16?) for Buzzword with OpenAL, on System #1 above, and didn't observe any problms.


plash(Posted 2008) [#12]
I would think the issue is using threading, other processes take up a lot of cpu when performing tasks and the thread for audio handling is low-priority.


GfK(Posted 2008) [#13]
I would think the issue is using threading, other processes take up a lot of cpu when performing tasks and the thread for audio handling is low-priority.
Don't know about REDi but I've not been anywhere near the threading stuff in Blitzmax.


REDi(Posted 2008) [#14]
I noticed another problem with Maxmod.

Okay I'll take a peek and post an update soon. *EDIT* done ;)

I would think the issue is using threading

Yeah pretty much, that and the circular buffer size, its a bit of a juggling act between stability and latency, nothing that cant be sorted though.


GfK(Posted 2008) [#15]
Does latency become less of an issue if you stream from RAM rather than HD?

Also, any ETA on when the OpenAL crackly problem can be mendid? :)


REDi(Posted 2008) [#16]
Does latency become less of an issue if you stream from RAM rather than HD?

Dunno, I wouldn't have thought there's much in it tbh, easy enough to test though.

Also, any ETA on when the OpenAL crackly problem can be mendid? :)

Oops I missed that bit, I'll 'ave a tinker in a bit.

*EDIT* 1.27 download is up, it *MAY* fix your OpenAL crackle, the buffer size was pretty big anyway so I didn't adjust that, but if this doesn't fix it I may have to.


GfK(Posted 2008) [#17]
Thanks Cliff - working perfectly now on my Intel Dual Core system. Should get time to test it on the XP3000+ later.


GfK(Posted 2008) [#18]
Right - this is interesting (Maxmod 1.27).

1. Pentium Dual Core @ 2x1.4GHz, 2GB RAM, Vista Home Premium - OK
2. Athlon XP3000+ @ 2.16GHz, 1.5GB RAM, Vista Home Premium - CRACKLY
3. P3-733MHz, 256MB RAM, WindowsXP - OK

Beginning to think there's some slight oddity between MaxMod/OpenAL/Vista.

When testing on system #2 above, even having taskmanager open is enough to make it cough every time the taskmanager window refreshes (~once per sec).


REDi(Posted 2008) [#19]
Strange! I'm flat out busy ATM, but I'll have a look when I've got some time.


GfK(Posted 2008) [#20]
Good news..... kind of. The crackling problem is nothing to do with MaxMod.

I just wrote some code that uses LoadSound instead and get exactly the same problem.