ALLEGRO_AUDIO_STREAM *al_create_audio_stream(size_t fragment_count,
   unsigned int samples, unsigned int freq, ALLEGRO_AUDIO_DEPTH depth,
Introduced in 5.0.0

Creates an ALLEGRO_AUDIO_STREAM. The stream will be set to play by default. It will feed audio data from a buffer, which is split into a number of fragments.


The choice of fragment_count, samples and freq directly influences the audio delay. The delay in seconds can be expressed as:

delay = fragment_count * samples / freq

This is only the delay due to Allegro's streaming, there may be additional delay caused by sound drivers and/or hardware.

Note: If you know the fragment size in bytes, you can get the size in samples like this:

sample_size = al_get_channel_count(chan_conf) * al_get_audio_depth_size(depth);
samples = bytes_per_fragment / sample_size;

The size of the complete buffer is:

buffer_size = bytes_per_fragment * fragment_count

Note: unlike many Allegro objects, audio streams are not implicitly destroyed when Allegro is shut down. You must destroy them manually with al_destroy_audio_stream before the audio system is shut down.

Examples: ex_saw, ex_synth

Most helpful discussions: