Data formats
The QNX Sound Architecture supports a variety of data formats.
Data format constants
The <sys/asound.h> header file defines two sets of constants for the data formats. The two sets are related (and easily converted between) but serve different purposes:
- SND_PCM_SFMT_*
- A single selection from the set of data formats. For a list of the supported formats,
see snd_pcm_get_format_name() in the
Audio Library
chapter. - SND_PCM_FMT_*
- A group of (one or more) formats within a single variable. This is useful for specifying the format capabilities of a device, for example.
Generally, the SND_PCM_FMT_* constants are used to convey information about raw potential, and the SND_PCM_SFMT_* constants are used to select and report a specific configuration.
You can build a format from its width and other attributes, by calling snd_pcm_build_linear_format().
You can use these functions to check the characteristics of a format:
24-bit audio format
Data for 24-bit audio is represented as either 3 bytes or 4 bytes.
In most cases, audio files store 24-bit data as 3 bytes.
Because your hardware likely requires 32-bit aligned data access, the 24-bit data is usually converted to 4 bytes. The 24-bit sample in the 32-bit integer can have one of the following types of alignment:
- Left-aligned — QSA recognizes and handles a left-aligned 24-bit value in a 32-bit integer as a 32-bit sample value, with no loss in efficiency.
- Right-aligned — If the hardware requires 24-bit samples to be right-aligned in a 32-bit container, use the 24_4 data format constant. For playback, QSA upsamples 24-bit data to 32-bit for all processing and then converts it from 32-bit to 24_4 before passing it to the hardware. Likewise, for capture, QSA can accept 24_4 and convert it to 32-bit for processing.
