Unit al5audio

Description

Audio addon.

In order to just play some samples, here's how to quick start with Allegro's audio addon: Call al_reserve_samples with the number of samples you'd like to be able to play simultaneously (don't forget to call al_install_audio beforehand). If these succeed, you can now call al_play_sample, with data obtained by al_load_sample, for example (don't forget to initialize the al5acodec addon). You don't need to worry about voices, mixers or sample instances when using this approach. In order to stop samples, you can use the ALLEGRO_SAMPLE_ID that al_play_sample returns.

If you want to play large audio files (e.g. background music) without loading the whole file at once or if you want to output audio generated in real-time, you can use Allegro's audio streams. The easiest way to setup an audio stream is to attach it to the default mixer (created for you by al_reserve_samples) using al_attach_audio_stream_to_mixer on the return value of al_get_default_mixer. Allegro will feed streams created from files using al_load_audio_stream automatically. However, you can also stream audio data you generate on the fly. In this case, audio streams will emit an event when it's time to provide the next fragment (chunk) of audio data. You can control several playback parameters of audio streams (speed, gain, pan, playmode, played/paused; additionally position and loop points when streaming a file).

For more fine-grained control over audio output, here's a short description of the basic concepts:

Voices represent audio devices on the system. Basically, every audio output chain that you want to be heard needs to end up in a voice. As voices are on the hardware/driver side of things, there is only limited control over their parameters (frequency, sample format, channel configuration). The number of available voices is limited as well. Typically, you will only use one voice and attach a mixer to it. Calling al_reserve_samples will do this for you by setting up a default voice and mixer; it can also be achieved by calling al_restore_default_mixer. Although you can attach sample instances and audio streams directly to a voice without using a mixer, it is, as of now, not recommended. In contrast to mixers, you can only attach a single object to a voice anyway.

Mixers mix several sample instances and/or audio streams into a single output buffer, converting sample data with differing formats according to their output parameters (frequency, depth, channels) in the process. In order to play several samples/streams at once reliably, you will need at least one mixer. A mixer that is not (indirectly) attached to a voice will remain silent. For most use cases, one (default) mixer attached to a single voice will be sufficient. You may attach mixers to other mixers in order to create complex audio chains.

Samples (ALLEGRO_SAMPLEptr) just represent "passive" buffers for sample data in memory. In order to play a sample, a sample instance (ALLEGRO_SAMPLE_INSTANCEptr) needs to be created and attached to a mixer (or voice). Sample instances control how the underlying samples are played. Several playback parameters (position, speed, gain, pan, playmode, playing/paused) can be adjusted. Particularly, multiple instances may be created from the same sample, e.g. with different parameters.

Audio streams (see above) are similar to sample instances insofar as they respond to the same playback parameters and have to be attached to mixers or voices. A single audio stream can only be played once simultaneously.

For example, consider the following configuration of the audio system:

[-]
An example configuration of the audio system to play music and a sound.

VAR
  Voice: ALLEGRO_VOICEptr;
  Mixer1, Mixer2: ALLEGRO_MIXERptr;
  Stream: ALLEGRO_AUDIO_STREAMptr;
  Sample: ALLEGRO_SAMPLEptr;
  Instance1, Instance2: ALLEGRO_SAMPLE_INSTANCEptr;
BEGIN
  Voice := al_create_voice (
    44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2
  );
  Mixer1 := al_create_mixer (
    44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2
  );
  Mixer2 := al_create_mixer (
    44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2
  );

{ Load a stream, the stream starts in a playing state and just needs
  to be attached to actually output sound. }
  Stream := al_load_audio_stream ('music.ogg', 4, 2048);
{ The sample needs sample instances to output sound. }
  Sample := al_load_sample ('sound.wav');
  Instance1 := al_create_sample_instance (Sample);
  Instance2 := al_create_sample_instance (Sample);

{ Attach everything up (as in the diagram). }
  al_attach_mixer_to_voice (Mixer1, Voice);
  al_attach_mixer_to_mixer (Mixer2, Mixer1);
  al_attach_audio_stream_to_mixer (Stream, Mixer1);
  al_attach_sample_instance_to_mixer (Instance1, Mixer2);
  al_attach_sample_instance_to_mixer (Instance2, Mixer2);

{ Play two copies of the sound simultaneously. }
  al_set_sample_instance_playing (Instance1, TRUE);
  al_set_sample_instance_playing (Instance2, TRUE);

Since we have two mixers, with the sample instances connected to a different mixer than the audio stream, you can control the volume of all the instances independently from the music by setting the gain of the mixer / stream. Having two sample instances lets you play two copies of the sample simultaneously.

With this in mind, another look at al_reserve_samples and al_play_sample is due: What the former does internally is to create a specified number of sample instances that are "empty" at first, i.e. with no sample data set. When al_play_sample is called, it'll use one of these internal sample instances that is not currently playing to play the requested sample. All of these sample instances will be attached to the default mixer, which can be changed via al_set_default_mixer.

See Audio recording for Allegro's audio recording API, which is, as of now, still unstable and subject to change.

Overview

Classes, Interfaces, Objects and Records

Name Description
Record ALLEGRO_AUDIO_RECORDER_EVENT Structure that holds the audio recorder event data.
Record ALLEGRO_SAMPLE_ID An ALLEGRO_SAMPLE_ID represents a sample being played via al_play_sample.

Functions and Procedures

function al_install_audio: AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_uninstall_audio; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_is_audio_installed: AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_allegro_audio_version: AL_UINT32; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_create_sample (buf: AL_VOIDptr; samples, freq: AL_UINT; depth: ALLEGRO_AUDIO_DEPTH; chan_conf: ALLEGRO_CHANNEL_CONF; free_buf: AL_BOOL): ALLEGRO_SAMPLEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_destroy_sample (spl: ALLEGRO_SAMPLEptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_create_sample_instance (data: ALLEGRO_SAMPLEptr): ALLEGRO_SAMPLE_INSTANCEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_destroy_sample_instance (spl: ALLEGRO_SAMPLE_INSTANCEptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_frequency (const spl: ALLEGRO_SAMPLEptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_length (const spl: ALLEGRO_SAMPLEptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_depth (const spl: ALLEGRO_SAMPLEptr): ALLEGRO_AUDIO_DEPTH; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_channels (const spl: ALLEGRO_SAMPLEptr): ALLEGRO_CHANNEL_CONF; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_data (const spl: ALLEGRO_SAMPLEptr): AL_VOIDptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_instance_frequency (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_instance_length (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_instance_position (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_instance_speed (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_instance_gain (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_instance_pan (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_instance_time (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_instance_depth (const spl: ALLEGRO_SAMPLE_INSTANCEptr): ALLEGRO_AUDIO_DEPTH; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_instance_channels (const spl: ALLEGRO_SAMPLE_INSTANCEptr): ALLEGRO_CHANNEL_CONF; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_instance_playmode (const spl: ALLEGRO_SAMPLE_INSTANCEptr): ALLEGRO_PLAYMODE; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_instance_playing (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample_instance_attached (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_sample_instance_position (spl: ALLEGRO_SAMPLE_INSTANCEptr; val: AL_UINT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_sample_instance_length (spl: ALLEGRO_SAMPLE_INSTANCEptr; val: AL_UINT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_sample_instance_speed (spl: ALLEGRO_SAMPLE_INSTANCEptr; val: AL_FLOAT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_sample_instance_gain (spl: ALLEGRO_SAMPLE_INSTANCEptr; val: AL_FLOAT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_sample_instance_pan (spl: ALLEGRO_SAMPLE_INSTANCEptr; val: AL_FLOAT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_sample_instance_playmode (spl: ALLEGRO_SAMPLE_INSTANCEptr; val: ALLEGRO_PLAYMODE): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_sample_instance_playing (spl: ALLEGRO_SAMPLE_INSTANCEptr; val: AL_BOOL): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_detach_sample_instance (spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_sample (spl: ALLEGRO_SAMPLE_INSTANCEptr; data: ALLEGRO_SAMPLEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_sample (spl: ALLEGRO_SAMPLE_INSTANCEptr): ALLEGRO_SAMPLEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_play_sample_instance (spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_stop_sample_instance (spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_create_audio_stream (buffer_count: AL_SIZE_T; samples, freq: AL_UINT; depth: ALLEGRO_AUDIO_DEPTH; chan_conf: ALLEGRO_CHANNEL_CONF): ALLEGRO_AUDIO_STREAMptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_destroy_audio_stream (stream: ALLEGRO_AUDIO_STREAMptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_drain_audio_stream (stream: ALLEGRO_AUDIO_STREAMptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_frequency (const stream: ALLEGRO_AUDIO_STREAMptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_length (const stream: ALLEGRO_AUDIO_STREAMptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_fragments (const stream: ALLEGRO_AUDIO_STREAMptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_available_audio_stream_fragments (const stream: ALLEGRO_AUDIO_STREAMptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_speed (const stream: ALLEGRO_AUDIO_STREAMptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_gain (const stream: ALLEGRO_AUDIO_STREAMptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_pan (const stream: ALLEGRO_AUDIO_STREAMptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_channels (const stream: ALLEGRO_AUDIO_STREAMptr): ALLEGRO_CHANNEL_CONF; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_depth (const stream: ALLEGRO_AUDIO_STREAMptr): ALLEGRO_AUDIO_DEPTH; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_playmode (const stream: ALLEGRO_AUDIO_STREAMptr): ALLEGRO_PLAYMODE; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_playing (const spl: ALLEGRO_AUDIO_STREAMptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_attached (const spl: ALLEGRO_AUDIO_STREAMptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_played_samples (const stream: ALLEGRO_AUDIO_STREAMptr): AL_UINT64; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_fragment (const stream: ALLEGRO_AUDIO_STREAMptr): AL_VOIDptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_audio_stream_speed (stream: ALLEGRO_AUDIO_STREAMptr; val: AL_FLOAT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_audio_stream_gain (stream: ALLEGRO_AUDIO_STREAMptr; val: AL_FLOAT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_audio_stream_pan (stream: ALLEGRO_AUDIO_STREAMptr; val: AL_FLOAT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_audio_stream_playmode (stream: ALLEGRO_AUDIO_STREAMptr; val: ALLEGRO_PLAYMODE): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_audio_stream_playing (stream: ALLEGRO_AUDIO_STREAMptr; val: AL_BOOL): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_detach_audio_stream (stream: ALLEGRO_AUDIO_STREAMptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_audio_stream_fragment (stream: ALLEGRO_AUDIO_STREAMptr; val: AL_VOIDptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_rewind_audio_stream (stream: ALLEGRO_AUDIO_STREAMptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_seek_audio_stream_secs (stream: ALLEGRO_AUDIO_STREAMptr; time: AL_DOUBLE): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_position_secs (stream: ALLEGRO_AUDIO_STREAMptr): AL_DOUBLE; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_length_secs (stream: ALLEGRO_AUDIO_STREAMptr): AL_DOUBLE; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_audio_stream_loop_secs (stream: ALLEGRO_AUDIO_STREAMptr; start, finish: AL_DOUBLE): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_stream_event_source (stream: ALLEGRO_AUDIO_STREAMptr): ALLEGRO_EVENT_SOURCEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_create_mixer (freq: AL_UINT; depth: ALLEGRO_AUDIO_DEPTH; chan_conf: ALLEGRO_CHANNEL_CONF): ALLEGRO_MIXERptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_destroy_mixer (mixer: ALLEGRO_MIXERptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_attach_sample_instance_to_mixer (sample: ALLEGRO_SAMPLE_INSTANCEptr; mixer: ALLEGRO_MIXERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_attach_audio_stream_to_mixer (stream: ALLEGRO_AUDIO_STREAMptr; mixer: ALLEGRO_MIXERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_attach_mixer_to_mixer (mixerA, mixerB: ALLEGRO_MIXERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_mixer_postprocess_callback (mixer: ALLEGRO_MIXERptr; cb: ALLEGRO_MIXER_CALLBACK; data: AL_VOIDptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_mixer_frequency (const mixer: ALLEGRO_MIXERptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_mixer_channels (const mixer: ALLEGRO_MIXERptr): ALLEGRO_CHANNEL_CONF; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_mixer_depth (const mixer: ALLEGRO_MIXERptr): ALLEGRO_AUDIO_DEPTH; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_mixer_quality (const mixer: ALLEGRO_MIXERptr): ALLEGRO_MIXER_QUALITY; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_mixer_gain (const mixer: ALLEGRO_MIXERptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_mixer_playing (const mixer: ALLEGRO_MIXERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_mixer_attached (const mixer: ALLEGRO_MIXERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_mixer_frequency (mixer: ALLEGRO_MIXERptr; val: AL_UINT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_mixer_quality (mixer: ALLEGRO_MIXERptr; val: ALLEGRO_MIXER_QUALITY): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_mixer_gain (mixer: ALLEGRO_MIXERptr; gain: AL_FLOAT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_mixer_playing (mixer: ALLEGRO_MIXERptr; val: AL_BOOL): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_detach_mixer (mixer: ALLEGRO_MIXERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_create_voice (freq: AL_UINT; depth: ALLEGRO_AUDIO_DEPTH; chan_conf: ALLEGRO_CHANNEL_CONF): ALLEGRO_VOICEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_destroy_voice (voice: ALLEGRO_VOICEptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_attach_sample_instance_to_voice (sample: ALLEGRO_SAMPLE_INSTANCEptr; voice: ALLEGRO_VOICEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_attach_audio_stream_to_voice (stream: ALLEGRO_AUDIO_STREAMptr; voice: ALLEGRO_VOICEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_attach_mixer_to_voice (mixer: ALLEGRO_MIXERptr; voice: ALLEGRO_VOICEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_detach_voice (voice: ALLEGRO_VOICEptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_voice_frequency (const voice: ALLEGRO_VOICEptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_voice_position (const voice: ALLEGRO_VOICEptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_voice_channels (const voice: ALLEGRO_VOICEptr): ALLEGRO_CHANNEL_CONF; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_voice_depth (const voice: ALLEGRO_VOICEptr): ALLEGRO_AUDIO_DEPTH; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_voice_playing (const voice: ALLEGRO_VOICEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_voice_position (voice: ALLEGRO_VOICEptr; val: AL_UINT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_voice_playing (voice: ALLEGRO_VOICEptr; val: AL_BOOL): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_channel_count (conf: ALLEGRO_CHANNEL_CONF): AL_SIZE_T; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_depth_size (conf: ALLEGRO_AUDIO_DEPTH): AL_SIZE_T; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_fill_silence (bur: AL_VOIDptr; samples: AL_UINT; depth: ALLEGRO_AUDIO_DEPTH; chan_conf: ALLEGRO_CHANNEL_CONF); CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_num_audio_output_devices: AL_INT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_output_device (index: AL_INT): ALLEGRO_AUDIO_DEVICEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_device_name (device: ALLEGRO_AUDIO_DEVICEptr): AL_STRptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_reserve_samples (reserve_samples: AL_INT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_default_mixer: ALLEGRO_MIXERptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_set_default_mixer (mixer: ALLEGRO_MIXERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_restore_default_mixer: AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_play_sample (data: ALLEGRO_SAMPLEptr; gain, pan, speed: AL_FLOAT; loop: ALLEGRO_PLAYMODE; ret_id: ALLEGRO_SAMPLE_IDptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_stop_sample (var spl_id: ALLEGRO_SAMPLE_ID); CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_stop_samples; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_default_voice: ALLEGRO_VOICEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_set_default_voice (voice: ALLEGRO_VOICEptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_lock_sample_id (var spl_id: ALLEGRO_SAMPLE_ID): ALLEGRO_SAMPLE_INSTANCEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_unlock_sample_id (var spl_id: ALLEGRO_SAMPLE_ID); CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_register_sample_loader (const ext: AL_STR; loader: ALLEGRO_SAMPLE_LOADER): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_register_sample_saver (const ext: AL_STR; saver: ALLEGRO_SAMPLE_SAVER): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_register_audio_stream_loader (const ext: AL_STR; stream_loader: ALLEGRO_AUDIO_STREAM_LOADER): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_register_sample_identifier (const ext: AL_STR; identifier: ALLEGRO_SAMPLE_IDENTIFIER_F): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_register_sample_loader_f (const ext: AL_STR; loader: ALLEGRO_SAMPLE_LOADER_F): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_register_sample_saver_f (const ext: AL_STR; saver: ALLEGRO_SAMPLE_SAVER_F): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_register_audio_stream_loader_f (const ext: AL_STR; stream_loader: ALLEGRO_AUDIO_STREAM_LOADER_F): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_load_sample (const filename: AL_STR): ALLEGRO_SAMPLEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_save_sample (const filename: AL_STR; spl: ALLEGRO_SAMPLEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_load_audio_stream (const filename: AL_STR; buffer_count: AL_SIZE_T; samples: AL_UINT): ALLEGRO_AUDIO_STREAMptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_load_sample_f (fp: ALLEGRO_FILEptr; const ident: AL_STR): ALLEGRO_SAMPLEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_save_sample_f (fp: ALLEGRO_FILEptr; const ident: AL_STR; spl: ALLEGRO_FILEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_load_audio_stream_f (fp: ALLEGRO_FILEptr; const ident: AL_STR; buffer_count: AL_SIZE_T; samples: AL_UINT): ALLEGRO_AUDIO_STREAMptr CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_identify_sample_f (p: ALLEGRO_FILEptr): AL_STRptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_identify_sample (filename: AL_STR): AL_STRptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_create_audio_recorder (fragment_count: AL_SIZE_T; samples, freq: AL_UINT; depth: ALLEGRO_AUDIO_DEPTH; chan_conf: ALLEGRO_CHANNEL_CONF): ALLEGRO_AUDIO_RECORDERptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_start_audio_recorder (r: ALLEGRO_AUDIO_RECORDERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_stop_audio_recorder (r: ALLEGRO_AUDIO_RECORDERptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_is_audio_recorder_recording (r: ALLEGRO_AUDIO_RECORDERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_recorder_event_source (r: ALLEGRO_AUDIO_RECORDERptr): ALLEGRO_EVENT_SOURCEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
function al_get_audio_recorder_event (event: ALLEGRO_EVENT): ALLEGRO_AUDIO_RECORDER_EVENT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;
procedure al_destroy_audio_recorder (r: ALLEGRO_AUDIO_RECORDERptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Types

ALLEGRO_AUDIO_RECORDERptr = type AL_POINTER;
ALLEGRO_AUDIO_DEPTH = (...);
ALLEGRO_CHANNEL_CONF = (...);
ALLEGRO_PLAYMODE = (...);
ALLEGRO_MIXER_QUALITY = (...);
ALLEGRO_SAMPLEptr = type AL_POINTER;
ALLEGRO_SAMPLE_IDptr = ˆALLEGRO_SAMPLE_ID;
ALLEGRO_SAMPLE_INSTANCEptr = AL_POINTER;
ALLEGRO_AUDIO_STREAMptr = AL_POINTER;
ALLEGRO_MIXERptr = AL_POINTER;
ALLEGRO_VOICEptr = AL_POINTER;
ALLEGRO_AUDIO_DEVICEptr = AL_POINTER;
ALLEGRO_MIXER_CALLBACK = procedure (buf: AL_VOIDptr; samples: AL_UINT; data: AL_VOIDptr); CDECL;
ALLEGRO_SAMPLE_LOADER = function (const filename: AL_STRptr): ALLEGRO_SAMPLEptr; CDECL;
ALLEGRO_SAMPLE_SAVER = function (const filename: AL_STRptr; spl: ALLEGRO_SAMPLEptr): AL_BOOL; CDECL;
ALLEGRO_AUDIO_STREAM_LOADER = function (const filename: AL_STRptr; buffer_count: AL_SIZE_T; samples: AL_UINT): ALLEGRO_AUDIO_STREAMptr; CDECL;
ALLEGRO_SAMPLE_LOADER_F = function (fp: ALLEGRO_FILEptr): ALLEGRO_SAMPLEptr; CDECL;
ALLEGRO_SAMPLE_SAVER_F = function (fp: ALLEGRO_FILEptr; spl: ALLEGRO_SAMPLEptr): AL_BOOL; CDECL;
ALLEGRO_AUDIO_STREAM_LOADER_F = function (fp: ALLEGRO_FILEptr; buffer_count: AL_SIZE_T; samples: AL_UINT): ALLEGRO_AUDIO_STREAMptr; CDECL;
ALLEGRO_SAMPLE_IDENTIFIER_F = function (fp: ALLEGRO_FILEptr): AL_BOOL; CDECL;

Constants

ALLEGRO_EVENT_AUDIO_STREAM_FRAGMENT = 513;
ALLEGRO_EVENT_AUDIO_STREAM_FINISHED = 514;
ALLEGRO_EVENT_AUDIO_RECORDER_FRAGMENT = 515;
ALLEGRO_AUDIO_PAN_NONE: AL_FLOAT = -1000.0;

Description

Functions and Procedures

function al_install_audio: AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Installs the audio subsystem.

Note

most users will call al_reserve_samples and al_init_acodec_addon after this. *)

Returns

True on success, False on failure.

See also
al_reserve_samples
Reserves a number of sample instances, attaching them to the default mixer.
al_uninstall_audio
Uninstalls the audio subsystem.
al_is_audio_installed
Returns True if al_install_audio was called previously and returned successfully.
al_init_acodec_addon
This procedure registers all the known audio file type handlers for al_load_sample, al_save_sample, al_load_audio_stream, etc.
procedure al_uninstall_audio; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Uninstalls the audio subsystem.

See also
al_install_audio
Installs the audio subsystem.
function al_is_audio_installed: AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns True if al_install_audio was called previously and returned successfully.

function al_get_allegro_audio_version: AL_UINT32; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the (compiled) version of the addon, in the same format as al_get_allegro_version.

function al_create_sample (buf: AL_VOIDptr; samples, freq: AL_UINT; depth: ALLEGRO_AUDIO_DEPTH; chan_conf: ALLEGRO_CHANNEL_CONF; free_buf: AL_BOOL): ALLEGRO_SAMPLEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Creates a sample data structure from the supplied buffer. If free_buf is True then the buffer will be freed with al_free when the sample data structure is destroyed. For portability (especially Windows), the buffer should have been allocated with al_malloc. Otherwise you should free the sample data yourself.

A sample that is referred to by the samples parameter refers to a sequence channel intensities. E.g. if you're making a stereo sample with the samples set to 4, then the layout of the data in buf will be:

LRLRLRLR

Where L and R are the intensities for the left and right channels respectively. A single sample, then, refers to the LR pair in this example.

To allocate a buffer of the correct size, you can use something like this:

VAR
  SampleSize, Bytes: INTEGER;
  Buffer: POINTER;
BEGIN
  SampleSize := al_get_channel_count (ChanConf) * al_get_audio_depth_size (Depth);
  Bytes := Samples * SampleSize;
  Buffer := al_malloc (Bytes)
END.

See also
al_destroy_sample
Frees the sample data structure.
ALLEGRO_AUDIO_DEPTH
Sample depth and type as well as signedness.
ALLEGRO_CHANNEL_CONF
Speaker configuration (mono, stereo, 2.1, etc).
procedure al_destroy_sample (spl: ALLEGRO_SAMPLEptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Frees the sample data structure. If it was created with the free_buf parameter set to True, then the buffer will be freed with al_free.

This function will stop any sample instances which may be playing the buffer referenced by the ALLEGRO_SAMPLEptr.

See also
al_destroy_sample_instance
Detaches the sample instance from anything it may be attached to and frees it (the sample data, i.e.
al_stop_sample
Stops the sample started by al_play_sample.
al_stop_samples
Stops all samples started by al_play_sample.
function al_create_sample_instance (data: ALLEGRO_SAMPLEptr): ALLEGRO_SAMPLE_INSTANCEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Creates a sample instance, using the supplied sample data. The instance must be attached to a mixer (or voice) in order to actually produce output.

The argument may be Nil. You can then set the sample data later with al_set_sample.

See also
al_destroy_sample_instance
Detaches the sample instance from anything it may be attached to and frees it (the sample data, i.e.
procedure al_destroy_sample_instance (spl: ALLEGRO_SAMPLE_INSTANCEptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Detaches the sample instance from anything it may be attached to and frees it (the sample data, i.e. its ALLEGRO_SAMPLE, is not freed!).

See also
al_create_sample_instance
Creates a sample instance, using the supplied sample data.
function al_get_sample_frequency (const spl: ALLEGRO_SAMPLEptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the frequency (in Hz) of the sample.

See also
al_get_sample_channels
Returns the channel configuration of the sample.
al_get_sample_depth
Returns the audio depth of the sample.
al_get_sample_length
Returns the length of the sample in sample values.
al_get_sample_data
Returns a pointer to the raw sample data.
function al_get_sample_length (const spl: ALLEGRO_SAMPLEptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the length of the sample in sample values.

See also
al_get_sample_channels
Returns the channel configuration of the sample.
al_get_sample_depth
Returns the audio depth of the sample.
al_get_sample_frequency
Returns the frequency (in Hz) of the sample.
al_get_sample_data
Returns a pointer to the raw sample data.
function al_get_sample_depth (const spl: ALLEGRO_SAMPLEptr): ALLEGRO_AUDIO_DEPTH; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the audio depth of the sample.

See also
ALLEGRO_AUDIO_DEPTH
Sample depth and type as well as signedness.
al_get_sample_channels
Returns the channel configuration of the sample.
al_get_sample_frequency
Returns the frequency (in Hz) of the sample.
al_get_sample_length
Returns the length of the sample in sample values.
al_get_sample_data
Returns a pointer to the raw sample data.
function al_get_sample_channels (const spl: ALLEGRO_SAMPLEptr): ALLEGRO_CHANNEL_CONF; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the channel configuration of the sample.

See also
ALLEGRO_CHANNEL_CONF
Speaker configuration (mono, stereo, 2.1, etc).
al_get_sample_depth
Returns the audio depth of the sample.
al_get_sample_frequency
Returns the frequency (in Hz) of the sample.
al_get_sample_length
Returns the length of the sample in sample values.
al_get_sample_data
Returns a pointer to the raw sample data.
function al_get_sample_data (const spl: ALLEGRO_SAMPLEptr): AL_VOIDptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns a pointer to the raw sample data.

See also
al_get_sample_channels
Returns the channel configuration of the sample.
al_get_sample_depth
Returns the audio depth of the sample.
al_get_sample_frequency
Returns the frequency (in Hz) of the sample.
al_get_sample_length
Returns the length of the sample in sample values.
function al_get_sample_instance_frequency (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the frequency (in Hz) of the sample instance's sample data.

function al_get_sample_instance_length (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the length of the sample instance in sample values. This property may differ from the length of the instance's sample data.

See also
al_set_sample_instance_length
Sets the length of the sample instance in sample values.
al_get_sample_instance_time
Returns the length of the sample instance in seconds, assuming a playback speed of 1.0.
function al_get_sample_instance_position (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Gets the playback position of a sample instance.

See also
al_set_sample_instance_position
Sets the playback position of a sample instance.
function al_get_sample_instance_speed (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the relative playback speed of the sample instance.

See also
al_set_sample_instance_speed
Sets the relative playback speed of the sample instance.
function al_get_sample_instance_gain (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the playback gain of the sample instance.

See also
al_set_sample_instance_gain
Sets the playback gain of the sample instance.
function al_get_sample_instance_pan (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Gets the pan value of the sample instance.

See also
al_set_sample_instance_pan
Sets the pan value on a sample instance.
function al_get_sample_instance_time (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the length of the sample instance in seconds, assuming a playback speed of 1.0.

See also
al_get_sample_instance_length
Returns the length of the sample instance in sample values.
function al_get_sample_instance_depth (const spl: ALLEGRO_SAMPLE_INSTANCEptr): ALLEGRO_AUDIO_DEPTH; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the audio depth of the sample instance's sample data.

See also
ALLEGRO_AUDIO_DEPTH
Sample depth and type as well as signedness.
function al_get_sample_instance_channels (const spl: ALLEGRO_SAMPLE_INSTANCEptr): ALLEGRO_CHANNEL_CONF; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the channel configuration of the sample instance's sample data.

See also
ALLEGRO_CHANNEL_CONF
Speaker configuration (mono, stereo, 2.1, etc).
function al_get_sample_instance_playmode (const spl: ALLEGRO_SAMPLE_INSTANCEptr): ALLEGRO_PLAYMODE; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the playback mode of the sample instance.

See also
ALLEGRO_PLAYMODE
Sample and stream playback mode.
al_set_sample_instance_playmode
Sets the playback mode of the sample instance.
function al_get_sample_instance_playing (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns True if the sample instance is in the playing state. This may be true even if the instance is not attached to anything.

See also
al_set_sample_instance_playing
Changes whether the sample instance is playing.
function al_get_sample_instance_attached (const spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns whether the sample instance is attached to something.

See also
al_attach_sample_instance_to_mixer
Attaches a sample instance to a mixer.
al_attach_sample_instance_to_voice
Attaches a sample instance to a voice, and allows it to play.
al_detach_sample_instance
Detachs the sample instance from whatever it's attached to, if anything.
function al_set_sample_instance_position (spl: ALLEGRO_SAMPLE_INSTANCEptr; val: AL_UINT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the playback position of a sample instance.

Returns

True on success, False on failure.

See also
al_get_sample_instance_position
Gets the playback position of a sample instance.
function al_set_sample_instance_length (spl: ALLEGRO_SAMPLE_INSTANCEptr; val: AL_UINT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the length of the sample instance in sample values. This can be used to play only parts of the underlying sample. Be careful not to exceed the actual length of the sample data, though.

Returns

True on success, False on failure. Will fail if the sample instance is currently playing.

See also
al_get_sample_instance_length
Returns the length of the sample instance in sample values.
function al_set_sample_instance_speed (spl: ALLEGRO_SAMPLE_INSTANCEptr; val: AL_FLOAT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the relative playback speed of the sample instance. 1.0 means normal speed.

Returns

True on success, False on failure. Will fail if the sample instance is attached directly to a voice.

See also
al_get_sample_instance_speed
Returns the relative playback speed of the sample instance.
function al_set_sample_instance_gain (spl: ALLEGRO_SAMPLE_INSTANCEptr; val: AL_FLOAT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the playback gain of the sample instance.

Returns

True on success, False on failure. Will fail if the sample instance is attached directly to a voice.

See also
al_get_sample_instance_gain
Returns the playback gain of the sample instance.
function al_set_sample_instance_pan (spl: ALLEGRO_SAMPLE_INSTANCEptr; val: AL_FLOAT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the pan value on a sample instance. A value of -1.0 means to play the sample only through the left speaker; +1.0 means only through the right speaker; 0.0 means the sample is centre balanced. A special value ALLEGRO_AUDIO_PAN_NONE disables panning and plays the sample at its original level. This will be louder than a pan value of 0.0.

Note

panning samples with more than two channels doesn't work yet.

Returns

True on success, False on failure. Will fail if the sample instance is attached directly to a voice.

See also
al_get_sample_instance_pan
Gets the pan value of the sample instance.
ALLEGRO_AUDIO_PAN_NONE
A special value for the pan property of sample instances and audio streams.
function al_set_sample_instance_playmode (spl: ALLEGRO_SAMPLE_INSTANCEptr; val: ALLEGRO_PLAYMODE): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the playback mode of the sample instance.

Returns

True on success, False on failure.

See also
ALLEGRO_PLAYMODE
Sample and stream playback mode.
al_get_sample_instance_playmode
Returns the playback mode of the sample instance.
function al_set_sample_instance_playing (spl: ALLEGRO_SAMPLE_INSTANCEptr; val: AL_BOOL): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Changes whether the sample instance is playing.

The instance does not need to be attached to anything.

Returns

True on success, False on failure.

See also
al_get_sample_instance_playing
Returns True if the sample instance is in the playing state.
function al_detach_sample_instance (spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Detachs the sample instance from whatever it's attached to, if anything.

Returns

True on success.

See also
al_attach_sample_instance_to_mixer
Attaches a sample instance to a mixer.
al_attach_sample_instance_to_voice
Attaches a sample instance to a voice, and allows it to play.
al_get_sample_instance_attached
Returns whether the sample instance is attached to something.
function al_set_sample (spl: ALLEGRO_SAMPLE_INSTANCEptr; data: ALLEGRO_SAMPLEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Changes the sample data that a sample instance plays. This can be quite an involved process.

First, the sample is stopped if it is not already.

Next, if data is Nil, the sample is detached from its parent (if any).

If data is not Nil, the sample may be detached and reattached to its parent (if any). This is not necessary if the old sample data and new sample data have the same frequency, depth and channel configuration. Reattaching may not always succeed.

On success, the sample remains stopped. The playback position and loop end points are reset to their default values. The loop mode remains unchanged.

Returns

True on success, False on failure. On failure, the sample will be stopped and detached from its parent.

See also
al_get_sample
Returns the sample data that the sample instance plays.
function al_get_sample (spl: ALLEGRO_SAMPLE_INSTANCEptr): ALLEGRO_SAMPLEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the sample data that the sample instance plays.

Note this returns a pointer to an internal structure, not the ALLEGRO_SAMPLEptr that you may have passed to al_set_sample. However, the sample buffer of the returned ALLEGRO_SAMPLEptr will be the same as the one that was used to create the sample (passed to al_create_sample). You can use al_get_sample_data on the return value to retrieve and compare it.

See also
al_set_sample
Changes the sample data that a sample instance plays.
function al_play_sample_instance (spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Plays the sample instance.

Returns

True on success, False on failure.

See also
al_stop_sample_instance
Stops an sample instance playing.
function al_stop_sample_instance (spl: ALLEGRO_SAMPLE_INSTANCEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Stops an sample instance playing.

See also
al_play_sample_instance
Plays the sample instance.
function al_create_audio_stream (buffer_count: AL_SIZE_T; samples, freq: AL_UINT; depth: ALLEGRO_AUDIO_DEPTH; chan_conf: ALLEGRO_CHANNEL_CONF): ALLEGRO_AUDIO_STREAMptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Creates an ALLEGRO_AUDIO_STREAMptr. 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.

A sample that is referred to by the samples parameter refers to a sequence channel intensities. E.g. if you're making a stereo stream with the samples set to 4, then the layout of the data in the fragment will be:

LRLRLRLR

Where L and R are the intensities for the left and right channels respectively. A single sample, then, refers to the LR pair in this example.

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

Delay := buffer_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:

SampleSize := al_get_channel_count (ChannelConf) * al_get_audio_depth_size (Depth);
Samples := BytesPerFragment / SampleSize;

The size of the complete buffer is:

BufferSize := BytesPerFragment * buffer_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.

Parameters
buffer_count
How many fragments to use for the audio stream. Usually only two fragments are required - splitting the audio buffer in two halves. But it means that the only time when new data can be supplied is whenever one half has finished playing. When using many fragments, you usually will use fewer samples for one, so there always will be (small) fragments available to be filled with new data.
samples
The size of a fragment in samples.
freq
The frequency, in Hertz.
depth
Must be one of the values listed for ALLEGRO_AUDIO_DEPTH.
chan_conf
Must be one of the values listed for ALLEGRO_CHANNEL_CONF.
procedure al_destroy_audio_stream (stream: ALLEGRO_AUDIO_STREAMptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Destroys an audio stream which was created with al_create_audio_stream or al_load_audio_stream.

Note

If the stream is still attached to a mixer or voice, al_detach_audio_stream is automatically called on it first.

See also
al_drain_audio_stream
You should call this to finalise an audio stream that you will no longer be feeding, to wait for all pending buffers to finish playing.
procedure al_drain_audio_stream (stream: ALLEGRO_AUDIO_STREAMptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;

You should call this to finalise an audio stream that you will no longer be feeding, to wait for all pending buffers to finish playing. The stream's playing state will change to False.

See also
al_destroy_audio_stream
Destroys an audio stream which was created with al_create_audio_stream or al_load_audio_stream.
function al_get_audio_stream_frequency (const stream: ALLEGRO_AUDIO_STREAMptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the stream frequency (in Hz).

function al_get_audio_stream_length (const stream: ALLEGRO_AUDIO_STREAMptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the stream length in samples.

function al_get_audio_stream_fragments (const stream: ALLEGRO_AUDIO_STREAMptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the number of fragments this stream uses. This is the same value as passed to al_create_audio_stream when a new stream is created.

See also
al_get_available_audio_stream_fragments
Returns the number of available fragments in the stream, that is, fragments which are not currently filled with data for playback.
function al_get_available_audio_stream_fragments (const stream: ALLEGRO_AUDIO_STREAMptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the number of available fragments in the stream, that is, fragments which are not currently filled with data for playback.

See also
al_get_audio_stream_fragment
When using Allegro's audio streaming, you will use this function to continuously provide new sample data to a stream.
al_get_audio_stream_fragments
Returns the number of fragments this stream uses.
function al_get_audio_stream_speed (const stream: ALLEGRO_AUDIO_STREAMptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the relative playback speed of the stream.

See also
al_set_audio_stream_speed
Sets the relative playback speed of the stream.
function al_get_audio_stream_gain (const stream: ALLEGRO_AUDIO_STREAMptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the playback gain of the stream.

See also
al_set_audio_stream_gain
Sets the playback gain of the stream.
function al_get_audio_stream_pan (const stream: ALLEGRO_AUDIO_STREAMptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Gets the pan value of the stream.

See also
al_set_audio_stream_pan
Sets the pan value on an audio stream.
function al_get_audio_stream_channels (const stream: ALLEGRO_AUDIO_STREAMptr): ALLEGRO_CHANNEL_CONF; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the stream channel configuration.

See also
ALLEGRO_CHANNEL_CONF
Speaker configuration (mono, stereo, 2.1, etc).
function al_get_audio_stream_depth (const stream: ALLEGRO_AUDIO_STREAMptr): ALLEGRO_AUDIO_DEPTH; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the stream audio depth.

See also
ALLEGRO_AUDIO_DEPTH
Sample depth and type as well as signedness.
function al_get_audio_stream_playmode (const stream: ALLEGRO_AUDIO_STREAMptr): ALLEGRO_PLAYMODE; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the playback mode of the stream.

See also
ALLEGRO_PLAYMODE
Sample and stream playback mode.
al_set_audio_stream_playmode
Sets the playback mode of the stream.
function al_get_audio_stream_playing (const spl: ALLEGRO_AUDIO_STREAMptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns True if the stream is playing.

See also
al_set_audio_stream_playing
Changes whether the stream is playing.
function al_get_audio_stream_attached (const spl: ALLEGRO_AUDIO_STREAMptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns whether the stream is attached to something.

See also
al_attach_audio_stream_to_mixer
Attaches an audio stream to a mixer.
al_attach_audio_stream_to_voice
Attaches an audio stream to a voice.
al_detach_audio_stream
Detaches the stream from whatever it's attached to, if anything.
function al_get_audio_stream_played_samples (const stream: ALLEGRO_AUDIO_STREAMptr): AL_UINT64; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Gets the number of samples consumed by the parent since the audio stream was started.

function al_get_audio_stream_fragment (const stream: ALLEGRO_AUDIO_STREAMptr): AL_VOIDptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

When using Allegro's audio streaming, you will use this function to continuously provide new sample data to a stream.

If the stream is ready for new data, the function will return the address of an internal buffer to be filled with audio data. The length and format of the buffer are specified with al_create_audio_stream or can be queried with the various functions described here. Once the buffer is filled, you must signal this to Allegro by passing the buffer to al_set_audio_stream_fragment.

If the stream is not ready for new data, the function will return Nil.

Note

If you listen to events from the stream, an ALLEGRO_EVENT_AUDIO_STREAM_FRAGMENT event will be generated whenever a new fragment is ready. However, getting an event is not a guarantee that al_get_audio_stream_fragment will not return Nil, so you still must check for it.

See also
al_set_audio_stream_fragment
This function needs to be called for every successful call of al_get_audio_stream_fragment to indicate that the buffer (pointed to by val) is filled with new data.
al_get_audio_stream_event_source
Retrieves the associated event source.
al_get_audio_stream_frequency
Returns the stream frequency (in Hz).
al_get_audio_stream_channels
Returns the stream channel configuration.
al_get_audio_stream_depth
Returns the stream audio depth.
al_get_audio_stream_length
Returns the stream length in samples.
function al_set_audio_stream_speed (stream: ALLEGRO_AUDIO_STREAMptr; val: AL_FLOAT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the relative playback speed of the stream. 1.0 means normal speed.

Returns

True on success, False on failure. Will fail if the audio stream is attached directly to a voice.

See also
al_get_audio_stream_speed
Returns the relative playback speed of the stream.
function al_set_audio_stream_gain (stream: ALLEGRO_AUDIO_STREAMptr; val: AL_FLOAT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the playback gain of the stream.

Returns

True on success, False on failure. Will fail if the audio stream is attached directly to a voice.

See also
al_get_audio_stream_gain
Returns the playback gain of the stream.
function al_set_audio_stream_pan (stream: ALLEGRO_AUDIO_STREAMptr; val: AL_FLOAT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the pan value on an audio stream. A value of -1.0 means to play the stream only through the left speaker; +1.0 means only through the right speaker; 0.0 means the sample is centre balanced. A special value ALLEGRO_AUDIO_PAN_NONE disables panning and plays the stream at its original level. This will be louder than a pan value of 0.0.

Returns

True on success, False on failure. Will fail if the audio stream is attached directly to a voice.

See also
al_get_audio_stream_pan
Gets the pan value of the stream.
ALLEGRO_AUDIO_PAN_NONE
A special value for the pan property of sample instances and audio streams.
function al_set_audio_stream_playmode (stream: ALLEGRO_AUDIO_STREAMptr; val: ALLEGRO_PLAYMODE): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the playback mode of the stream.

Returns

True on success, False on failure.

See also
ALLEGRO_PLAYMODE
Sample and stream playback mode.
al_get_audio_stream_playmode
Returns the playback mode of the stream.
function al_set_audio_stream_playing (stream: ALLEGRO_AUDIO_STREAMptr; val: AL_BOOL): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Changes whether the stream is playing.

Returns

True on success, False on failure.

See also
al_get_audio_stream_playing
Returns True if the stream is playing.
function al_detach_audio_stream (stream: ALLEGRO_AUDIO_STREAMptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Detaches the stream from whatever it's attached to, if anything.

See also
al_attach_audio_stream_to_mixer
Attaches an audio stream to a mixer.
al_attach_audio_stream_to_voice
Attaches an audio stream to a voice.
al_get_audio_stream_attached
Returns whether the stream is attached to something.
function al_set_audio_stream_fragment (stream: ALLEGRO_AUDIO_STREAMptr; val: AL_VOIDptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

This function needs to be called for every successful call of al_get_audio_stream_fragment to indicate that the buffer (pointed to by val) is filled with new data.

See also
al_get_audio_stream_fragment
When using Allegro's audio streaming, you will use this function to continuously provide new sample data to a stream.
function al_rewind_audio_stream (stream: ALLEGRO_AUDIO_STREAMptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the streaming file playing position to the beginning. Currently this can only be called on streams created with al_load_audio_stream, al_load_audio_stream_f and the format-specific functions underlying those functions.

Returns

True on success.

function al_seek_audio_stream_secs (stream: ALLEGRO_AUDIO_STREAMptr; time: AL_DOUBLE): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the streaming file playing position to time. Currently this can only be called on streams created with al_load_audio_stream, al_load_audio_stream_f and the format-specific functions underlying those functions.

Returns

True on success.

See also
al_get_audio_stream_position_secs
Returns the position of the stream in seconds.
al_get_audio_stream_length_secs
Returns the length of the stream in seconds, if known.
function al_get_audio_stream_position_secs (stream: ALLEGRO_AUDIO_STREAMptr): AL_DOUBLE; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the position of the stream in seconds. Currently this can only be called on streams created with al_load_audio_stream.

See also
al_get_audio_stream_length_secs
Returns the length of the stream in seconds, if known.
function al_get_audio_stream_length_secs (stream: ALLEGRO_AUDIO_STREAMptr): AL_DOUBLE; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the length of the stream in seconds, if known. Otherwise returns zero.

Currently this can only be called on streams created with al_load_audio_stream, al_load_audio_stream_f and the format-specific functions underlying those functions.

See also
al_get_audio_stream_position_secs
Returns the position of the stream in seconds.
function al_set_audio_stream_loop_secs (stream: ALLEGRO_AUDIO_STREAMptr; start, finish: AL_DOUBLE): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the loop points for the stream in seconds. Currently this can only be called on streams created with al_load_audio_stream, al_load_audio_stream_f and the format-specific functions underlying those functions.

function al_get_audio_stream_event_source (stream: ALLEGRO_AUDIO_STREAMptr): ALLEGRO_EVENT_SOURCEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Retrieves the associated event source.

See al_get_audio_stream_fragment for a description of the ALLEGRO_EVENT_AUDIO_STREAM_FRAGMENT event that audio streams emit.

function al_create_mixer (freq: AL_UINT; depth: ALLEGRO_AUDIO_DEPTH; chan_conf: ALLEGRO_CHANNEL_CONF): ALLEGRO_MIXERptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Creates a mixer to attach sample instances, audio streams, or other mixers to. It will mix into a buffer at the requested frequency (in Hz) and channel count.

The only supported audio depths are ALLEGRO_AUDIO_DEPTH_FLOAT32 and ALLEGRO_AUDIO_DEPTH_INT16 (not yet complete).

To actually produce any output, the mixer will have to be attached to a voice.

Returns

True on success, False on error.

See also
al_destroy_mixer
Destroys the mixer.
ALLEGRO_AUDIO_DEPTH
Sample depth and type as well as signedness.
ALLEGRO_CHANNEL_CONF
Speaker configuration (mono, stereo, 2.1, etc).
al_destroy_mixer
Destroys the mixer.
procedure al_destroy_mixer (mixer: ALLEGRO_MIXERptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Destroys the mixer.

See also
al_create_mixer
Creates a mixer to attach sample instances, audio streams, or other mixers to.
function al_attach_sample_instance_to_mixer (sample: ALLEGRO_SAMPLE_INSTANCEptr; mixer: ALLEGRO_MIXERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Attaches a sample instance to a mixer. The instance must not already be attached to anything.

Returns

True on success, False on failure.

See also
al_detach_sample_instance
Detachs the sample instance from whatever it's attached to, if anything.
function al_attach_audio_stream_to_mixer (stream: ALLEGRO_AUDIO_STREAMptr; mixer: ALLEGRO_MIXERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Attaches an audio stream to a mixer. The stream must not already be attached to anything.

Returns

True on success, False on failure.

See also
al_detach_audio_stream
Detaches the stream from whatever it's attached to, if anything.
function al_attach_mixer_to_mixer (mixerA, mixerB: ALLEGRO_MIXERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Attaches the mixer passed as the first argument onto the mixer passed as the second argument. The first mixer (that is going to be attached) must not already be attached to anything. Both mixers must use the same frequency, audio depth and channel configuration.

It is invalid to attach a mixer to itself.

Returns

True on success, False on error.

See also
al_detach_mixer
Detach the mixer from whatever it is attached to, if anything.
function al_set_mixer_postprocess_callback (mixer: ALLEGRO_MIXERptr; cb: ALLEGRO_MIXER_CALLBACK; data: AL_VOIDptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets a post-processing filter function that's called after the attached streams have been mixed. The buffer's format will be whatever the mixer was created with. The sample count and user-data pointer is also passed.

Note

The callback is called from a dedicated audio thread.

function al_get_mixer_frequency (const mixer: ALLEGRO_MIXERptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the mixer frequency (in Hz).

See also
al_set_mixer_frequency
Sets the mixer frequency (in Hz).
function al_get_mixer_channels (const mixer: ALLEGRO_MIXERptr): ALLEGRO_CHANNEL_CONF; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the mixer channel configuration.

See also
ALLEGRO_CHANNEL_CONF
Speaker configuration (mono, stereo, 2.1, etc).
function al_get_mixer_depth (const mixer: ALLEGRO_MIXERptr): ALLEGRO_AUDIO_DEPTH; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the mixer audio depth.

See also
ALLEGRO_AUDIO_DEPTH
Sample depth and type as well as signedness.
function al_get_mixer_quality (const mixer: ALLEGRO_MIXERptr): ALLEGRO_MIXER_QUALITY; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the mixer quality.

See also
ALLEGRO_MIXER_QUALITY
al_set_mixer_quality
Sets the mixer quality.
function al_get_mixer_gain (const mixer: ALLEGRO_MIXERptr): AL_FLOAT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the mixer gain (amplification factor). The default is 1.0.

See also
al_set_mixer_gain
Sets the mixer gain (amplification factor).
function al_get_mixer_playing (const mixer: ALLEGRO_MIXERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns True if the mixer is playing.

See also
al_set_mixer_playing
Changes whether the mixer is playing.
function al_get_mixer_attached (const mixer: ALLEGRO_MIXERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns True if the mixer is attached to something.

See also
al_attach_sample_instance_to_mixer
Attaches a sample instance to a mixer.
al_attach_audio_stream_to_mixer
Attaches an audio stream to a mixer.
al_attach_mixer_to_mixer
Attaches the mixer passed as the first argument onto the mixer passed as the second argument.
al_detach_mixer
Detach the mixer from whatever it is attached to, if anything.
function al_set_mixer_frequency (mixer: ALLEGRO_MIXERptr; val: AL_UINT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the mixer frequency (in Hz). This will only work if the mixer is not attached to anything.

Returns

True on success, False on failure.

See also
al_get_mixer_frequency
Returns the mixer frequency (in Hz).
function al_set_mixer_quality (mixer: ALLEGRO_MIXERptr; val: ALLEGRO_MIXER_QUALITY): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the mixer quality. This can only succeed if the mixer does not have anything attached to it. (al_get_mixer_quality)

Returns

True on success, False on failure.

See also
ALLEGRO_MIXER_QUALITY
function al_set_mixer_gain (mixer: ALLEGRO_MIXERptr; gain: AL_FLOAT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the mixer gain (amplification factor).

Returns

True on success, False on failure.

See also
al_get_mixer_gain
Returns the mixer gain (amplification factor).
function al_set_mixer_playing (mixer: ALLEGRO_MIXERptr; val: AL_BOOL): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Changes whether the mixer is playing.

Returns

True on success, False on failure.

See also
al_get_mixer_playing
Returns True if the mixer is playing.
function al_detach_mixer (mixer: ALLEGRO_MIXERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Detach the mixer from whatever it is attached to, if anything.

See also
al_attach_mixer_to_mixer
Attaches the mixer passed as the first argument onto the mixer passed as the second argument.
function al_create_voice (freq: AL_UINT; depth: ALLEGRO_AUDIO_DEPTH; chan_conf: ALLEGRO_CHANNEL_CONF): ALLEGRO_VOICEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Creates a voice structure and allocates a voice from the digital sound driver. The passed frequency (in HZ), sample format and channel configuration are used as a hint to what kind of data will be sent to the voice. However, the underlying sound driver is free to use non-matching values. For example, it may be the native format of the sound hardware.

If a mixer is attached to the voice, the mixer will handle the conversion of all its input streams to the voice format and care does not have to be taken for this. However if you access the voice directly, make sure to not rely on the parameters passed to this function, but instead query the returned voice for the actual settings.

See also
al_destroy_voice
Destroys the voice and deallocates it from the digital driver.
procedure al_destroy_voice (voice: ALLEGRO_VOICEptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Destroys the voice and deallocates it from the digital driver. Does nothing if the voice is Nil.

See also
al_create_voice
Creates a voice structure and allocates a voice from the digital sound driver.
function al_attach_sample_instance_to_voice (sample: ALLEGRO_SAMPLE_INSTANCEptr; voice: ALLEGRO_VOICEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Attaches a sample instance to a voice, and allows it to play. The instance's gain and loop mode will be ignored, and it must have the same frequency, channel configuration and depth (including signed-ness) as the voice. This function may fail if the selected driver doesn't support preloading sample data.

At this time, we don't recommend attaching sample instances directly to voices. Use a mixer inbetween. seealso(al_detach_voice)

Returns

True on success, False on failure.

function al_attach_audio_stream_to_voice (stream: ALLEGRO_AUDIO_STREAMptr; voice: ALLEGRO_VOICEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Attaches an audio stream to a voice. The same rules as al_attach_sample_instance_to_voice apply. This may fail if the driver can't create a voice with the buffer count and buffer size the stream uses.

An audio stream attached directly to a voice has a number of limitations: The audio stream plays immediately and cannot be stopped. The stream position, speed, gain and panning cannot be changed. At this time, we don't recommend attaching audio streams directly to voices. Use a mixer inbetween.

Returns

True on success, False on failure.

See also
al_detach_voice
Detaches the mixer, sample instance or audio stream from the voice.
function al_attach_mixer_to_voice (mixer: ALLEGRO_MIXERptr; voice: ALLEGRO_VOICEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Attaches a mixer to a voice. It must have the same frequency and channel configuration, but the depth may be different.

Returns

True on success, False on failure.

See also
al_detach_voice
Detaches the mixer, sample instance or audio stream from the voice.
procedure al_detach_voice (voice: ALLEGRO_VOICEptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Detaches the mixer, sample instance or audio stream from the voice.

See also
al_attach_mixer_to_voice
Attaches a mixer to a voice.
al_attach_sample_instance_to_voice
Attaches a sample instance to a voice, and allows it to play.
al_attach_audio_stream_to_voice
Attaches an audio stream to a voice.
function al_get_voice_frequency (const voice: ALLEGRO_VOICEptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the frequency of the voice (in Hz), e.g. 44100.

function al_get_voice_position (const voice: ALLEGRO_VOICEptr): AL_UINT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

When the voice has a non-streaming object attached to it, e.g. a sample, returns the voice's current sample position. Otherwise, returns zero.

See also
al_set_voice_position
Sets the voice position.
function al_get_voice_channels (const voice: ALLEGRO_VOICEptr): ALLEGRO_CHANNEL_CONF; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the channel configuration of the voice.

See also
ALLEGRO_CHANNEL_CONF
Speaker configuration (mono, stereo, 2.1, etc).
function al_get_voice_depth (const voice: ALLEGRO_VOICEptr): ALLEGRO_AUDIO_DEPTH; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the audio depth of the voice.

See also
ALLEGRO_AUDIO_DEPTH
Sample depth and type as well as signedness.
function al_get_voice_playing (const voice: ALLEGRO_VOICEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns True if the voice is currently playing.

See also
al_set_voice_playing
Changes whether a voice is playing or not.
function al_set_voice_position (voice: ALLEGRO_VOICEptr; val: AL_UINT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the voice position. This can only work if the voice has a non-streaming object attached to it, e.g. a sample instance.

Returns

True on success, False on failure.

See also
al_get_voice_position
When the voice has a non-streaming object attached to it, e.g.
function al_set_voice_playing (voice: ALLEGRO_VOICEptr; val: AL_BOOL): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Changes whether a voice is playing or not. This can only work if the voice has a non-streaming object attached to it, e.g. a sample instance. On success the voice's current sample position is reset.

Returns

True on success, False on failure.

See also
al_get_voice_playing
Returns True if the voice is currently playing.
function al_get_channel_count (conf: ALLEGRO_CHANNEL_CONF): AL_SIZE_T; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the number of channels for the given channel configuration, which is one of the values listed under ALLEGRO_CHANNEL_CONF.

function al_get_audio_depth_size (conf: ALLEGRO_AUDIO_DEPTH): AL_SIZE_T; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the size of a sample, in bytes, for the given format. The format is one of the values listed under ALLEGRO_AUDIO_DEPTH.

procedure al_fill_silence (bur: AL_VOIDptr; samples: AL_UINT; depth: ALLEGRO_AUDIO_DEPTH; chan_conf: ALLEGRO_CHANNEL_CONF); CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Fills a buffer with silence, for the given format and channel configuration. The buffer must have enough space for the given number of samples, and be properly aligned.

function al_get_num_audio_output_devices: AL_INT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Gets the number of available audio output devices on the system.

Returns

-1 for unsupported drivers.

See also
al_get_audio_output_device
Gets the output audio device of the specified index.
function al_get_audio_output_device (index: AL_INT): ALLEGRO_AUDIO_DEVICEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Gets the output audio device of the specified index.

See also
al_get_num_audio_output_devices
Gets the number of available audio output devices on the system.
al_get_audio_device_name
Gets the user friendly display name of the device.
function al_get_audio_device_name (device: ALLEGRO_AUDIO_DEVICEptr): AL_STRptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Gets the user friendly display name of the device.

See also
al_get_audio_output_device
Gets the output audio device of the specified index.
function al_reserve_samples (reserve_samples: AL_INT): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Reserves a number of sample instances, attaching them to the default mixer. If no default mixer is set when this function is called, then it will create one and attach it to the default voice. If no default voice has been set, it, too, will be created.

This diagram illustrates the structures that are set up:

                                      sample instance 1
                                    / sample instance 2
default voice <-- default mixer <---         .
                                    \        .
                                      sample instance N

Returns

True on success, False on error. al_install_audio must have been called first.

See also
al_set_default_mixer
Sets the default mixer.
al_play_sample
Plays a sample on one of the sample instances created by al_reserve_samples.
function al_get_default_mixer: ALLEGRO_MIXERptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the default mixer, or Nil if one has not been set. Although different configurations of mixers and voices can be used, in most cases a single mixer attached to a voice is what you want. The default mixer is used by al_play_sample.

See also
al_reserve_samples
Reserves a number of sample instances, attaching them to the default mixer.
al_play_sample
Plays a sample on one of the sample instances created by al_reserve_samples.
al_set_default_mixer
Sets the default mixer.
al_restore_default_mixer
Restores Allegro's default mixer and attaches it to the default voice.
function al_set_default_mixer (mixer: ALLEGRO_MIXERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Sets the default mixer. All samples started with al_play_sample will be stopped and all sample instances returned by al_lock_sample_id will be invalidated. If you are using your own mixer, this should be called before al_reserve_samples.

Returns

True on success, False on error.

See also
al_reserve_samples
Reserves a number of sample instances, attaching them to the default mixer.
al_play_sample
Plays a sample on one of the sample instances created by al_reserve_samples.
al_get_default_mixer
Returns the default mixer, or Nil if one has not been set.
al_restore_default_mixer
Restores Allegro's default mixer and attaches it to the default voice.
function al_restore_default_mixer: AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Restores Allegro's default mixer and attaches it to the default voice. If the default mixer hasn't been created before, it will be created. If the default voice hasn't been set via al_set_default_voice or created before, it will also be created. All samples started with al_play_sample will be stopped and all sample instances returned by al_lock_sample_id will be invalidated.

Returns

True on success, False on error.

See also
al_get_default_mixer
Returns the default mixer, or Nil if one has not been set.
al_set_default_mixer
Sets the default mixer.
al_reserve_samples
Reserves a number of sample instances, attaching them to the default mixer.
function al_play_sample (data: ALLEGRO_SAMPLEptr; gain, pan, speed: AL_FLOAT; loop: ALLEGRO_PLAYMODE; ret_id: ALLEGRO_SAMPLE_IDptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Plays a sample on one of the sample instances created by al_reserve_samples.

Parameters
gain
relative volume at which the sample is played; 1.0 is normal.
pan
0.0 is centred, -1.0 is left, 1.0 is right, or ALLEGRO_AUDIO_PAN_NONE.
speed
relative speed at which the sample is played; 1.0 is normal.
loop
ALLEGRO_PLAYMODE_ONCE, ALLEGRO_PLAYMODE_LOOP, or ALLEGRO_PLAYMODE_BIDIR.
ret_id
if non-Nil the variable which this points to will be assigned an id representing the sample being played.
Returns

True on success, False on failure. Playback may fail because all the reserved sample instances are currently used.

See also
ALLEGRO_PLAYMODE
Sample and stream playback mode.
ALLEGRO_AUDIO_PAN_NONE
A special value for the pan property of sample instances and audio streams.
ALLEGRO_SAMPLE_ID
An ALLEGRO_SAMPLE_ID represents a sample being played via al_play_sample.
al_stop_sample
Stops the sample started by al_play_sample.
al_stop_samples
Stops all samples started by al_play_sample.
procedure al_stop_sample (var spl_id: ALLEGRO_SAMPLE_ID); CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Stops the sample started by al_play_sample.

See also
al_stop_samples
Stops all samples started by al_play_sample.
procedure al_stop_samples; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Stops all samples started by al_play_sample.

See also
al_stop_sample
Stops the sample started by al_play_sample.
function al_get_default_voice: ALLEGRO_VOICEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the default voice or Nil if there is none.

See also
al_get_default_mixer
Returns the default mixer, or Nil if one has not been set.
procedure al_set_default_voice (voice: ALLEGRO_VOICEptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;

You can call this before calling al_restore_default_mixer to provide the voice which should be used. Any previous voice will be destroyed. You can also pass Nil to destroy the current default voice.

See also
al_get_default_mixer
Returns the default mixer, or Nil if one has not been set.
function al_lock_sample_id (var spl_id: ALLEGRO_SAMPLE_ID): ALLEGRO_SAMPLE_INSTANCEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Locks a ALLEGRO_SAMPLE_ID, returning the underlying ALLEGRO_SAMPLE_INSTANCEptr. This allows you to adjust the various properties of the instance (such as volume, pan, etc) while the sound is playing.

This function will return Nil if the sound corresponding to the id is no longer playing.

While locked, ALLEGRO_SAMPLE_ID will be unavailable to additional calls to al_play_sample, even if the sound stops while locked. To put the ALLEGRO_SAMPLE_ID back into the pool for reuse, make sure to call al_unlock_sample_id when you're done with the instance.

Unstable API: New API.

See also
al_play_sample
Plays a sample on one of the sample instances created by al_reserve_samples.
al_unlock_sample_id
Unlocks a ALLEGRO_SAMPLE_ID, allowing future calls to al_play_sample to reuse it if possible.
procedure al_unlock_sample_id (var spl_id: ALLEGRO_SAMPLE_ID); CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Unlocks a ALLEGRO_SAMPLE_ID, allowing future calls to al_play_sample to reuse it if possible. Note that after the id is unlocked, the ALLEGRO_SAMPLE_INSTANCEptr that was previously returned by al_lock_sample_id will possibly be playing a different sound, so you should only use it after locking the id again.

Unstable API: New API.

See also
al_play_sample
Plays a sample on one of the sample instances created by al_reserve_samples.
al_lock_sample_id
Locks a ALLEGRO_SAMPLE_ID, returning the underlying ALLEGRO_SAMPLE_INSTANCEptr.
function al_register_sample_loader (const ext: AL_STR; loader: ALLEGRO_SAMPLE_LOADER): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Registers a handler for al_load_sample. The given function will be used to handle the loading of sample files with the given extension.

The extension should include the leading dot ('.') character. It will be matched case-insensitively.

The loader argument may be Nil to unregister an entry.

Returns

True on success, False on error. Returns False if unregistering an entry that doesn't exist.

See also
al_register_sample_loader_f
Registers a handler for al_load_sample_f.
al_register_sample_saver
Registers a handler for al_save_sample.
function al_register_sample_saver (const ext: AL_STR; saver: ALLEGRO_SAMPLE_SAVER): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Registers a handler for al_save_sample. The given function will be used to handle the saving of sample files with the given extension.

The extension should include the leading dot ('.') character. It will be matched case-insensitively.

The saver argument may be Nil to unregister an entry.

Returns

True on success, False on error. Returns False if unregistering an entry that doesn't exist.

See also
al_register_sample_saver_f
Registers a handler for al_save_sample_f.
al_register_sample_loader
Registers a handler for al_load_sample.
function al_register_audio_stream_loader (const ext: AL_STR; stream_loader: ALLEGRO_AUDIO_STREAM_LOADER): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Registers a handler for al_load_audio_stream. The given function will be used to open streams from files with the given extension.

The extension should include the leading dot ('.') character. It will be matched case-insensitively.

The stream_loader argument may be Nil to unregister an entry.

Returns

True on success, False on error. Returns False if unregistering an entry that doesn't exist.

See also
al_register_audio_stream_loader_f
Registers a handler for al_load_audio_stream_f.
function al_register_sample_identifier (const ext: AL_STR; identifier: ALLEGRO_SAMPLE_IDENTIFIER_F): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Registers an identify handler for al_identify_sample. The given function will be used to detect files for the given extension. It will be called with a single argument of type ALLEGRO_FILEptr which is a file handle opened for reading and located at the first byte of the file. The handler should try to read as few bytes as possible to safely determine if the given file contents correspond to the type with the extension and return true in that case, false otherwise. The file handle must not be closed but there is no need to reset it to the beginning.

The extension should include the leading dot (‘.’) character. It will be matched case-insensitively.

The identifier argument may be Nil to unregister an entry.

Returns

True on success, False on error. It returns False if unregistering an entry that doesn’t exist.

See also
al_identify_bitmap
This works exactly as al_identify_bitmap_f but you specify the filename of the file for which to detect the type and not a file handle.
function al_register_sample_loader_f (const ext: AL_STR; loader: ALLEGRO_SAMPLE_LOADER_F): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Registers a handler for al_load_sample_f. The given function will be used to handle the loading of sample files with the given extension.

The extension should include the leading dot ('.') character. It will be matched case-insensitively.

The loader argument may be Nil to unregister an entry.

Returns

True on success, False on error. Returns False if unregistering an entry that doesn't exist.

See also
al_register_sample_loader
Registers a handler for al_load_sample.
function al_register_sample_saver_f (const ext: AL_STR; saver: ALLEGRO_SAMPLE_SAVER_F): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Registers a handler for al_save_sample_f. The given function will be used to handle the saving of sample files with the given extension.

The extension should include the leading dot ('.') character. It will be matched case-insensitively.

The saver argument may be Nil to unregister an entry.

Returns

True on success, False on error. Returns False if unregistering an entry that doesn't exist.

See also
al_register_sample_saver
Registers a handler for al_save_sample.
function al_register_audio_stream_loader_f (const ext: AL_STR; stream_loader: ALLEGRO_AUDIO_STREAM_LOADER_F): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Registers a handler for al_load_audio_stream_f. The given function will be used to open streams from files with the given extension.

The extension should include the leading dot ('.') character. It will be matched case-insensitively.

The stream_loader argument may be Nil to unregister an entry.

Returns

True on success, False on error. Returns False if unregistering an entry that doesn't exist.

See also
al_register_audio_stream_loader
Registers a handler for al_load_audio_stream.
function al_load_sample (const filename: AL_STR): ALLEGRO_SAMPLEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Loads a few different audio file formats based on their extension.

Note that this stores the entire file in memory at once, which may be time consuming. To read the file as it is needed, use al_load_audio_stream.

Note

the al5audio unit does not support any audio file formats by default. You must use the al5acodec addon, or register your own format handler.

Returns

The sample on success, Nil on failure.

See also
al_register_sample_loader
Registers a handler for al_load_sample.
al_init_acodec_addon
This procedure registers all the known audio file type handlers for al_load_sample, al_save_sample, al_load_audio_stream, etc.
function al_save_sample (const filename: AL_STR; spl: ALLEGRO_SAMPLEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Writes a sample into a file. Currently, wav is the only supported format, and the extension must be '.wav'.

Note

the al5acodec unit does not support any audio file formats by default. You must use the al5acodec addon, or register your own format handler.

Returns

True on success, False on error.

See also
al_save_sample_f
Writes a sample into a ALLEGRO_FILEptr filestream.
al_register_sample_saver
Registers a handler for al_save_sample.
al_init_acodec_addon
This procedure registers all the known audio file type handlers for al_load_sample, al_save_sample, al_load_audio_stream, etc.
function al_load_audio_stream (const filename: AL_STR; buffer_count: AL_SIZE_T; samples: AL_UINT): ALLEGRO_AUDIO_STREAMptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Loads an audio file from disk as it is needed.

Unlike regular streams, the one returned by this function need not be fed by the user; the library will automatically read more of the file as it is needed. The stream will contain buffer_count buffers with samples samples.

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_STREAMptr for more details.

Note

the al5audio library does not support any audio file formats by default. You must use the al5acodec addon, or register your own format handler.

Returns

the stream on success, Nil on failure.

See also
al_load_audio_stream_f
Loads an audio file from ALLEGRO_FILEptr stream as it is needed.
al_register_audio_stream_loader
Registers a handler for al_load_audio_stream.
al_init_acodec_addon
This procedure registers all the known audio file type handlers for al_load_sample, al_save_sample, al_load_audio_stream, etc.
function al_load_sample_f (fp: ALLEGRO_FILEptr; const ident: AL_STR): ALLEGRO_SAMPLEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Loads an audio file from an ALLEGRO_FILEptr tream into an ALLEGRO_SAMPLEptr. The file type is determined by the passed ident parameter, which is a file name extension including the leading dot.

Note that this stores the entire file in memory at once, which may be time consuming. To read the file as it is needed, use al_load_audio_stream_f.

Note

the al5audio add-on does not support any audio file formats by default. You must use the al5acodec addon, or register your own format handler.

Returns

the sample on success, Nil on failure. The file remains open afterwards.

See also
al_register_sample_loader_f
Registers a handler for al_load_sample_f.
al_init_acodec_addon
This procedure registers all the known audio file type handlers for al_load_sample, al_save_sample, al_load_audio_stream, etc.
function al_save_sample_f (fp: ALLEGRO_FILEptr; const ident: AL_STR; spl: ALLEGRO_FILEptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Writes a sample into a ALLEGRO_FILEptr filestream. Currently, wav is the only supported format, and the extension must be '.wav'.

Note

the al5audio add-on does not support any audio file formats by default. You must use the al5acodec addon, or register your own format handler.

Returns

True on success, False on error. The file remains open afterwards.

See also
al_save_sample
Writes a sample into a file.
al_register_sample_saver_f
Registers a handler for al_save_sample_f.
al_init_acodec_addon
This procedure registers all the known audio file type handlers for al_load_sample, al_save_sample, al_load_audio_stream, etc.
function al_load_audio_stream_f (fp: ALLEGRO_FILEptr; const ident: AL_STR; buffer_count: AL_SIZE_T; samples: AL_UINT): ALLEGRO_AUDIO_STREAMptr CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Loads an audio file from ALLEGRO_FILEptr stream as it is needed.

Unlike regular streams, the one returned by this function need not be fed by the user; the library will automatically read more of the file as it is needed. The stream will contain buffer_count buffers with samples samples.

The file type is determined by the passed ident parameter, which is a file name extension including the leading dot.

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_STREAMptr for more details.

Note

the al5audio library does not support any audio file formats by default. You must use the al5acodec addon, or register your own format handler.

Returns

the stream on success, Nil on failure. On success the file should be considered owned by the audio stream, and will be closed when the audio stream is destroyed. On failure the file will be closed.

See also
al_load_audio_stream
Loads an audio file from disk as it is needed.
al_register_audio_stream_loader_f
Registers a handler for al_load_audio_stream_f.
al_init_acodec_addon
This procedure registers all the known audio file type handlers for al_load_sample, al_save_sample, al_load_audio_stream, etc.
function al_identify_sample_f (p: ALLEGRO_FILEptr): AL_STRptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Tries to guess the audio file type of the open ALLEGRO_FILEptr by reading the first few bytes. By default Allegro cannot recognize any file types, but calling al_init_acodec_addon will add detection of the types it can read. You can also use al_register_sample_identifier to add identification for custom file types.

al_identify_sample al_register_sample_identifier

Returns

a pointer to a static string with a file extension for the type, including the leading dot. For example '.wav' or '.ogg. Returns Nil if the audio type cannot be determined.

See also
al_init_acodec_addon
This procedure registers all the known audio file type handlers for al_load_sample, al_save_sample, al_load_audio_stream, etc.
function al_identify_sample (filename: AL_STR): AL_STRptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

This works exactly as al_identify_sample_f but you specify the filename of the file for which to detect the type and not a file handle. The extension, if any, of the passed filename is not taken into account - only the file contents.

See also
al_init_acodec_addon
This procedure registers all the known audio file type handlers for al_load_sample, al_save_sample, al_load_audio_stream, etc.
al_identify_sample_f
Tries to guess the audio file type of the open ALLEGRO_FILEptr by reading the first few bytes.
al_register_sample_identifier
Registers an identify handler for al_identify_sample.
function al_create_audio_recorder (fragment_count: AL_SIZE_T; samples, freq: AL_UINT; depth: ALLEGRO_AUDIO_DEPTH; chan_conf: ALLEGRO_CHANNEL_CONF): ALLEGRO_AUDIO_RECORDERptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Creates an audio recorder using the system's default recording device. (So if the returned device does not work, try updating the system's default recording device.)

Allegro will internally buffer several seconds of captured audio with minimal latency. (XXX: These settings need to be exposed via config or API calls.) Audio will be copied out of that private buffer into a fragment buffer of the size specified by the samples parameter. Whenever a new fragment is ready an event will be generated.

The total size of the fragment buffer is fragment_count * samples * bytes_per_sample. It is treated as a circular, never ending buffer. If you do not process the information fast enough, it will be overrun. Because of that, even if you only ever need to process one small fragment at a time, you should still use a large enough value for fragment_count to hold a few seconds of audio.

frequency is the number of samples per second to record. Common values are:

  • 8000 - telephone quality speech

  • 11025

  • 22050

  • 44100 - CD quality music (if 16-bit, stereo)

For maximum compatibility, use a depth of ALLEGRO_AUDIO_DEPTH_UINT8 or ALLEGRO_AUDIO_DEPTH_INT16, and a single (mono) channel.

The recorder will not record until you start it with al_start_audio_recorder.

Unstable API: The API may need a slight redesign.

Returns

Pointer to recorder control object or Nil on failure.

See also
al_start_audio_recorder
Begin recording into the fragment buffer.
al_get_audio_recorder_event_source
Returns the event source for the recorder that generates the various recording events.
al_destroy_audio_recorder
Destroys the audio recorder and frees all resources associated with it.
function al_start_audio_recorder (r: ALLEGRO_AUDIO_RECORDERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Begin recording into the fragment buffer. Once a complete fragment has been captured (as specified in al_create_audio_recorder), an ALLEGRO_EVENT_AUDIO_RECORDER_FRAGMENT event will be triggered.

Unstable API: The API may need a slight redesign.

Returns

True if it was able to begin recording.

See also
al_stop_audio_recorder
Stop capturing audio data.
al_get_audio_recorder_event_source
Returns the event source for the recorder that generates the various recording events.
procedure al_stop_audio_recorder (r: ALLEGRO_AUDIO_RECORDERptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Stop capturing audio data. Note that the audio recorder is still active and consuming resources, so if you are finished recording you should destroy it with al_destroy_audio_recorder.

You may still receive a few events after you call this function as the device flushes the buffer.

If you restart the recorder, it will begin recording at the beginning of the next fragment buffer.

See also
al_start_audio_recorder
Begin recording into the fragment buffer.
function al_is_audio_recorder_recording (r: ALLEGRO_AUDIO_RECORDERptr): AL_BOOL; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns True if the audio recorder is currently capturing data and generating events.

Unstable API: The API may need a slight redesign.

function al_get_audio_recorder_event_source (r: ALLEGRO_AUDIO_RECORDERptr): ALLEGRO_EVENT_SOURCEptr; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the event source for the recorder that generates the various recording events.

Unstable API: The API may need a slight redesign.

See also
al_get_audio_recorder_event
Returns the event as an ALLEGRO_AUDIO_RECORDER_EVENT.
function al_get_audio_recorder_event (event: ALLEGRO_EVENT): ALLEGRO_AUDIO_RECORDER_EVENT; CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Returns the event as an ALLEGRO_AUDIO_RECORDER_EVENT.

Unstable API: The API may need a slight redesign.

procedure al_destroy_audio_recorder (r: ALLEGRO_AUDIO_RECORDERptr); CDECL; external ALLEGRO_AUDIO_LIB_NAME;

Destroys the audio recorder and frees all resources associated with it. It is safe to destroy a recorder that is recording.

You may receive events after the recorder has been destroyed. They must be ignored, as the fragment buffer will no longer be valid.

Unstable API: The API may need a slight redesign.

Types

ALLEGRO_AUDIO_RECORDERptr = type AL_POINTER;

An opaque datatype that represents a recording device.

Unstable API: The API may need a slight redesign.

ALLEGRO_AUDIO_DEPTH = (...);

Sample depth and type as well as signedness. Mixers only use 32-bit signed float (-1..+1), or 16-bit signed integers. Signedness is determined by an "unsigned" bit-flag applied to the depth value.

ALLEGRO_AUDIO_DEPTH_UINT8: INT8 + UNSIGNED

Values
  • ALLEGRO_AUDIO_DEPTH_INT8 = $00
  • ALLEGRO_AUDIO_DEPTH_INT16 = $01
  • ALLEGRO_AUDIO_DEPTH_INT24 = $02
  • ALLEGRO_AUDIO_DEPTH_FLOAT32 = $03
  • ALLEGRO_AUDIO_DEPTH_UNSIGNED = $08
  • ALLEGRO_AUDIO_DEPTH_UINT16 = $09: INT16 + UNSIGNED
  • ALLEGRO_AUDIO_DEPTH_UINT24 = $0A: INT24 + UNSIGNED
ALLEGRO_CHANNEL_CONF = (...);

Speaker configuration (mono, stereo, 2.1, etc).

Values
  • ALLEGRO_CHANNEL_CONF_1 = $10
  • ALLEGRO_CHANNEL_CONF_2 = $20
  • ALLEGRO_CHANNEL_CONF_3 = $30
  • ALLEGRO_CHANNEL_CONF_4 = $40
  • ALLEGRO_CHANNEL_CONF_5_1 = $51
  • ALLEGRO_CHANNEL_CONF_6_1 = $61
  • ALLEGRO_CHANNEL_CONF_7_1 = $71
ALLEGRO_PLAYMODE = (...);

Sample and stream playback mode.

Values
  • ALLEGRO_PLAYMODE_ONCE = $100: the sample/stream is played from start to finish an then it stops.
  • ALLEGRO_PLAYMODE_LOOP = $101: the sample/stream is played from start to finish (or between the two loop points). When it reaches the end, it restarts from the beginning.
  • ALLEGRO_PLAYMODE_BIDIR = $102: the sample is played from start to finish (or between the two loop points). When it reaches the end, it reverses the playback direction and plays until it reaches the beginning when it reverses the direction back to normal. This is mode is rarely supported for streams.
  • ALLEGRO_PLAYMODE_LOOP_ONCE = $105: just like ALLEGRO_PLAYMODE_ONCE, but respects the loop end point.
ALLEGRO_MIXER_QUALITY = (...);
 
Values
  • ALLEGRO_MIXER_QUALITY_POINT = $110: Point sampling.
  • ALLEGRO_MIXER_QUALITY_LINEAR = $111: Linear interpolation.
  • ALLEGRO_MIXER_QUALITY_CUBIC = $112: Cubic interpolation.
ALLEGRO_SAMPLEptr = type AL_POINTER;

Pointer to an Allegro sample object.

An Allegro sample object stores the data necessary for playing pre-defined digital audio. It holds a user-specified PCM data buffer and information about its format (data length, depth, frequency, channel configuration). You can have the same ALLEGRO_SAMPLE playing multiple times simultaneously.

See also
ALLEGRO_SAMPLE_INSTANCEptr
Pointer to an Allegro sample instance.
ALLEGRO_SAMPLE_IDptr = ˆALLEGRO_SAMPLE_ID;

Pointer to ALLEGRO_SAMPLE_ID.

ALLEGRO_SAMPLE_INSTANCEptr = AL_POINTER;

Pointer to an Allegro sample instance.

An Allegro sample instance represents a playable instance of a predefined sound effect. It holds information about how the effect should be played: These playback parameters consist of the looping mode, loop start/end points, playing position, speed, gain, pan and the playmode. Whether a sample instance is currently playing or paused is also one of its properties.

An instance uses the data from an Allegro sample object. Multiple instances may be created from the same ALLEGRO_SAMPLE. An ALLEGRO_SAMPLE must not be destroyed while there are instances which reference it.

To actually produce audio output, an ALLEGRO_SAMPLE_INSTANCEptr must be attached to an ALLEGRO_MIXERptr which eventually reaches an ALLEGRO_VOICEptr object.

See also
ALLEGRO_SAMPLEptr
Pointer to an Allegro sample object.
ALLEGRO_AUDIO_STREAMptr = AL_POINTER;

Pointer to an ALLEGRO_AUDIO_STREAM object that 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_INSTANCEptr 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_MIXERptr, which, eventually, reaches an ALLEGRO_VOICEptr 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 will also generate an ALLEGRO_EVENT_AUDIO_STREAM_FINISHED event if it reaches the end of the file and is not set to loop.

ALLEGRO_MIXERptr = AL_POINTER;

A mixer mixes together attached streams into a single buffer. In the process, it converts channel configurations, sample frequencies and audio depths of the attached sample instances and audio streams accordingly. You can control the quality of this conversion using ALLEGRO_MIXER_QUALITY.

When going from mono to stereo (and above), the mixer reduces the volume of both channels by sqrt(2). When going from stereo (and above) to mono, the mixer reduces the volume of the left and right channels by sqrt(2) before adding them to the center channel (if present).

ALLEGRO_VOICEptr = AL_POINTER;

A pointer to an Allegro voice.

A voice represents an audio device on the system, which may be a real device, or an abstract device provided by the operating system. To play back audio, you would attach a mixer, sample instance or audio stream to a voice.

See also
ALLEGRO_MIXERptr
A mixer mixes together attached streams into a single buffer.
ALLEGRO_SAMPLEptr
Pointer to an Allegro sample object.
ALLEGRO_AUDIO_STREAMptr
Pointer to an ALLEGRO_AUDIO_STREAM object that is used to stream generated audio to the sound device, in real-time.
ALLEGRO_AUDIO_DEVICEptr = AL_POINTER;

An opaque datatype that represents an audio device.

See also
al_get_audio_output_device
Gets the output audio device of the specified index.
ALLEGRO_MIXER_CALLBACK = procedure (buf: AL_VOIDptr; samples: AL_UINT; data: AL_VOIDptr); CDECL;
 
See also
al_set_mixer_postprocess_callback
Sets a post-processing filter function that's called after the attached streams have been mixed.
ALLEGRO_SAMPLE_LOADER = function (const filename: AL_STRptr): ALLEGRO_SAMPLEptr; CDECL;

Callback function to load samples.

See also
al_register_sample_loader
Registers a handler for al_load_sample.
ALLEGRO_SAMPLE_SAVER = function (const filename: AL_STRptr; spl: ALLEGRO_SAMPLEptr): AL_BOOL; CDECL;

Callback function to save samples.

See also
al_register_sample_saver
Registers a handler for al_save_sample.
ALLEGRO_AUDIO_STREAM_LOADER = function (const filename: AL_STRptr; buffer_count: AL_SIZE_T; samples: AL_UINT): ALLEGRO_AUDIO_STREAMptr; CDECL;

Callback function to load audio streams.

See also
al_register_audio_stream_loader
Registers a handler for al_load_audio_stream.
ALLEGRO_SAMPLE_LOADER_F = function (fp: ALLEGRO_FILEptr): ALLEGRO_SAMPLEptr; CDECL;

Callback function to load samples.

See also
al_register_sample_loader_f
Registers a handler for al_load_sample_f.
ALLEGRO_SAMPLE_SAVER_F = function (fp: ALLEGRO_FILEptr; spl: ALLEGRO_SAMPLEptr): AL_BOOL; CDECL;

Callback function to save samples.

See also
al_register_sample_saver_f
Registers a handler for al_save_sample_f.
ALLEGRO_AUDIO_STREAM_LOADER_F = function (fp: ALLEGRO_FILEptr; buffer_count: AL_SIZE_T; samples: AL_UINT): ALLEGRO_AUDIO_STREAMptr; CDECL;

Callback function to load audio streams.

See also
al_register_audio_stream_loader_f
Registers a handler for al_load_audio_stream_f.
ALLEGRO_SAMPLE_IDENTIFIER_F = function (fp: ALLEGRO_FILEptr): AL_BOOL; CDECL;
 

Constants

ALLEGRO_EVENT_AUDIO_STREAM_FRAGMENT = 513;

Sent when a stream fragment is ready to be filled in.

See also
al_get_audio_stream_fragment
When using Allegro's audio streaming, you will use this function to continuously provide new sample data to a stream.
ALLEGRO_EVENT_AUDIO_STREAM_FINISHED = 514;

Sent when a stream is finished.

ALLEGRO_EVENT_AUDIO_RECORDER_FRAGMENT = 515;

Sent after a user-specified number of samples have been recorded. Convert this to ALLEGRO_AUDIO_RECORDER_EVENT via al_get_audio_recorder_event.

You must always check the values for the buffer and samples as they are not guaranteed to be exactly what was originally specified.

Unstable API: The API may need a slight redesign.

ALLEGRO_AUDIO_PAN_NONE: AL_FLOAT = -1000.0;

A special value for the pan property of sample instances and audio streams. Use this value to disable panning on sample instances and audio streams, and play them without attentuation implied by panning support.

ALLEGRO_AUDIO_PAN_NONE is different from a pan value of 0.0 (centered) because, when panning is enabled, we try to maintain a constant sound power level as a sample is panned from left to right. A sound coming out of one speaker should sound as loud as it does when split over two speakers. As a consequence, a sample with pan value 0.0 will be 3 dB softer than the original level.

(Please correct us if this is wrong.)


Generated by PasDoc 0.15.0. Generated on 2024-11-10 15:15:06.