Audio devices are opened exclusively for a selected direction. This does not allow open from more than one processes for the same audio device in the same direction, but does allow one open call to each playback direction and second open call to record direction independently. Audio devices return EBUSY error to applications when other applications have already opened the requested direction.
The driver supports these sample formats:
Format | Description |
---|---|
SND_PCM_SFMT_S8 | Signed 8-bit sample. |
SND_PCM_SFMT_U8 | Unsigned 8-bit sample. |
SND_PCM_SFMT_S16_LE | Signed little endian 16-bit sample. |
SND_PCM_SFMT_S16_BE | Signed big endian 16-bit sample. |
SND_PCM_SFMT_U16_LE | Unsigned little endian 16-bit sample. |
SND_PCM_SFMT_U16_BE | Unsigned big endian 16-bit sample. |
SND_PCM_SFMT_S24_LE | Signed little endian 24-bit sample (in 32-bit word). |
SND_PCM_SFMT_S24_BE | Signed big endian 24-bit sample (in 32-bit word). |
SND_PCM_SFMT_U24_LE | Unsigned little endian 24-bit sample (in 32-bit word). |
SND_PCM_SFMT_U24_BE | Unsigned big endian 24-bit sample (in 32-bit word). |
SND_PCM_SFMT_S32_LE | Signed little endian 32-bit sample. |
SND_PCM_SFMT_S32_BE | Signed big endian 32-bit sample. |
SND_PCM_SFMT_U32_LE | Unsigned little endian 32-bit sample. |
SND_PCM_SFMT_U32_BE | Unsigned big endian 32-bit sample. |
SND_PCM_SFMT_FLOAT_LE | Little endian float in 32-bit word (IEE-754). |
SND_PCM_SFMT_FLOAT_BE | Big endian float in 32-bit word (IEE-754). |
SND_PCM_SFMT_FLOAT64_LE | Little endian float in 64-bit word (IEE-754). |
SND_PCM_SFMT_FLOAT64_BE | Big endian float in 64-bit word (IEE-754). |
SND_PCM_SFMT_MU_LAW | Mu-law compression (one byte per sample). |
SND_PCM_SFMT_A_LAW | A-law compression (one byte per sample). |
SND_PCM_SFMT_IMA_ADPCM | Ima ADPCM compression (four bits per sample). |
SND_PCM_SFMT_MPEG | MPEG compression. |
SND_PCM_SFMT_GSM | GSM compression. |
SND_PCM_SFMT_SPECIAL | Hardware dependent sample format. |
Constants with prefix SND_PCM_FMT_ are used in info structures (bitmaps) and constants with prefix SND_PCM_SFMT_ are used in format structures.
24-bit linear samples are using three low bytes from the 32-bit word. When hardware uses 24-bit format in 32-bit linear samples (the low byte is ignored), then the sample format is 32-bit, and the msbits_per_sample member from the snd_pcm_channel_setup_t structure shows count of most significant bits being used (24 in this case). The other formats (for example 20-bit linear sample stored in the 32-bit linear sample) may follow this example as well.
ALSA PCM API uses two operating modes - block and stream. The block mode uses an enhanced double buffering scheme. This allows the user to implement a more comfortable buffer setup. Audio buffer is separated to small fragments. Each fragment has the same size. Application can set wakeup limits like ``I want to get captured data when at least two fragments with size 160 bytes are filled.''. For more information you should see description of snd_pcm_channel_params_t and snd_pcm_channel_status_t structures and the snd_pcm_channel_setup function, documented below.
The stream mode may be used for real-time audio applications. The driver allows to transfer data with the sample resolution. The process using the audio device in this mode is never blocked. Only one parameter for buffering is required - queue size. There are no other boundaries like fragments. The driver directly operates with the hardware ring buffer in this mode.
The ALSA drivers does not offer the data conversions on the fly at all. If you want to write an application which is able to run on most hardware, use the PCM plugin layer.
The driver manages various states. The PCM calls, available at some time, depend heavy on the current state.
State | Description |
---|---|
SND_PCM_STATUS_NOTREADY | The driver is not prepared for any operation. After successful snd_pcm_channel_params call the state will be changed to SND_PCM_STATUS_READY. |
SND_PCM_STATUS_READY | The driver is ready for operation. The audio buffer may be mmaped only at this moment, but the samples can not be still transferred. After successful snd_pcm_channel_prepare call the state will be changed to SND_PCM_STATUS_PREPARED. |
SND_PCM_STATUS_PREPARED | The driver is prepared for operation. The samples may be transferred at this moment. |
SND_PCM_STATUS_RUNNING | The driver manages running stream. The samples may be transferred at this moment. |
SND_PCM_STATUS_UNDERRUN | The playback direction is in underrun state. It means that the driver did not get the data in right time. Only snd_pcm_playback_prepare call or snd_pcm_playback_flush call or snd_pcm_playback_drain call may change this state. |
SND_PCM_STATUS_OVERRUN | The capture direction is in overrun state. It means that hardware have not received the data in right time. Only snd_pcm_capture_prepare call or snd_pcm_capture_flush call may change this state. |
SND_PCM_STATUS_PAUSE | The playback is paused. |