# The audio output layer

## Audio output overview

This chapter documents the audio output layer known under the "audio output 3" codename. It has first been released with VLC version 0.5.0. Previous versions use an antic API, which is no longer documented nor supported. You definitely should write new code only for aout3 and later.

The audio output's main purpose is to take sound samples from one or several decoders (called "input streams" in this chapter), to mix them and write them to an output device (called "output stream"). During this process, transformations may be needed or asked by the user, and they will be performed by audio filters.

(insert here a schematic of the data flow in aout3)

### Typical runcourse

The input spawns a new decoder audio decoder, say for instance an A/52 decoder. The A/52 decoder parses the sync info for format information, and creates a new aout "input stream" whith aout_InputNew().

## API for the decoders

## API for the output module

## Writing an audio filter

## Writing an audio mixer

## 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.