Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Set audio buffer chunk size?

This thread is locked; no one can reply to it. rss feed Print
Set audio buffer chunk size?
Tumlee
Member #15,061
April 2013

When testing out a game I'm making with Allegro 5, I couldn't help but notice that the timing on a rapidly-playing (about 5 times per second) sound seemed "off". What I mean by this is that the sound wasn't playing at a constant rhythm, but rather erratically changing the timing between each sound.

Back when I was working with SDL, there was an option you could set when creating initializing the audio that was essentially the size of a "chunk" of audio. This is a completely different thing than the frequency and its normal value was usually around 2048. Making this value a high number would reduce the instance of pops and crackles that might happen on slower computers, but it caused horrid timing issues like the one I described above. Likewise, lowering the value made crackling more likely to happen, but it almost completely fixed any timing issues I was having.

Is there a way to adjusting this sort of setting in Allegro 5? I read through the API but the only thing that looked promising were the 'fragment_count' and 'samples' arguments to al_create_audio_stream(). I don't think this is what I'm looking for, though, because I'm not sure you can even play sound effects to an audio stream.

Peter Wang
Member #23
April 2000

Not in a systematic way, but that would be nice to have. The DirectSound driver's buffer size can be set through the allegro5.cfg file, under key directsound.buffer_size.

Edgar Reynaldo
Member #8,592
May 2007
avatar

al_create_audio_stream accepts a frag_samples parameter - this is essentially your buffer size, in number of samples per fragment (fragment_count) per audio stream.

The choice of fragment_count, frag_samples and freq directly influences the audio delay. The delay in seconds can be expressed as:

delay = fragment_count * frag_samples / freq

This is only the delay due to Allegro's streaming, there may be additional delay caused by sound drivers and/or hardware.

Tumlee
Member #15,061
April 2013

al_create_audio_stream accepts a frag_samples parameter - this is essentially your buffer size, in number of samples per fragment (fragment_count) per audio stream

Is it possible to pump calls to al_play_sample() through an audio stream, though? Otherwise, it really doesn't help me.

Not in a systematic way, but that would be nice to have.

If it would be nice to have, should I throw out a feature request for it? Or is there some underlying reason why it can't be done directly through Allegro?

I guess I'll just take your suggestion, though. It probably won't help any Linux users but it sounds like it will at least solve that problem under Windows.

Peter Wang
Member #23
April 2000

It's not hard, just work. Also unsure how to expose it through the API but maybe that can come later.

Thomas Fjellstrom
Member #476
June 2000
avatar

Tumlee said:

I'm not sure you can even play sound effects to an audio stream.

You can play anything you want through a stream. At the lower levels there is no real conceptual difference, other than allegro does the streaming for you when using sample instances.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Tumlee
Member #15,061
April 2013

You can play anything you want through a stream. At the lower levels there is no real conceptual difference, other than allegro does the streaming for you when using sample instances.

From what I understand from the API guide, you can load and play a sound as an audio stream, but that's not the same thing as playing multiple sample instances through an already-running audio stream, and I don't think that's what they're for. I'm probably not going to solve any lag issues unless I can change the buffer size of the actual mixer.

Go to: