ALLEGRO_AUDIO_STREAM
typedef struct ALLEGRO_AUDIO_STREAM ALLEGRO_AUDIO_STREAM;
Introduced in 5.0.0
An ALLEGRO_AUDIO_STREAM object is used to stream generated audio to the sound device, in real-time. This is done by reading from a buffer, which is split into a number of fragments. Whenever a fragment has finished playing, the user can refill it with new data.
As with ALLEGRO_SAMPLE_INSTANCE objects, streams store information necessary for playback, so you may not play the same stream multiple times simultaneously. Streams also need to be attached to an ALLEGRO_VOICE object, or to an ALLEGRO_MIXER object which, eventually, reaches an ALLEGRO_VOICE object.
While playing, you must periodically fill fragments with new audio data. To know when a new fragment is ready to be filled, you can either directly check with al_get_available_audio_stream_fragments, or listen to events from the stream.
You can register an audio stream event source to an event queue; see al_get_audio_stream_event_source. An ALLEGRO_EVENT_AUDIO_STREAM_FRAGMENT event is generated whenever a new fragment is ready. When you receive an event, use al_get_audio_stream_fragment to obtain a pointer to the fragment to be filled. The size and format are determined by the parameters passed to al_create_audio_stream.
If you're late with supplying new data, the stream will be silent until new data is provided. You must call al_drain_audio_stream when you're finished with supplying data to the stream.
If the stream is created by al_load_audio_stream then it can also generate an ALLEGRO_EVENT_AUDIO_STREAM_FINISHED event if it reaches the end of the file and is not set to loop.
Examples: ex_mixer_pp, ex_saw, ex_stream_file, ex_stream_seek, ex_synth
Most helpful discussions:
- Difficulty compiling on Windows
- Screen is cleared and a new one appears Allegro5 in C?
- Audio Stream: Seeking doesn't work
- Audio waveform with unexpected frequency behavior
- Implementing an audio visualiser with A5
- Allegro Legacy Project
- This Place Just Doesn't Die
- Problem loading audio stream from tracker music file
- Dsound undefined reference error when compiling using 5.2.1 binaries
- Random deadlocks playing WAV sounds (Windows, MSVC)
Other recent discussions:
- ALLEGRO_AUDIO_STREAM possible to add API to access the 'extra' ponter?
- [A5] Playing Samples on the Fly?
- Can only load .ogg??
- Audio drift in Allegro 5.1.8
- allegro audio stream improvements
- ALLEGRO_EVENT_AUDIO_STREAM_FRAGMENT and Multiple Streams
- Audio synchronization in Allegro 5
- switching stream files
- [A5] audio stream empty on completion of playback
- [A5]ALLEGRO_SAMPLE_ID return id -1