Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Streaming Multiple Audio Files At Once

This thread is locked; no one can reply to it. rss feed Print
Streaming Multiple Audio Files At Once
roger levy
Member #2,513
July 2002

In 5.0.10 we seemed to be unable to stream multiple files, and this seems to still be un-rectified in 5.1

Still, it could have been an oversight or coding error on my part, so has anyone had success streaming multiple audio files simultaneously? For instance playing background music and voiceover, or dynamic multi-layered background music streaming from disk.

---

Make games in Forth! -
http://github.com/rogerLevy/ramen

Todd Cope
Member #998
November 2000
avatar

I think you can achieve the desired effect like so:

  • Create a voice.

  • Make sure it is not set to playing.

  • Create a mixer.

  • Create and/or load all the streams you want to play simultaneously.

  • Attach all of those streams to the mixer.

  • Attach the mixer to the voice.

  • Set the voice to playing.

After you do this, you can manipulate each stream however you see fit. For instance, if you wanted to turn off a layer of music, you can set that streams volume to 0.

I haven't actually tried it, but will be doing so soon. I have a project which needs this exact functionality.

Append: Just tried this method and it seems to work correctly. I would advise configuring your mixer to use ALLEGRO_AUDIO_DEPTH_FLOAT32 to get the best results. I had a lot of clipping when trying to use ALLEGRO_AUDIO_DEPTH_INT*.

Append 2: This method might be overkill if you don't need exact synchronization. Allegro allows you to create as many streams as you want and attach them to whatever mixer you are using.

roger levy
Member #2,513
July 2002

Thank you for the detailed advice.

Did you test this by streaming directly from files, or did you load them into memory first? Could you give me a code example for setting up a file stream this way? In my code I use al_load_audio_stream() and al_attach_audio_stream_to_mixer() as expected, so I'm not sure why it doesn't work (only one stream plays)

---

Make games in Forth! -
http://github.com/rogerLevy/ramen

Todd Cope
Member #998
November 2000
avatar

Here is the code I just tested:

#SelectExpand
1bool app_start_song_audio(APP_INSTANCE * app, ALLEGRO_PATH * pp) 2{ 3 ALLEGRO_PATH * pcp; 4 int i; 5 6 pcp = al_clone_path(pp); 7 app->voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2); 8 if(app->voice) 9 { 10 app->mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2); 11 if(app->mixer) 12 { 13 al_set_path_filename(pcp, "song.ogg"); 14 app->stream[0] = al_load_audio_stream(al_path_cstr(pcp, '/'), 4, 1024); 15 al_set_path_filename(pcp, "guitar.ogg"); 16 app->stream[1] = al_load_audio_stream(al_path_cstr(pcp, '/'), 4, 1024); 17 al_set_path_filename(pcp, "rhythm.ogg"); 18 app->stream[2] = al_load_audio_stream(al_path_cstr(pcp, '/'), 4, 1024); 19 al_set_path_filename(pcp, "drums.ogg"); 20 app->stream[3] = al_load_audio_stream(al_path_cstr(pcp, '/'), 4, 1024); 21 for(i = 0; i < 4; i++) 22 { 23 if(app->stream[i]) 24 { 25 al_attach_audio_stream_to_mixer(app->stream[i], app->mixer); 26 al_set_audio_stream_playing(app->stream[i], true); 27 } 28 } 29 al_attach_mixer_to_voice(app->mixer, app->voice); 30 } 31 al_set_voice_playing(app->voice, true); 32 al_destroy_path(pcp); 33 return true; 34 } 35 al_destroy_path(pcp); 36 return false; 37}

This code loads four separate streams from on-disk Ogg Vorbis files.

Are you sure all of your streams are actually playing and set to an audible volume?

roger levy
Member #2,513
July 2002

Hmm, I do not explicitly set them playing after attaching them to the mixer, so I'll have to do some tests and get back to you.

---

Make games in Forth! -
http://github.com/rogerLevy/ramen

Go to: