Multiple audio stream causes static?
BulletDave4

For the past few days, I have been working hard on adding an audio system to my game. So far, I have managed to set-up two different audio systems.

The first is specialized for songs since they can be large. Note: all of my audio files are .ogg files. For the songs, I load them into an ALLEGRO_AUDIO_STREAM.

The second is designed for sound effects. Note: they are also .ogg files. This time around I use an ALLEGRO_SAMPLE_INSTANCE.

For some odd reason, when I play a song with multiple sound effects, I get static. I tried on other computers and on my headphones and its the same issue.

I tried isolating the issue with little luck. All I noticed is that if I play a single sound, be it a song, or a sound effect, it will be clear, and the moment I begin adding other audio, it begins to fill-up with static.

Note: For each song I am creating a new AUDIO_STREAM, MIXER, and VOICE. For each sound, I am creating a new MIXER, VOICE, SAMPLE, SAMPLE INSTANCE, AUDIO STREAM. I don't really know if its a bad thing having that many mixers/voices/samples.

Here is how I create my song class:

#SelectExpand
1CSong::CSong( const char* filename, uint frequency, 2 size_t bufferCount, uint samples ) : 3 m_mixer(NULL), m_voice(NULL), m_stream(NULL) 4{ 5 m_voice = al_create_voice( frequency, ALLEGRO_DEPTH_INT16, 6 ALLEGRO_CHANNEL_CONF_2 ); 7 m_mixer = al_create_mixer( frequency, ALLEGRO_DEPTH_FLOAT32, 8 ALLEGRO_CHANNEL_CONF_2 ); 9 al_attach_mixer_to_voice( m_mixer, m_voice ); 10 11 m_stream = al_load_audio_stream( filename, bufferCount, samples ); 12 al_attach_audio_stream_to_mixer( m_stream, m_mixer ); 13 14 al_set_audio_stream_playmode( m_stream, ALLEGRO_PLAYMODE_LOOP ); 15 16 setPlay( false ); 17}

And here is how I create my sound class:

#SelectExpand
1CSound::CSound( const char* filename ) : 2 m_mixer(NULL), m_voice(NULL), 3 m_sample(NULL), m_sampleInstance(NULL), 4 m_position(0), m_audioStream(NULL) 5{ 6 m_voice = al_create_voice( 44100, ALLEGRO_AUDIO_DEPTH_INT16, 7 ALLEGRO_CHANNEL_CONF_2 ); 8 m_mixer = al_create_mixer( 44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, 9 ALLEGRO_CHANNEL_CONF_2 ); 10 al_attach_mixer_to_voice( m_mixer, m_voice ); 11 12 m_sampleInstance = al_create_sample_instance( NULL ); 13 m_sample = al_load_sample( filename ); 14 al_set_sample( m_sampleInstance, m_sample ); 15 16 al_attach_sample_instance_to_mixer( m_sampleInstance, m_mixer ); 17 al_set_sample_instance_playmode( m_sampleInstance, ALLEGRO_PLAYMODE_ONCE ); 18 al_play_sample_instance( m_sampleInstance ); 19}

Additional info, here are my settings:
-Frequency: 44100
-Buffer Count: 2
-Samples: 2048
-Reserved Samples: 50

Why might it be creating static???

Matthew Leverton

Generally you only need a single voice and mixer. You definitely should not be creating one per song.

If you call al_reserve_samples() that will automatically create a mixer. You can then call al_get_default_mixer(). Also, with al_reserve_samples() you can simply call al_play_sample() without creating your own instances... that's what it's for, after all.

BulletDave4

I did exactly as you told me and it works great! No more static noise. ;D

Thanks a bunch :)

Peter Wang

Fixed in r14803. This was due to the use of a global mixing buffer which obviously is wrong when two mixers run in parallel (which only happens when there are multiple voices).

Not that you need multiple voices.

Thread #607646. Printed from Allegro.cc