# The audio output layer

## Data exchanges between a decoder and the audio output

The audio output basically takes audio samples from one or several FIFOs, mixes and resamples them, and plays them through the audio chip. Data exchanges are simple and described in `src/audio_output/audio_output.c.` A decoder needs to open a channel FIFO with `aout_CreateFifo` , and then write the data to the buffer. The buffer is in `p_aout_fifo->buffer + p_aout_fifo->l_end_frame` * `ADEC_FRAME_SIZE`.

## How to write an audio output plugin

[This API is subject to change in the very near future.] Have a look at `plugins/dsp/aout_dsp.c`. You need to write six functions :

- int `aout_Probe` `( probedata_t *p_data )` : Returns a score between 0 and 999 to tell whether the plugin can be used. `p_data` is currently unused.

- int `aout_Open` `( aout_thread_t *p_aout )` : Opens the audio device.

- int `aout_SetFormat` `( aout_thread_t *p_aout )` : Sets the output format, the number of channels, and the output rate.

- long `aout_GetBufInfo` `( aout_thread_t *p_aout, long l_buffer_limit )` : Gets the status of the audio buffer.

- `aout_Play` `( aout_thread_t *p_aout, byte_t *buffer, int i_size )` : Writes the audio output buffer to the audio device.

- `aout_Close` `( aout_thread_t *p_aout )` : Closes the audio device.