music
duncan perham

What is the best way to play music in game.

I was using al_load_sample and it all works fine. but this is slow to load as it all has to be loaded into memory at the start (and will eventually use a lot of memory).

So I tried al_load_audio_stream, which works, but is poorly documented in how to control it.

al_attach_audio_stream_to_mixer(Music, al_get_default_mixer()); The music plays fine.
But now how to stop it, it just keeps adding new music over the old music so I end up with multiple music files playing at once.

Also when it gets to the end of the file, it will no longer play it.

I have dozens of ogg files, that I need to be able to play at random, however when I play a new one, I need the old one to stop, or fade would be better.

The documentation is fine for documenting what each function does, but it dosent give an overview of how to use them all together and what is the correct way to use them.

Polybios

I haven't used the audio addon much myself, but it seems that you can stop an audio stream by passing false to al_set_audio_stream_playing.
I think you can accomplish fading of an individual audio-stream by calling al_set_audio_stream_gain repeatedly with values 1.0 ... 0.0.
However, I guess you should wait for someone with more experience with the audio addon...

Edit:
You can set al_set_audio_stream_playmode to ALLEGRO_PLAYMODE_LOOP if you want the stream to start anew after it's finished.

Elias

al_attach_audio_stream_to_mixer has a link to al_detach_audio_stream in the documentation, so that would be my first guess to stop it again.

Chris Katko
Polybios said:

I think you can accomplish fading of an individual audio-stream by calling al_set_audio_stream_gain repeatedly with values 1.0 ... 0.0.

Isn't that fairly inefficient and subject to logic loop latency? Shouldn't audio playback (since it already depends so much on timing) support something like

al_set_audio_stream_gradient(stream, start_volume, end_volume, time_for_envelope)?

Ideally, you'd could also use a *_get_gradient_value and *_stop_gradient, so you could change the envelope mid-gradient. But you could fall back to the normal way for those if you had to.

Thread #615222. Printed from Allegro.cc