|
[A5] Problem with streaming sound |
TeaRDoWN
Member #8,518
April 2007
|
I've tried to load and stream the music in my game and the file is loaded but it never starts to play. I've checked the "ex_stream_seek example" and I don't see any other functions being used that should relate to this issue. As far as I've read in the manual only the al_load_audio_stream is needed to load and start streaming the file. ALLEGRO_AUDIO_STREAM *music; ... music = al_load_audio_stream(path, 4, 2048); al_set_audio_stream_playmode(music, ALLEGRO_PLAYMODE_LOOP); al_set_audio_stream_playing(music, true); I've tested to load the entire ogg file into memory with al_load_sample and play it with al_play_sample and that work as intended. Another question, how big sound files are reasonable to load into memory and when is it time to start streaming? Currently the ogg files in my game are ranging from 1.5Mb to 4Mb. Stream or load whole file into memory? |
AMCerasoli
Member #11,955
May 2010
|
TeaRDoWN said: Currently the ogg files in my game are ranging from 1.5Mb to 4Mb. Stream or load whole file into memory? You should definitely load them into memory. I think streaming is good for files > 50 Mb.
|
TeaRDoWN
Member #8,518
April 2007
|
Oh, hehe. Roger. |
Matthew Leverton
Supreme Loser
January 1999
|
Loading a sample will uncompress the file. The source size is not directly relevant. It's the length of the audio and its quality that affects how much RAM is used. I would always stream background music. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Maybe this helps? The Manual said: The audio stream will start in the playing state. It should be attached to a voice or mixer to generate any output. See ALLEGRO_AUDIO_STREAM for more details.
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
TeaRDoWN
Member #8,518
April 2007
|
Edgar: Tried this, changed my music from ALLEGRO_SAMPLE to ALLEGRO_AUDIO_STREAM and after loading the stream I used: voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2); music = al_load_audio_stream("music.ogg", 4, 2048); al_attach_audio_stream_to_voice(music, voice); As far as I can see in the ex_stream_file example this is all you need to do...or? EDIT: Noticed the text "don't recommend attaching audio streams directly to voices" and that helped: mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2); voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2); music = al_load_audio_stream("music.ogg", 4, 2048); al_attach_audio_stream_to_mixer(music, mixer); al_attach_mixer_to_voice(mixer, voice); When I want to start to stream a new music file what do I need to do? Just run al_detach_audio_stream or? |
Edgar Reynaldo
Major Reynaldo
May 2007
|
TeaRDoWN said: When I want to start to stream a new music file what do I need to do? Just run al_detach_audio_stream or? Looks like it, and then attach your new audio stream to the same mixer. I haven't tried any of this stuff myself yet. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
TeaRDoWN
Member #8,518
April 2007
|
Ok, I'll go with this for now and keep an eye out for memory leaks. |
Matthew Leverton
Supreme Loser
January 1999
|
You need to destroy the stream at some point. |
TeaRDoWN
Member #8,518
April 2007
|
Of course, when I start to stream a new file this is the first I do: if (music != NULL) { al_detach_audio_stream(music); al_destroy_audio_stream(music); }
|
|