Audio format definitions
Audio

Definitions for several variations of audio data. More...

## Data Structures

struct | gavl_audio_format_t
| Audio Format. More...

## Macros

#define | GAVL_MAX_CHANNELS 128
| Maximum number of audio channels.

## Enumerations

enum | gavl_sample_format_t { GAVL_SAMPLE_NONE = 0 , GAVL_SAMPLE_U8 = 1 , GAVL_SAMPLE_S8 = 2 , GAVL_SAMPLE_U16 = 3 , GAVL_SAMPLE_S16 = 4 , GAVL_SAMPLE_S32 = 5 , GAVL_SAMPLE_FLOAT = 6 , GAVL_SAMPLE_DOUBLE = 7 }
| Format of one audio sample. More...
enum | gavl_interleave_mode_t { GAVL_INTERLEAVE_NONE = 0 , GAVL_INTERLEAVE_2 = 1 , GAVL_INTERLEAVE_ALL = 2 }
enum | gavl_channel_id_t { GAVL_CHID_NONE = 0 , GAVL_CHID_FRONT_CENTER , GAVL_CHID_FRONT_LEFT , GAVL_CHID_FRONT_RIGHT , GAVL_CHID_FRONT_CENTER_LEFT , GAVL_CHID_FRONT_CENTER_RIGHT , GAVL_CHID_REAR_LEFT , GAVL_CHID_REAR_RIGHT , GAVL_CHID_REAR_CENTER , GAVL_CHID_SIDE_LEFT , GAVL_CHID_SIDE_RIGHT , GAVL_CHID_LFE , GAVL_CHID_AUX }
| Audio channel setup. More...

## Functions

GAVL_PUBLIC const char * | gavl_sample_format_to_string (gavl_sample_format_t format)
| Convert a gavl_sample_format_t to a human readable string.
GAVL_PUBLIC const char * | gavl_sample_format_to_short_string (gavl_sample_format_t format)
| Convert a gavl_sample_format_t to a human readable string.
GAVL_PUBLIC gavl_sample_format_t | gavl_string_to_sample_format (const char *str)
| Convert a string to a sample format.
GAVL_PUBLIC gavl_sample_format_t | gavl_short_string_to_sample_format (const char *format)
| Convert a short string to a gavl_sample_format_t.
GAVL_PUBLIC int | gavl_num_sample_formats (void)
| Get total number of supported sample formats.
GAVL_PUBLIC gavl_sample_format_t | gavl_get_sample_format (int index)
| Get the sample format from index.
GAVL_PUBLIC const char * | gavl_channel_id_to_string (gavl_channel_id_t id)
| Convert a gavl_channel_id_t to a human readable string.
GAVL_PUBLIC const char * | gavl_channel_id_to_short_string (gavl_channel_id_t id)
| Convert a gavl_channel_id_t to a short string.
GAVL_PUBLIC gavl_channel_id_t | gavl_short_string_to_channel_id (const char *id)
| Convert short string to a gavl_channel_id_t.
GAVL_PUBLIC const char * | gavl_interleave_mode_to_string (gavl_interleave_mode_t mode)
| Convert a gavl_interleave_mode_t to a human readable string.
GAVL_PUBLIC const char * | gavl_interleave_mode_to_short_string (gavl_interleave_mode_t mode)
| Convert a gavl_interleave_mode_t to a short string.
GAVL_PUBLIC gavl_interleave_mode_t | gavl_short_string_to_interleave_mode (const char *mode)
| Convert a short string to a gavl_interleave_mode_t.
GAVL_PUBLIC void | gavl_audio_format_dump (const gavl_audio_format_t *format)
| Dump an audio format to stderr.
GAVL_PUBLIC void | gavl_audio_format_dumpi (const gavl_audio_format_t *format, int indent)
| Dump an audio format to stderr.
GAVL_PUBLIC int | gavl_channel_index (const gavl_audio_format_t *format, gavl_channel_id_t id)
| Get the index of a particular channel for a given format.
GAVL_PUBLIC int | gavl_front_channels (const gavl_audio_format_t *format)
| Get number of front channels for a given format.
GAVL_PUBLIC int | gavl_rear_channels (const gavl_audio_format_t *format)
| Get number of rear channels for a given format.
GAVL_PUBLIC int | gavl_side_channels (const gavl_audio_format_t *format)
| Get number of side channels for a given format.
GAVL_PUBLIC int | gavl_aux_channels (const gavl_audio_format_t *format)
| Get number of aux channels for a given format.
GAVL_PUBLIC int | gavl_lfe_channels (const gavl_audio_format_t *format)
| Get number of LFE channels for a given format.
GAVL_PUBLIC void | gavl_audio_format_copy (gavl_audio_format_t *dst, const gavl_audio_format_t *src)
| Copy one audio format to another.
GAVL_PUBLIC int | gavl_audio_formats_equal (const gavl_audio_format_t *format_1, const gavl_audio_format_t *format_2)
| Compare 2 audio formats.
GAVL_PUBLIC void | gavl_set_channel_setup (gavl_audio_format_t *format)
| Set the default channel setup and indices.
GAVL_PUBLIC int | gavl_bytes_per_sample (gavl_sample_format_t format)
| Get the number of bytes per sample for a given sample format.
GAVL_PUBLIC int | gavl_nearest_samplerate (int in_rate, const int *supported)
| Get the nearest samplerate out of a list of supported rates.

## Detailed Description

Definitions for several variations of audio data.

## Macro Definition Documentation

## GAVL_MAX_CHANNELS

#define GAVL_MAX_CHANNELS 128

Maximum number of audio channels.

## Enumeration Type Documentation

## gavl_sample_format_t

enum gavl_sample_format_t

Format of one audio sample.

For multibyte numbers, the byte order is always machine native endian

Enumerator
GAVL_SAMPLE_NONE | Undefined
GAVL_SAMPLE_U8 | Unsigned 8 bit
GAVL_SAMPLE_S8 | Signed 8 bit
GAVL_SAMPLE_U16 | Unsigned 16 bit
GAVL_SAMPLE_S16 | Signed 16 bit
GAVL_SAMPLE_S32 | Signed 32 bit
GAVL_SAMPLE_FLOAT | Floating point (-1.0 .. 1.0)
GAVL_SAMPLE_DOUBLE | Double (-1.0 .. 1.0)

## gavl_interleave_mode_t

enum gavl_interleave_mode_t

Interleave mode of the channels

Enumerator
GAVL_INTERLEAVE_NONE | No interleaving, all channels separate
GAVL_INTERLEAVE_2 | Interleaved pairs of channels
GAVL_INTERLEAVE_ALL | Everything interleaved

## gavl_channel_id_t

enum gavl_channel_id_t

Audio channel setup.

These are the channel locations used to identify the channel order for an audio format

Enumerator
GAVL_CHID_NONE | Undefined
GAVL_CHID_FRONT_CENTER | For mono
GAVL_CHID_FRONT_LEFT | Front left
GAVL_CHID_FRONT_RIGHT | Front right
GAVL_CHID_FRONT_CENTER_LEFT | Left of Center
GAVL_CHID_FRONT_CENTER_RIGHT | Right of Center
GAVL_CHID_REAR_LEFT | Rear left
GAVL_CHID_REAR_RIGHT | Rear right
GAVL_CHID_REAR_CENTER | Rear Center
GAVL_CHID_SIDE_LEFT | Side left
GAVL_CHID_SIDE_RIGHT | Side right
GAVL_CHID_LFE | Subwoofer
GAVL_CHID_AUX | Additional channel (can be more than one)

## Function Documentation

## gavl_sample_format_to_string()

GAVL_PUBLIC const char * gavl_sample_format_to_string | ( | gavl_sample_format_t | format | ) |

Convert a gavl_sample_format_t to a human readable string.

Parameters

  format | A sample format

Returns
  A human readable string describing the format

## gavl_sample_format_to_short_string()

GAVL_PUBLIC const char * gavl_sample_format_to_short_string | ( | gavl_sample_format_t | format | ) |

Convert a gavl_sample_format_t to a human readable string.

Parameters

  format | A sample format

Returns
  A short string describing the format

## gavl_string_to_sample_format()

GAVL_PUBLIC gavl_sample_format_t gavl_string_to_sample_format | ( | const char * | str | ) |

Convert a string to a sample format.

Parameters

  str | String

str must be one of the strings returned by gavl_sample_format_to_string

## gavl_short_string_to_sample_format()

GAVL_PUBLIC gavl_sample_format_t gavl_short_string_to_sample_format | ( | const char * | format | ) |

Convert a short string to a gavl_sample_format_t.

Parameters

  format | A string returned by gavl_sample_format_to_short_string

Returns
  A short string describing the format

## gavl_num_sample_formats()

GAVL_PUBLIC int gavl_num_sample_formats | ( | void |  | ) |

Get total number of supported sample formats.

Returns
  total number of supported sample formats

## gavl_get_sample_format()

GAVL_PUBLIC gavl_sample_format_t gavl_get_sample_format | ( | int | index | ) |

Get the sample format from index.

Parameters

  index | index (must be between 0 and the result of gavl_num_sample_formats)

Returns
  The sample format corresponding to index or GAVL_SAMPLE_NONE.

## gavl_channel_id_to_string()

GAVL_PUBLIC const char * gavl_channel_id_to_string | ( | gavl_channel_id_t | id | ) |

Convert a gavl_channel_id_t to a human readable string.

Parameters

  id | A channel id

Returns
  A human readable string

## gavl_channel_id_to_short_string()

GAVL_PUBLIC const char * gavl_channel_id_to_short_string | ( | gavl_channel_id_t | id | ) |

Convert a gavl_channel_id_t to a short string.

Parameters

  id | A channel id

Returns
  A short string

## gavl_short_string_to_channel_id()

GAVL_PUBLIC gavl_channel_id_t gavl_short_string_to_channel_id | ( | const char * | id | ) |

Convert short string to a gavl_channel_id_t.

Parameters

  id | A short string

Returns
  A channel id

## gavl_interleave_mode_to_string()

GAVL_PUBLIC const char * gavl_interleave_mode_to_string | ( | gavl_interleave_mode_t | mode | ) |

Convert a gavl_interleave_mode_t to a human readable string.

Parameters

  mode | An interleave mode

Returns
  A human readable string

## gavl_interleave_mode_to_short_string()

GAVL_PUBLIC const char * gavl_interleave_mode_to_short_string | ( | gavl_interleave_mode_t | mode | ) |

Convert a gavl_interleave_mode_t to a short string.

Parameters

  mode | An interleave mode

Returns
  A short string

## gavl_short_string_to_interleave_mode()

GAVL_PUBLIC gavl_interleave_mode_t gavl_short_string_to_interleave_mode | ( | const char * | mode | ) |

Convert a short string to a gavl_interleave_mode_t.

Parameters

  mode | A short string

Returns
  An interleave mode

## gavl_audio_format_dump()

GAVL_PUBLIC void gavl_audio_format_dump | ( | const gavl_audio_format_t * | format | ) |

Dump an audio format to stderr.

Parameters

  format | An audio format

## gavl_audio_format_dumpi()

GAVL_PUBLIC void gavl_audio_format_dumpi | ( | const gavl_audio_format_t * | format,
|  | int | indent )

Dump an audio format to stderr.

Parameters

  format | An audio format
  indent | Indentation

Like gavl_audio_format_dump but it places indent whitespaces in front of each line

Since 1.5.0

## gavl_channel_index()

GAVL_PUBLIC int gavl_channel_index | ( | const gavl_audio_format_t * | format,
|  | gavl_channel_id_t | id )

Get the index of a particular channel for a given format.

Parameters

  format | An audio format
  id | A channel id

Returns
  The index of the channel in the format or -1 if such a channel is not present

## gavl_front_channels()

GAVL_PUBLIC int gavl_front_channels | ( | const gavl_audio_format_t * | format | ) |

Get number of front channels for a given format.

Parameters

  format | An audio format

## gavl_rear_channels()

GAVL_PUBLIC int gavl_rear_channels | ( | const gavl_audio_format_t * | format | ) |

Get number of rear channels for a given format.

Parameters

  format | An audio format

## gavl_side_channels()

GAVL_PUBLIC int gavl_side_channels | ( | const gavl_audio_format_t * | format | ) |

Get number of side channels for a given format.

Parameters

  format | An audio format

## gavl_aux_channels()

GAVL_PUBLIC int gavl_aux_channels | ( | const gavl_audio_format_t * | format | ) |

Get number of aux channels for a given format.

Parameters

  format | An audio format

## gavl_lfe_channels()

GAVL_PUBLIC int gavl_lfe_channels | ( | const gavl_audio_format_t * | format | ) |

Get number of LFE channels for a given format.

Parameters

  format | An audio format

## gavl_audio_format_copy()

GAVL_PUBLIC void gavl_audio_format_copy | ( | gavl_audio_format_t * | dst,
|  | const gavl_audio_format_t * | src )

Copy one audio format to another.

Parameters

  dst | Destination format
  src | Source format

## gavl_audio_formats_equal()

GAVL_PUBLIC int gavl_audio_formats_equal | ( | const gavl_audio_format_t * | format_1,
|  | const gavl_audio_format_t * | format_2 )

Compare 2 audio formats.

Parameters

  format_1 | First format
  format_2 | Second format

Returns
  1 if the formats are equal, 0 else

## gavl_set_channel_setup()

GAVL_PUBLIC void gavl_set_channel_setup | ( | gavl_audio_format_t * | format | ) |

Set the default channel setup and indices.

Parameters

  format | An audio format

Set a default channel setup and channel indices if only the number of channels is known. The result might be wrong if you have something else than mono or stereo from a stream, which has no informtions about the speaker configurations.

## gavl_bytes_per_sample()

GAVL_PUBLIC int gavl_bytes_per_sample | ( | gavl_sample_format_t | format | ) |

Get the number of bytes per sample for a given sample format.

Parameters

  format | A sample format

## gavl_nearest_samplerate()

GAVL_PUBLIC int gavl_nearest_samplerate | ( | int | in_rate,
|  | const int * | supported )

Get the nearest samplerate out of a list of supported rates.

Parameters

  in_rate | Source samplerate
  supported | Array of supported samplerates (0 terminated)

Returns
  The nearest supported samplerate

Since 1.5.0