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?
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.
Oh, hehe. Roger.
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.
Maybe this helps?
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.
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?
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.
Ok, I'll go with this for now and keep an eye out for memory leaks.
You need to destroy the stream at some point.
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); }