Buffers

A Buffer encapsulates AL state related to storing sample data. The application can request and release Buffer objects, and fill them with data. Data can be supplied compressed and encoded as long as the format is supported. Buffers can, internally, contain waveform data as uncompressed or compressed samples.

Unlike Sources and Listener, Buffer Objects can be shared among AL contexts. Buffers are referenced by Sources. A single Buffer can be referred to by multiple Sources. This separation allows drivers and hardware to optimize storage and processing where applicable.

The simplest supported format for buffer data is PCM.

NoteAnnotation/ Compressed Buffers
 

Compressed formats are in no way guaranteed by the implementation to remain compressed. The driver might have to uncompres in memory at once, if no hardware-assisted or incremental decoding is possible. In many cases an implementation has to decompress the buffer, converting the uncompressed data to a canonical internal format, and resample it into the format native to the current context.

NoteRFC: Compressed Buffers
 

MikeV suggests: an application can query the amount of memory buffer is consuming. He suggests using GetBufferi(AL_SIZE, ... ). This seems a bad idea as (a) the application is not meant to micromanage driver-internal memory, (b) the memory requirements known to the application might differ from the actual, (c) there are OS mechanisms to query free memory, (d) AL_SIZE is now ambiguous as it announces app-side memory as allocated vs. driver side memory as used by the driver. For clarity AL_INTERNAL_SIZE (analog to internal format enums) might be a better choice.

Buffer States

At this time, Buffer states are defined for purposes of discussion. The states described in this section are not exposed through the API (can not be queried, or be set directly), and the state description used in the implementation might differ from this.

A Buffer is considered to be in one of the following States, with respect to all Sources:

The Buffer state is dependent on the state of all Sources that is has been queued for. A single queue occurrence of a Buffer propagates the Buffer state (over all Sources) from UNUSED to PROCESSED or higher. Sources that are STOPPED or INITIAL still have queue entries that cause Buffers to be PROCESSED.

A single queue entry with a single Source for which the Buffer is not yet PROCESSED propagates the buffer's queueing state to PENDING.

Buffers that are PROCESSED for a given Source can be unqueued from that Source's queue. Buffers that have been unqueued from all Sources are UNUSED. Buffers that are UNUSED can be deleted, or changed by BufferData commands.

NoteAnnotation (No CURRENT State)
 

For buffer queueing, it is not relevant whether the Buffer data is currently dereferenced by any Source or not. It is therefore not necessary to distinguish a CURRENT state (being referenced as current buffer by a single PLAYING or PAUSED Source).

NoteAnnotation (State Query and Shared Buffers)
 

A buffer that is unused by one Source might be used by another. The Unqueue operation is determined by the number of queue entries already processed by the given Source. However, the application has to check whether the Buffer is still in use by other Sources. For now, applications have to maintain their own lists of buffer consumer (source) lists. If necessary, an explicit call to determine current buffer state with respect to all Sources might be added in future revisions.

NoteRFC: IsBufferProcessed?
 

Instead of exposing the internal state, a simple boolean query whether a buffer can be deleted or refilled can be used.

NoteRFC: BufferData on QUEUED
 

The error on using BufferData in QUEUED buffers is introduced because the implementation might not be able to guarantee when the Buffer is dereferenced. Applications have to account for the possibility that the Buffer is dereferenced at the latest possible moment, e.g. when it becomes CURRENT. As it is easier to relax this restricition at a later time (no effect on backwards compatibility) than doing the reverse, we are conserative here.

NoteRFC: Buffer State Query
 

Buffer State could be queried using alBuffer(), but it can't be set. Prohibiting deferred deletion of buffers would make such a state query desirable.