Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Simultaneous sample limit?

This thread is locked; no one can reply to it. rss feed Print
Simultaneous sample limit?
Trent Gamblin
Member #261
April 2000
avatar

Is there a limit on the number of samples that can be played at the same time? I'm using Linux and have tried the OSS and ALSA drivers but I seem to only be able to play 8 samples at a time. In the following code the "blast" sample cannot be heard unless I play only 7 or less "bolt" samples:

1#include <allegro.h>
2 
3int main(void)
4{
5 int i;
6 
7 allegro_init();
8 install_sound(DIGI_ALSA, MIDI_NONE, 0);
9 install_keyboard();
10 set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
11 SAMPLE* blast;
12 blast = load_wav("blast.wav");
13 SAMPLE* bolts[8];
14 for (i = 0; i < 8; i++)
15 bolts<i> = load_wav("bolt.wav");
16 printf("%d\n", play_sample(blast, 255, 128, 1000, 0));
17 for (i = 0; i < 8; i++)
18 printf("%d\n", play_sample(bolts<i>, 20, 128, 1000, 0));
19 while (!keypressed())
20 ;
21 allegro_exit();
22 return 0;
23}

They are all getting a unique voice. And as you can see I'm playing the bolt sample at a much lower volume. I haven't tried this on Windows. Any advice or information would be appreciated. Thanks.

Kitty Cat
Member #2,815
October 2002
avatar

reserve_voices
Clicky. :) Although I think that note about sound quality is a bit misleading. Since the mixer rewrite in 4.1.x, reserving voices won't decrease the overall quality. However, trying to play too many sounds so that the mixed samples overflow the data range will cause distortion since the values need to be clamped to 16-bit values. You may also want to look at:
set_volume_per_voice

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Trent Gamblin
Member #261
April 2000
avatar

Ah, thanks very much. Now I have another question. :)
What is a safe amount of voices to reserve? I would like to reserve 16 but 12 would probably be enough. Are those values supported widely enough? I'm not planning on bending over backwards for DOS compatability but I'd like my game to run well on fairly modern Windows and Linux (and maybe in the future Mac) computers. Thanks for the help!

Matt Smith
Member #783
November 2000

It is/was common to use powers of 2, up to 64 as a reasonable max. This was so the old mixer could shift the values down and guarantee the accumulated values couldn't overflow.

There has been a lot of experimental work in compressing the dynamic range of the output (in DUMB, which has been the prototype for the new mixer) so the quality may improve and the restrictions may disappear completely.

The short answer is that 16 voices is fine.

Trent Gamblin
Member #261
April 2000
avatar

Great. I'll bump it up to 32 and keep in mind that I could use 64 in the future. Thanks.

[edit]
If 64 is reasonable I guess I'll just use that and save myself some time later. :)

Go to: