PulseAudio  16.0
sample.h File Reference

Constants and routines for sample type handling. More...

Go to the source code of this file.

Data Structures

struct  pa_sample_spec
 A sample format and attribute specification. More...
 

Macros

#define PA_CHANNELS_MAX   32U
 Maximum number of allowed channels. More...
 
#define PA_RATE_MAX   (48000U*8U)
 Maximum allowed sample rate. More...
 
#define PA_SAMPLE_S16NE   PA_SAMPLE_S16LE
 Signed 16 Bit PCM, native endian. More...
 
#define PA_SAMPLE_FLOAT32NE   PA_SAMPLE_FLOAT32LE
 32 Bit IEEE floating point, native endian More...
 
#define PA_SAMPLE_S32NE   PA_SAMPLE_S32LE
 Signed 32 Bit PCM, native endian. More...
 
#define PA_SAMPLE_S24NE   PA_SAMPLE_S24LE
 Signed 24 Bit PCM packed, native endian. More...
 
#define PA_SAMPLE_S24_32NE   PA_SAMPLE_S24_32LE
 Signed 24 Bit PCM in LSB of 32 Bit words, native endian. More...
 
#define PA_SAMPLE_S16RE   PA_SAMPLE_S16BE
 Signed 16 Bit PCM, reverse endian. More...
 
#define PA_SAMPLE_FLOAT32RE   PA_SAMPLE_FLOAT32BE
 32 Bit IEEE floating point, reverse endian More...
 
#define PA_SAMPLE_S32RE   PA_SAMPLE_S32BE
 Signed 32 Bit PCM, reverse endian. More...
 
#define PA_SAMPLE_S24RE   PA_SAMPLE_S24BE
 Signed 24 Bit PCM, packed reverse endian. More...
 
#define PA_SAMPLE_S24_32RE   PA_SAMPLE_S24_32BE
 Signed 24 Bit PCM, in LSB of 32 Bit words, reverse endian. More...
 
#define PA_SAMPLE_FLOAT32   PA_SAMPLE_FLOAT32NE
 A Shortcut for PA_SAMPLE_FLOAT32NE. More...
 
#define PA_SAMPLE_SPEC_SNPRINT_MAX   32
 Maximum required string length for pa_sample_spec_snprint(). More...
 
#define PA_BYTES_SNPRINT_MAX   11
 Maximum required string length for pa_bytes_snprint(). More...
 
#define pa_sample_format_is_ne(f)   pa_sample_format_is_le(f)
 Returns 1 when the specified format is native endian, 0 when not. More...
 
#define pa_sample_format_is_re(f)   pa_sample_format_is_be(f)
 Returns 1 when the specified format is reverse endian, 0 when native. More...
 

Typedefs

typedef enum pa_sample_format pa_sample_format_t
 Sample format. More...
 
typedef struct pa_sample_spec pa_sample_spec
 A sample format and attribute specification. More...
 
typedef uint64_t pa_usec_t
 Type for usec specifications (unsigned). More...
 

Enumerations

enum  pa_sample_format {
  PA_SAMPLE_U8 ,
  PA_SAMPLE_ALAW ,
  PA_SAMPLE_ULAW ,
  PA_SAMPLE_S16LE ,
  PA_SAMPLE_S16BE ,
  PA_SAMPLE_FLOAT32LE ,
  PA_SAMPLE_FLOAT32BE ,
  PA_SAMPLE_S32LE ,
  PA_SAMPLE_S32BE ,
  PA_SAMPLE_S24LE ,
  PA_SAMPLE_S24BE ,
  PA_SAMPLE_S24_32LE ,
  PA_SAMPLE_S24_32BE ,
  PA_SAMPLE_MAX ,
  PA_SAMPLE_INVALID = -1
}
 Sample format. More...
 

Functions

size_t pa_bytes_per_second (const pa_sample_spec *spec) PA_GCC_PURE
 Return the amount of bytes that constitute playback of one second of audio, with the specified sample spec. More...
 
size_t pa_frame_size (const pa_sample_spec *spec) PA_GCC_PURE
 Return the size of a frame with the specific sample type. More...
 
size_t pa_sample_size (const pa_sample_spec *spec) PA_GCC_PURE
 Return the size of a sample with the specific sample type. More...
 
size_t pa_sample_size_of_format (pa_sample_format_t f) PA_GCC_PURE
 Similar to pa_sample_size() but take a sample format instead of a full sample spec. More...
 
pa_usec_t pa_bytes_to_usec (uint64_t length, const pa_sample_spec *spec) PA_GCC_PURE
 Calculate the time it would take to play a buffer of the specified size with the specified sample type. More...
 
size_t pa_usec_to_bytes (pa_usec_t t, const pa_sample_spec *spec) PA_GCC_PURE
 Calculates the size of a buffer required, for playback duration of the time specified, with the specified sample type. More...
 
pa_sample_specpa_sample_spec_init (pa_sample_spec *spec)
 Initialize the specified sample spec and return a pointer to it. More...
 
int pa_sample_format_valid (unsigned format) PA_GCC_PURE
 Return non-zero if the given integer is a valid sample format. More...
 
int pa_sample_rate_valid (uint32_t rate) PA_GCC_PURE
 Return non-zero if the rate is within the supported range. More...
 
int pa_channels_valid (uint8_t channels) PA_GCC_PURE
 Return non-zero if the channel count is within the supported range. More...
 
int pa_sample_spec_valid (const pa_sample_spec *spec) PA_GCC_PURE
 Return non-zero when the sample type specification is valid. More...
 
int pa_sample_spec_equal (const pa_sample_spec *a, const pa_sample_spec *b) PA_GCC_PURE
 Return non-zero when the two sample type specifications match. More...
 
const char * pa_sample_format_to_string (pa_sample_format_t f) PA_GCC_PURE
 Return a descriptive string for the specified sample format. More...
 
pa_sample_format_t pa_parse_sample_format (const char *format) PA_GCC_PURE
 Parse a sample format text. More...
 
char * pa_sample_spec_snprint (char *s, size_t l, const pa_sample_spec *spec)
 Pretty print a sample type specification to a string. More...
 
char * pa_bytes_snprint (char *s, size_t l, unsigned v)
 Pretty print a byte size value (i.e. "2.5 MiB"). More...
 
int pa_sample_format_is_le (pa_sample_format_t f) PA_GCC_PURE
 Returns 1 when the specified format is little endian, 0 when big endian. More...
 
int pa_sample_format_is_be (pa_sample_format_t f) PA_GCC_PURE
 Returns 1 when the specified format is big endian, 0 when little endian. More...
 

Detailed Description

Constants and routines for sample type handling.

See also Sample Format Specifications

Macro Definition Documentation

◆ PA_BYTES_SNPRINT_MAX

#define PA_BYTES_SNPRINT_MAX   11

Maximum required string length for pa_bytes_snprint().

Please note that this value can change with any release without warning and without being considered API or ABI breakage. You should not use this definition anywhere where it might become part of an ABI.

Since
0.9.16

◆ PA_CHANNELS_MAX

#define PA_CHANNELS_MAX   32U

Maximum number of allowed channels.

◆ PA_RATE_MAX

#define PA_RATE_MAX   (48000U*8U)

Maximum allowed sample rate.

◆ PA_SAMPLE_FLOAT32

#define PA_SAMPLE_FLOAT32   PA_SAMPLE_FLOAT32NE

A Shortcut for PA_SAMPLE_FLOAT32NE.

◆ PA_SAMPLE_FLOAT32NE

#define PA_SAMPLE_FLOAT32NE   PA_SAMPLE_FLOAT32LE

32 Bit IEEE floating point, native endian

◆ PA_SAMPLE_FLOAT32RE

#define PA_SAMPLE_FLOAT32RE   PA_SAMPLE_FLOAT32BE

32 Bit IEEE floating point, reverse endian

◆ pa_sample_format_is_ne

#define pa_sample_format_is_ne (   f)    pa_sample_format_is_le(f)

Returns 1 when the specified format is native endian, 0 when not.

Returns -1 when endianness does not apply to the specified format, or endianess is unknown.

Since
0.9.16

◆ pa_sample_format_is_re

#define pa_sample_format_is_re (   f)    pa_sample_format_is_be(f)

Returns 1 when the specified format is reverse endian, 0 when native.

Returns -1 when endianness does not apply to the specified format, or endianess is unknown.

Since
0.9.16

◆ PA_SAMPLE_S16NE

#define PA_SAMPLE_S16NE   PA_SAMPLE_S16LE

Signed 16 Bit PCM, native endian.

◆ PA_SAMPLE_S16RE

#define PA_SAMPLE_S16RE   PA_SAMPLE_S16BE

Signed 16 Bit PCM, reverse endian.

◆ PA_SAMPLE_S24_32NE

#define PA_SAMPLE_S24_32NE   PA_SAMPLE_S24_32LE

Signed 24 Bit PCM in LSB of 32 Bit words, native endian.

Since
0.9.15

◆ PA_SAMPLE_S24_32RE

#define PA_SAMPLE_S24_32RE   PA_SAMPLE_S24_32BE

Signed 24 Bit PCM, in LSB of 32 Bit words, reverse endian.

Since
0.9.15

◆ PA_SAMPLE_S24NE

#define PA_SAMPLE_S24NE   PA_SAMPLE_S24LE

Signed 24 Bit PCM packed, native endian.

Since
0.9.15

◆ PA_SAMPLE_S24RE

#define PA_SAMPLE_S24RE   PA_SAMPLE_S24BE

Signed 24 Bit PCM, packed reverse endian.

Since
0.9.15

◆ PA_SAMPLE_S32NE

#define PA_SAMPLE_S32NE   PA_SAMPLE_S32LE

Signed 32 Bit PCM, native endian.

◆ PA_SAMPLE_S32RE

#define PA_SAMPLE_S32RE   PA_SAMPLE_S32BE

Signed 32 Bit PCM, reverse endian.

◆ PA_SAMPLE_SPEC_SNPRINT_MAX

#define PA_SAMPLE_SPEC_SNPRINT_MAX   32

Maximum required string length for pa_sample_spec_snprint().

Please note that this value can change with any release without warning and without being considered API or ABI breakage. You should not use this definition anywhere where it might become part of an ABI.

Typedef Documentation

◆ pa_sample_format_t

Sample format.

◆ pa_sample_spec

A sample format and attribute specification.

◆ pa_usec_t

typedef uint64_t pa_usec_t

Type for usec specifications (unsigned).

Always 64 bit.

Enumeration Type Documentation

◆ pa_sample_format

Sample format.

Enumerator
PA_SAMPLE_U8 

Unsigned 8 Bit PCM.

PA_SAMPLE_ALAW 

8 Bit a-Law

PA_SAMPLE_ULAW 

8 Bit mu-Law

PA_SAMPLE_S16LE 

Signed 16 Bit PCM, little endian (PC)

PA_SAMPLE_S16BE 

Signed 16 Bit PCM, big endian.

PA_SAMPLE_FLOAT32LE 

32 Bit IEEE floating point, little endian (PC), range -1.0 to 1.0

PA_SAMPLE_FLOAT32BE 

32 Bit IEEE floating point, big endian, range -1.0 to 1.0

PA_SAMPLE_S32LE 

Signed 32 Bit PCM, little endian (PC)

PA_SAMPLE_S32BE 

Signed 32 Bit PCM, big endian.

PA_SAMPLE_S24LE 

Signed 24 Bit PCM packed, little endian (PC).

Since
0.9.15
PA_SAMPLE_S24BE 

Signed 24 Bit PCM packed, big endian.

Since
0.9.15
PA_SAMPLE_S24_32LE 

Signed 24 Bit PCM in LSB of 32 Bit words, little endian (PC).

Since
0.9.15
PA_SAMPLE_S24_32BE 

Signed 24 Bit PCM in LSB of 32 Bit words, big endian.

Since
0.9.15
PA_SAMPLE_MAX 

Upper limit of valid sample types.

PA_SAMPLE_INVALID 

An invalid value.

Function Documentation

◆ pa_bytes_per_second()

size_t pa_bytes_per_second ( const pa_sample_spec spec)

Return the amount of bytes that constitute playback of one second of audio, with the specified sample spec.

◆ pa_bytes_snprint()

char* pa_bytes_snprint ( char *  s,
size_t  l,
unsigned  v 
)

Pretty print a byte size value (i.e. "2.5 MiB").

Returns s.

◆ pa_bytes_to_usec()

pa_usec_t pa_bytes_to_usec ( uint64_t  length,
const pa_sample_spec spec 
)

Calculate the time it would take to play a buffer of the specified size with the specified sample type.

The return value will always be rounded down for non-integral return values.

◆ pa_channels_valid()

int pa_channels_valid ( uint8_t  channels)

Return non-zero if the channel count is within the supported range.

Since
5.0

◆ pa_frame_size()

size_t pa_frame_size ( const pa_sample_spec spec)

Return the size of a frame with the specific sample type.

◆ pa_parse_sample_format()

pa_sample_format_t pa_parse_sample_format ( const char *  format)

Parse a sample format text.

Inverse of pa_sample_format_to_string()

◆ pa_sample_format_is_be()

int pa_sample_format_is_be ( pa_sample_format_t  f)

Returns 1 when the specified format is big endian, 0 when little endian.

Returns -1 when endianness does not apply to the specified format, or endianess is unknown.

Since
0.9.16

◆ pa_sample_format_is_le()

int pa_sample_format_is_le ( pa_sample_format_t  f)

Returns 1 when the specified format is little endian, 0 when big endian.

Returns -1 when endianness does not apply to the specified format, or endianess is unknown.

Since
0.9.16

◆ pa_sample_format_to_string()

const char* pa_sample_format_to_string ( pa_sample_format_t  f)

Return a descriptive string for the specified sample format.

Since
0.8

◆ pa_sample_format_valid()

int pa_sample_format_valid ( unsigned  format)

Return non-zero if the given integer is a valid sample format.

Since
5.0

◆ pa_sample_rate_valid()

int pa_sample_rate_valid ( uint32_t  rate)

Return non-zero if the rate is within the supported range.

Since
5.0

◆ pa_sample_size()

size_t pa_sample_size ( const pa_sample_spec spec)

Return the size of a sample with the specific sample type.

◆ pa_sample_size_of_format()

size_t pa_sample_size_of_format ( pa_sample_format_t  f)

Similar to pa_sample_size() but take a sample format instead of a full sample spec.

Since
0.9.15

◆ pa_sample_spec_equal()

int pa_sample_spec_equal ( const pa_sample_spec a,
const pa_sample_spec b 
)

Return non-zero when the two sample type specifications match.

◆ pa_sample_spec_init()

pa_sample_spec* pa_sample_spec_init ( pa_sample_spec spec)

Initialize the specified sample spec and return a pointer to it.

The sample spec will have a defined state but pa_sample_spec_valid() will fail for it.

Since
0.9.13

◆ pa_sample_spec_snprint()

char* pa_sample_spec_snprint ( char *  s,
size_t  l,
const pa_sample_spec spec 
)

Pretty print a sample type specification to a string.

Returns s.

◆ pa_sample_spec_valid()

int pa_sample_spec_valid ( const pa_sample_spec spec)

Return non-zero when the sample type specification is valid.

◆ pa_usec_to_bytes()

size_t pa_usec_to_bytes ( pa_usec_t  t,
const pa_sample_spec spec 
)

Calculates the size of a buffer required, for playback duration of the time specified, with the specified sample type.

The return value will always be rounded down for non-integral return values.

Since
0.9