153a5a1b3Sopenharmony_ci#ifndef foosamplehfoo
253a5a1b3Sopenharmony_ci#define foosamplehfoo
353a5a1b3Sopenharmony_ci
453a5a1b3Sopenharmony_ci/***
553a5a1b3Sopenharmony_ci  This file is part of PulseAudio.
653a5a1b3Sopenharmony_ci
753a5a1b3Sopenharmony_ci  Copyright 2004-2006 Lennart Poettering
853a5a1b3Sopenharmony_ci  Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
953a5a1b3Sopenharmony_ci
1053a5a1b3Sopenharmony_ci  PulseAudio is free software; you can redistribute it and/or modify
1153a5a1b3Sopenharmony_ci  it under the terms of the GNU Lesser General Public License as published
1253a5a1b3Sopenharmony_ci  by the Free Software Foundation; either version 2.1 of the License,
1353a5a1b3Sopenharmony_ci  or (at your option) any later version.
1453a5a1b3Sopenharmony_ci
1553a5a1b3Sopenharmony_ci  PulseAudio is distributed in the hope that it will be useful, but
1653a5a1b3Sopenharmony_ci  WITHOUT ANY WARRANTY; without even the implied warranty of
1753a5a1b3Sopenharmony_ci  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1853a5a1b3Sopenharmony_ci  General Public License for more details.
1953a5a1b3Sopenharmony_ci
2053a5a1b3Sopenharmony_ci  You should have received a copy of the GNU Lesser General Public License
2153a5a1b3Sopenharmony_ci  along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
2253a5a1b3Sopenharmony_ci***/
2353a5a1b3Sopenharmony_ci
2453a5a1b3Sopenharmony_ci#include <inttypes.h>
2553a5a1b3Sopenharmony_ci#include <sys/types.h>
2653a5a1b3Sopenharmony_ci#include <sys/param.h>
2753a5a1b3Sopenharmony_ci
2853a5a1b3Sopenharmony_ci#include <pulse/gccmacro.h>
2953a5a1b3Sopenharmony_ci#include <pulse/cdecl.h>
3053a5a1b3Sopenharmony_ci#include <pulse/version.h>
3153a5a1b3Sopenharmony_ci
3253a5a1b3Sopenharmony_ci/** \page sample Sample Format Specifications
3353a5a1b3Sopenharmony_ci *
3453a5a1b3Sopenharmony_ci * \section overv_sec Overview
3553a5a1b3Sopenharmony_ci *
3653a5a1b3Sopenharmony_ci * PulseAudio is capable of handling a multitude of sample formats, rates
3753a5a1b3Sopenharmony_ci * and channels, transparently converting and mixing them as needed.
3853a5a1b3Sopenharmony_ci *
3953a5a1b3Sopenharmony_ci * \section format_sec Sample Format
4053a5a1b3Sopenharmony_ci *
4153a5a1b3Sopenharmony_ci * PulseAudio supports the following sample formats:
4253a5a1b3Sopenharmony_ci *
4353a5a1b3Sopenharmony_ci * \li PA_SAMPLE_U8 - Unsigned 8 bit integer PCM.
4453a5a1b3Sopenharmony_ci * \li PA_SAMPLE_S16LE - Signed 16 integer bit PCM, little endian.
4553a5a1b3Sopenharmony_ci * \li PA_SAMPLE_S16BE - Signed 16 integer bit PCM, big endian.
4653a5a1b3Sopenharmony_ci * \li PA_SAMPLE_FLOAT32LE - 32 bit IEEE floating point PCM, little endian.
4753a5a1b3Sopenharmony_ci * \li PA_SAMPLE_FLOAT32BE - 32 bit IEEE floating point PCM, big endian.
4853a5a1b3Sopenharmony_ci * \li PA_SAMPLE_ALAW - 8 bit a-Law.
4953a5a1b3Sopenharmony_ci * \li PA_SAMPLE_ULAW - 8 bit mu-Law.
5053a5a1b3Sopenharmony_ci * \li PA_SAMPLE_S32LE - Signed 32 bit integer PCM, little endian.
5153a5a1b3Sopenharmony_ci * \li PA_SAMPLE_S32BE - Signed 32 bit integer PCM, big endian.
5253a5a1b3Sopenharmony_ci * \li PA_SAMPLE_S24LE - Signed 24 bit integer PCM packed, little endian.
5353a5a1b3Sopenharmony_ci * \li PA_SAMPLE_S24BE - Signed 24 bit integer PCM packed, big endian.
5453a5a1b3Sopenharmony_ci * \li PA_SAMPLE_S24_32LE - Signed 24 bit integer PCM in LSB of 32 bit words, little endian.
5553a5a1b3Sopenharmony_ci * \li PA_SAMPLE_S24_32BE - Signed 24 bit integer PCM in LSB of 32 bit words, big endian.
5653a5a1b3Sopenharmony_ci *
5753a5a1b3Sopenharmony_ci * The floating point sample formats have the range from -1.0 to 1.0.
5853a5a1b3Sopenharmony_ci *
5953a5a1b3Sopenharmony_ci * The sample formats that are sensitive to endianness have convenience
6053a5a1b3Sopenharmony_ci * macros for native endian (NE), and reverse endian (RE).
6153a5a1b3Sopenharmony_ci *
6253a5a1b3Sopenharmony_ci * \section rate_sec Sample Rates
6353a5a1b3Sopenharmony_ci *
6453a5a1b3Sopenharmony_ci * PulseAudio supports any sample rate between 1 Hz and 192000 Hz. There is no
6553a5a1b3Sopenharmony_ci * point trying to exceed the sample rate of the output device though as the
6653a5a1b3Sopenharmony_ci * signal will only get downsampled, consuming CPU on the machine running the
6753a5a1b3Sopenharmony_ci * server.
6853a5a1b3Sopenharmony_ci *
6953a5a1b3Sopenharmony_ci * \section chan_sec Channels
7053a5a1b3Sopenharmony_ci *
7153a5a1b3Sopenharmony_ci * PulseAudio supports up to 32 individual channels. The order of the
7253a5a1b3Sopenharmony_ci * channels is up to the application, but they must be continuous. To map
7353a5a1b3Sopenharmony_ci * channels to speakers, see \ref channelmap.
7453a5a1b3Sopenharmony_ci *
7553a5a1b3Sopenharmony_ci * \section calc_sec Calculations
7653a5a1b3Sopenharmony_ci *
7753a5a1b3Sopenharmony_ci * The PulseAudio library contains a number of convenience functions to do
7853a5a1b3Sopenharmony_ci * calculations on sample formats:
7953a5a1b3Sopenharmony_ci *
8053a5a1b3Sopenharmony_ci * \li pa_bytes_per_second() - The number of bytes one second of audio will
8153a5a1b3Sopenharmony_ci *                             take given a sample format.
8253a5a1b3Sopenharmony_ci * \li pa_frame_size() - The size, in bytes, of one frame (i.e. one set of
8353a5a1b3Sopenharmony_ci *                       samples, one for each channel).
8453a5a1b3Sopenharmony_ci * \li pa_sample_size() - The size, in bytes, of one sample.
8553a5a1b3Sopenharmony_ci * \li pa_bytes_to_usec() - Calculate the time it would take to play a buffer
8653a5a1b3Sopenharmony_ci *                          of a certain size.
8753a5a1b3Sopenharmony_ci *
8853a5a1b3Sopenharmony_ci * \section util_sec Convenience Functions
8953a5a1b3Sopenharmony_ci *
9053a5a1b3Sopenharmony_ci * The library also contains a couple of other convenience functions:
9153a5a1b3Sopenharmony_ci *
9253a5a1b3Sopenharmony_ci * \li pa_sample_spec_valid() - Tests if a sample format specification is
9353a5a1b3Sopenharmony_ci *                              valid.
9453a5a1b3Sopenharmony_ci * \li pa_sample_spec_equal() - Tests if the sample format specifications are
9553a5a1b3Sopenharmony_ci *                              identical.
9653a5a1b3Sopenharmony_ci * \li pa_sample_format_to_string() - Return a textual description of a
9753a5a1b3Sopenharmony_ci *                                    sample format.
9853a5a1b3Sopenharmony_ci * \li pa_parse_sample_format() - Parse a text string into a sample format.
9953a5a1b3Sopenharmony_ci * \li pa_sample_spec_snprint() - Create a textual description of a complete
10053a5a1b3Sopenharmony_ci *                                 sample format specification.
10153a5a1b3Sopenharmony_ci * \li pa_bytes_snprint() - Pretty print a byte value (e.g. 2.5 MiB).
10253a5a1b3Sopenharmony_ci */
10353a5a1b3Sopenharmony_ci
10453a5a1b3Sopenharmony_ci/** \file
10553a5a1b3Sopenharmony_ci * Constants and routines for sample type handling
10653a5a1b3Sopenharmony_ci *
10753a5a1b3Sopenharmony_ci * See also \subpage sample
10853a5a1b3Sopenharmony_ci */
10953a5a1b3Sopenharmony_ci
11053a5a1b3Sopenharmony_ciPA_C_DECL_BEGIN
11153a5a1b3Sopenharmony_ci
11253a5a1b3Sopenharmony_ci#if !defined(WORDS_BIGENDIAN)
11353a5a1b3Sopenharmony_ci
11453a5a1b3Sopenharmony_ci#if defined(__BYTE_ORDER)
11553a5a1b3Sopenharmony_ci#if __BYTE_ORDER == __BIG_ENDIAN
11653a5a1b3Sopenharmony_ci#define WORDS_BIGENDIAN
11753a5a1b3Sopenharmony_ci#endif
11853a5a1b3Sopenharmony_ci#endif
11953a5a1b3Sopenharmony_ci
12053a5a1b3Sopenharmony_ci/* On Sparc, WORDS_BIGENDIAN needs to be set if _BIG_ENDIAN is defined. */
12153a5a1b3Sopenharmony_ci#if defined(__sparc__) && defined(_BIG_ENDIAN)
12253a5a1b3Sopenharmony_ci#define WORDS_BIGENDIAN
12353a5a1b3Sopenharmony_ci#endif
12453a5a1b3Sopenharmony_ci
12553a5a1b3Sopenharmony_ci#endif
12653a5a1b3Sopenharmony_ci
12753a5a1b3Sopenharmony_ci/** Maximum number of allowed channels */
12853a5a1b3Sopenharmony_ci#define PA_CHANNELS_MAX 32U
12953a5a1b3Sopenharmony_ci
13053a5a1b3Sopenharmony_ci/** Maximum allowed sample rate */
13153a5a1b3Sopenharmony_ci#define PA_RATE_MAX (48000U*8U)
13253a5a1b3Sopenharmony_ci
13353a5a1b3Sopenharmony_ci/** Sample format */
13453a5a1b3Sopenharmony_citypedef enum pa_sample_format {
13553a5a1b3Sopenharmony_ci    PA_SAMPLE_U8,
13653a5a1b3Sopenharmony_ci    /**< Unsigned 8 Bit PCM */
13753a5a1b3Sopenharmony_ci
13853a5a1b3Sopenharmony_ci    PA_SAMPLE_ALAW,
13953a5a1b3Sopenharmony_ci    /**< 8 Bit a-Law */
14053a5a1b3Sopenharmony_ci
14153a5a1b3Sopenharmony_ci    PA_SAMPLE_ULAW,
14253a5a1b3Sopenharmony_ci    /**< 8 Bit mu-Law */
14353a5a1b3Sopenharmony_ci
14453a5a1b3Sopenharmony_ci    PA_SAMPLE_S16LE,
14553a5a1b3Sopenharmony_ci    /**< Signed 16 Bit PCM, little endian (PC) */
14653a5a1b3Sopenharmony_ci
14753a5a1b3Sopenharmony_ci    PA_SAMPLE_S16BE,
14853a5a1b3Sopenharmony_ci    /**< Signed 16 Bit PCM, big endian */
14953a5a1b3Sopenharmony_ci
15053a5a1b3Sopenharmony_ci    PA_SAMPLE_FLOAT32LE,
15153a5a1b3Sopenharmony_ci    /**< 32 Bit IEEE floating point, little endian (PC), range -1.0 to 1.0 */
15253a5a1b3Sopenharmony_ci
15353a5a1b3Sopenharmony_ci    PA_SAMPLE_FLOAT32BE,
15453a5a1b3Sopenharmony_ci    /**< 32 Bit IEEE floating point, big endian, range -1.0 to 1.0 */
15553a5a1b3Sopenharmony_ci
15653a5a1b3Sopenharmony_ci    PA_SAMPLE_S32LE,
15753a5a1b3Sopenharmony_ci    /**< Signed 32 Bit PCM, little endian (PC) */
15853a5a1b3Sopenharmony_ci
15953a5a1b3Sopenharmony_ci    PA_SAMPLE_S32BE,
16053a5a1b3Sopenharmony_ci    /**< Signed 32 Bit PCM, big endian */
16153a5a1b3Sopenharmony_ci
16253a5a1b3Sopenharmony_ci    PA_SAMPLE_S24LE,
16353a5a1b3Sopenharmony_ci    /**< Signed 24 Bit PCM packed, little endian (PC). \since 0.9.15 */
16453a5a1b3Sopenharmony_ci
16553a5a1b3Sopenharmony_ci    PA_SAMPLE_S24BE,
16653a5a1b3Sopenharmony_ci    /**< Signed 24 Bit PCM packed, big endian. \since 0.9.15 */
16753a5a1b3Sopenharmony_ci
16853a5a1b3Sopenharmony_ci    PA_SAMPLE_S24_32LE,
16953a5a1b3Sopenharmony_ci    /**< Signed 24 Bit PCM in LSB of 32 Bit words, little endian (PC). \since 0.9.15 */
17053a5a1b3Sopenharmony_ci
17153a5a1b3Sopenharmony_ci    PA_SAMPLE_S24_32BE,
17253a5a1b3Sopenharmony_ci    /**< Signed 24 Bit PCM in LSB of 32 Bit words, big endian. \since 0.9.15 */
17353a5a1b3Sopenharmony_ci
17453a5a1b3Sopenharmony_ci    /* Remeber to update
17553a5a1b3Sopenharmony_ci     * https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/SupportedAudioFormats/
17653a5a1b3Sopenharmony_ci     * when adding new formats! */
17753a5a1b3Sopenharmony_ci
17853a5a1b3Sopenharmony_ci    PA_SAMPLE_MAX,
17953a5a1b3Sopenharmony_ci    /**< Upper limit of valid sample types */
18053a5a1b3Sopenharmony_ci
18153a5a1b3Sopenharmony_ci    PA_SAMPLE_INVALID = -1
18253a5a1b3Sopenharmony_ci    /**< An invalid value */
18353a5a1b3Sopenharmony_ci} pa_sample_format_t;
18453a5a1b3Sopenharmony_ci
18553a5a1b3Sopenharmony_ci#ifdef WORDS_BIGENDIAN
18653a5a1b3Sopenharmony_ci/** Signed 16 Bit PCM, native endian */
18753a5a1b3Sopenharmony_ci#define PA_SAMPLE_S16NE PA_SAMPLE_S16BE
18853a5a1b3Sopenharmony_ci/** 32 Bit IEEE floating point, native endian */
18953a5a1b3Sopenharmony_ci#define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32BE
19053a5a1b3Sopenharmony_ci/** Signed 32 Bit PCM, native endian */
19153a5a1b3Sopenharmony_ci#define PA_SAMPLE_S32NE PA_SAMPLE_S32BE
19253a5a1b3Sopenharmony_ci/** Signed 24 Bit PCM packed, native endian. \since 0.9.15 */
19353a5a1b3Sopenharmony_ci#define PA_SAMPLE_S24NE PA_SAMPLE_S24BE
19453a5a1b3Sopenharmony_ci/** Signed 24 Bit PCM in LSB of 32 Bit words, native endian. \since 0.9.15 */
19553a5a1b3Sopenharmony_ci#define PA_SAMPLE_S24_32NE PA_SAMPLE_S24_32BE
19653a5a1b3Sopenharmony_ci
19753a5a1b3Sopenharmony_ci/** Signed 16 Bit PCM reverse endian */
19853a5a1b3Sopenharmony_ci#define PA_SAMPLE_S16RE PA_SAMPLE_S16LE
19953a5a1b3Sopenharmony_ci/** 32 Bit IEEE floating point, reverse endian */
20053a5a1b3Sopenharmony_ci#define PA_SAMPLE_FLOAT32RE PA_SAMPLE_FLOAT32LE
20153a5a1b3Sopenharmony_ci/** Signed 32 Bit PCM, reverse endian */
20253a5a1b3Sopenharmony_ci#define PA_SAMPLE_S32RE PA_SAMPLE_S32LE
20353a5a1b3Sopenharmony_ci/** Signed 24 Bit PCM, packed reverse endian. \since 0.9.15 */
20453a5a1b3Sopenharmony_ci#define PA_SAMPLE_S24RE PA_SAMPLE_S24LE
20553a5a1b3Sopenharmony_ci/** Signed 24 Bit PCM, in LSB of 32 Bit words, reverse endian. \since 0.9.15 */
20653a5a1b3Sopenharmony_ci#define PA_SAMPLE_S24_32RE PA_SAMPLE_S24_32LE
20753a5a1b3Sopenharmony_ci#else
20853a5a1b3Sopenharmony_ci/** Signed 16 Bit PCM, native endian */
20953a5a1b3Sopenharmony_ci#define PA_SAMPLE_S16NE PA_SAMPLE_S16LE
21053a5a1b3Sopenharmony_ci/** 32 Bit IEEE floating point, native endian */
21153a5a1b3Sopenharmony_ci#define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32LE
21253a5a1b3Sopenharmony_ci/** Signed 32 Bit PCM, native endian */
21353a5a1b3Sopenharmony_ci#define PA_SAMPLE_S32NE PA_SAMPLE_S32LE
21453a5a1b3Sopenharmony_ci/** Signed 24 Bit PCM packed, native endian. \since 0.9.15 */
21553a5a1b3Sopenharmony_ci#define PA_SAMPLE_S24NE PA_SAMPLE_S24LE
21653a5a1b3Sopenharmony_ci/** Signed 24 Bit PCM in LSB of 32 Bit words, native endian. \since 0.9.15 */
21753a5a1b3Sopenharmony_ci#define PA_SAMPLE_S24_32NE PA_SAMPLE_S24_32LE
21853a5a1b3Sopenharmony_ci
21953a5a1b3Sopenharmony_ci/** Signed 16 Bit PCM, reverse endian */
22053a5a1b3Sopenharmony_ci#define PA_SAMPLE_S16RE PA_SAMPLE_S16BE
22153a5a1b3Sopenharmony_ci/** 32 Bit IEEE floating point, reverse endian */
22253a5a1b3Sopenharmony_ci#define PA_SAMPLE_FLOAT32RE PA_SAMPLE_FLOAT32BE
22353a5a1b3Sopenharmony_ci/** Signed 32 Bit PCM, reverse endian */
22453a5a1b3Sopenharmony_ci#define PA_SAMPLE_S32RE PA_SAMPLE_S32BE
22553a5a1b3Sopenharmony_ci/** Signed 24 Bit PCM, packed reverse endian. \since 0.9.15 */
22653a5a1b3Sopenharmony_ci#define PA_SAMPLE_S24RE PA_SAMPLE_S24BE
22753a5a1b3Sopenharmony_ci/** Signed 24 Bit PCM, in LSB of 32 Bit words, reverse endian. \since 0.9.15 */
22853a5a1b3Sopenharmony_ci#define PA_SAMPLE_S24_32RE PA_SAMPLE_S24_32BE
22953a5a1b3Sopenharmony_ci#endif
23053a5a1b3Sopenharmony_ci
23153a5a1b3Sopenharmony_ci/** A Shortcut for PA_SAMPLE_FLOAT32NE */
23253a5a1b3Sopenharmony_ci#define PA_SAMPLE_FLOAT32 PA_SAMPLE_FLOAT32NE
23353a5a1b3Sopenharmony_ci
23453a5a1b3Sopenharmony_ci/** \cond fulldocs */
23553a5a1b3Sopenharmony_ci/* Allow clients to check with #ifdef for these sample formats */
23653a5a1b3Sopenharmony_ci#define PA_SAMPLE_U8 PA_SAMPLE_U8
23753a5a1b3Sopenharmony_ci#define PA_SAMPLE_ALAW PA_SAMPLE_ALAW
23853a5a1b3Sopenharmony_ci#define PA_SAMPLE_ULAW PA_SAMPLE_ULAW
23953a5a1b3Sopenharmony_ci#define PA_SAMPLE_S16LE PA_SAMPLE_S16LE
24053a5a1b3Sopenharmony_ci#define PA_SAMPLE_S16BE PA_SAMPLE_S16BE
24153a5a1b3Sopenharmony_ci#define PA_SAMPLE_FLOAT32LE PA_SAMPLE_FLOAT32LE
24253a5a1b3Sopenharmony_ci#define PA_SAMPLE_FLOAT32BE PA_SAMPLE_FLOAT32BE
24353a5a1b3Sopenharmony_ci#define PA_SAMPLE_S32LE PA_SAMPLE_S32LE
24453a5a1b3Sopenharmony_ci#define PA_SAMPLE_S32BE PA_SAMPLE_S32BE
24553a5a1b3Sopenharmony_ci#define PA_SAMPLE_S24LE PA_SAMPLE_S24LE
24653a5a1b3Sopenharmony_ci#define PA_SAMPLE_S24BE PA_SAMPLE_S24BE
24753a5a1b3Sopenharmony_ci#define PA_SAMPLE_S24_32LE PA_SAMPLE_S24_32LE
24853a5a1b3Sopenharmony_ci#define PA_SAMPLE_S24_32BE PA_SAMPLE_S24_32BE
24953a5a1b3Sopenharmony_ci/** \endcond */
25053a5a1b3Sopenharmony_ci
25153a5a1b3Sopenharmony_ci/** A sample format and attribute specification */
25253a5a1b3Sopenharmony_citypedef struct pa_sample_spec {
25353a5a1b3Sopenharmony_ci    pa_sample_format_t format;
25453a5a1b3Sopenharmony_ci    /**< The sample format */
25553a5a1b3Sopenharmony_ci
25653a5a1b3Sopenharmony_ci    uint32_t rate;
25753a5a1b3Sopenharmony_ci    /**< The sample rate. (e.g. 44100) */
25853a5a1b3Sopenharmony_ci
25953a5a1b3Sopenharmony_ci    uint8_t channels;
26053a5a1b3Sopenharmony_ci    /**< Audio channels. (1 for mono, 2 for stereo, ...) */
26153a5a1b3Sopenharmony_ci} pa_sample_spec;
26253a5a1b3Sopenharmony_ci
26353a5a1b3Sopenharmony_ci/** Type for usec specifications (unsigned). Always 64 bit. */
26453a5a1b3Sopenharmony_citypedef uint64_t pa_usec_t;
26553a5a1b3Sopenharmony_ci
26653a5a1b3Sopenharmony_ci/** Return the amount of bytes that constitute playback of one second of
26753a5a1b3Sopenharmony_ci * audio, with the specified sample spec. */
26853a5a1b3Sopenharmony_cisize_t pa_bytes_per_second(const pa_sample_spec *spec) PA_GCC_PURE;
26953a5a1b3Sopenharmony_ci
27053a5a1b3Sopenharmony_ci/** Return the size of a frame with the specific sample type */
27153a5a1b3Sopenharmony_cisize_t pa_frame_size(const pa_sample_spec *spec) PA_GCC_PURE;
27253a5a1b3Sopenharmony_ci
27353a5a1b3Sopenharmony_ci/** Return the size of a sample with the specific sample type */
27453a5a1b3Sopenharmony_cisize_t pa_sample_size(const pa_sample_spec *spec) PA_GCC_PURE;
27553a5a1b3Sopenharmony_ci
27653a5a1b3Sopenharmony_ci/** Similar to pa_sample_size() but take a sample format instead of a
27753a5a1b3Sopenharmony_ci * full sample spec. \since 0.9.15 */
27853a5a1b3Sopenharmony_cisize_t pa_sample_size_of_format(pa_sample_format_t f) PA_GCC_PURE;
27953a5a1b3Sopenharmony_ci
28053a5a1b3Sopenharmony_ci/** Calculate the time it would take to play a buffer of the specified
28153a5a1b3Sopenharmony_ci * size with the specified sample type. The return value will always
28253a5a1b3Sopenharmony_ci * be rounded down for non-integral return values. */
28353a5a1b3Sopenharmony_cipa_usec_t pa_bytes_to_usec(uint64_t length, const pa_sample_spec *spec) PA_GCC_PURE;
28453a5a1b3Sopenharmony_ci
28553a5a1b3Sopenharmony_ci/** Calculates the size of a buffer required, for playback duration
28653a5a1b3Sopenharmony_ci * of the time specified, with the specified sample type. The
28753a5a1b3Sopenharmony_ci * return value will always be rounded down for non-integral
28853a5a1b3Sopenharmony_ci * return values. \since 0.9 */
28953a5a1b3Sopenharmony_cisize_t pa_usec_to_bytes(pa_usec_t t, const pa_sample_spec *spec) PA_GCC_PURE;
29053a5a1b3Sopenharmony_ci
29153a5a1b3Sopenharmony_ci/** Initialize the specified sample spec and return a pointer to
29253a5a1b3Sopenharmony_ci * it. The sample spec will have a defined state but
29353a5a1b3Sopenharmony_ci * pa_sample_spec_valid() will fail for it. \since 0.9.13 */
29453a5a1b3Sopenharmony_cipa_sample_spec* pa_sample_spec_init(pa_sample_spec *spec);
29553a5a1b3Sopenharmony_ci
29653a5a1b3Sopenharmony_ci/** Return non-zero if the given integer is a valid sample format. \since 5.0 */
29753a5a1b3Sopenharmony_ciint pa_sample_format_valid(unsigned format) PA_GCC_PURE;
29853a5a1b3Sopenharmony_ci
29953a5a1b3Sopenharmony_ci/** Return non-zero if the rate is within the supported range. \since 5.0 */
30053a5a1b3Sopenharmony_ciint pa_sample_rate_valid(uint32_t rate) PA_GCC_PURE;
30153a5a1b3Sopenharmony_ci
30253a5a1b3Sopenharmony_ci/** Return non-zero if the channel count is within the supported range.
30353a5a1b3Sopenharmony_ci * \since 5.0 */
30453a5a1b3Sopenharmony_ciint pa_channels_valid(uint8_t channels) PA_GCC_PURE;
30553a5a1b3Sopenharmony_ci
30653a5a1b3Sopenharmony_ci/** Return non-zero when the sample type specification is valid */
30753a5a1b3Sopenharmony_ciint pa_sample_spec_valid(const pa_sample_spec *spec) PA_GCC_PURE;
30853a5a1b3Sopenharmony_ci
30953a5a1b3Sopenharmony_ci/** Return non-zero when the two sample type specifications match */
31053a5a1b3Sopenharmony_ciint pa_sample_spec_equal(const pa_sample_spec*a, const pa_sample_spec*b) PA_GCC_PURE;
31153a5a1b3Sopenharmony_ci
31253a5a1b3Sopenharmony_ci/** Return a descriptive string for the specified sample format. \since 0.8 */
31353a5a1b3Sopenharmony_ciconst char *pa_sample_format_to_string(pa_sample_format_t f) PA_GCC_PURE;
31453a5a1b3Sopenharmony_ci
31553a5a1b3Sopenharmony_ci/** Parse a sample format text. Inverse of pa_sample_format_to_string() */
31653a5a1b3Sopenharmony_cipa_sample_format_t pa_parse_sample_format(const char *format) PA_GCC_PURE;
31753a5a1b3Sopenharmony_ci
31853a5a1b3Sopenharmony_ci/** Maximum required string length for
31953a5a1b3Sopenharmony_ci * pa_sample_spec_snprint(). Please note that this value can change
32053a5a1b3Sopenharmony_ci * with any release without warning and without being considered API
32153a5a1b3Sopenharmony_ci * or ABI breakage. You should not use this definition anywhere where
32253a5a1b3Sopenharmony_ci * it might become part of an ABI. */
32353a5a1b3Sopenharmony_ci#define PA_SAMPLE_SPEC_SNPRINT_MAX 32
32453a5a1b3Sopenharmony_ci
32553a5a1b3Sopenharmony_ci/** Pretty print a sample type specification to a string. Returns \a s. */
32653a5a1b3Sopenharmony_cichar* pa_sample_spec_snprint(char *s, size_t l, const pa_sample_spec *spec);
32753a5a1b3Sopenharmony_ci
32853a5a1b3Sopenharmony_ci/** Maximum required string length for pa_bytes_snprint(). Please note
32953a5a1b3Sopenharmony_ci * that this value can change with any release without warning and
33053a5a1b3Sopenharmony_ci * without being considered API or ABI breakage. You should not use
33153a5a1b3Sopenharmony_ci * this definition anywhere where it might become part of an
33253a5a1b3Sopenharmony_ci * ABI. \since 0.9.16 */
33353a5a1b3Sopenharmony_ci#define PA_BYTES_SNPRINT_MAX 11
33453a5a1b3Sopenharmony_ci
33553a5a1b3Sopenharmony_ci/** Pretty print a byte size value (i.e.\ "2.5 MiB"). Returns \a s. */
33653a5a1b3Sopenharmony_cichar* pa_bytes_snprint(char *s, size_t l, unsigned v);
33753a5a1b3Sopenharmony_ci
33853a5a1b3Sopenharmony_ci/** Returns 1 when the specified format is little endian, 0 when
33953a5a1b3Sopenharmony_ci * big endian. Returns -1 when endianness does not apply to the
34053a5a1b3Sopenharmony_ci * specified format, or endianess is unknown. \since 0.9.16 */
34153a5a1b3Sopenharmony_ciint pa_sample_format_is_le(pa_sample_format_t f) PA_GCC_PURE;
34253a5a1b3Sopenharmony_ci
34353a5a1b3Sopenharmony_ci/** Returns 1 when the specified format is big endian, 0 when
34453a5a1b3Sopenharmony_ci * little endian. Returns -1 when endianness does not apply to the
34553a5a1b3Sopenharmony_ci * specified format, or endianess is unknown. \since 0.9.16 */
34653a5a1b3Sopenharmony_ciint pa_sample_format_is_be(pa_sample_format_t f) PA_GCC_PURE;
34753a5a1b3Sopenharmony_ci
34853a5a1b3Sopenharmony_ci#ifdef WORDS_BIGENDIAN
34953a5a1b3Sopenharmony_ci#define pa_sample_format_is_ne(f) pa_sample_format_is_be(f)
35053a5a1b3Sopenharmony_ci#define pa_sample_format_is_re(f) pa_sample_format_is_le(f)
35153a5a1b3Sopenharmony_ci#else
35253a5a1b3Sopenharmony_ci/** Returns 1 when the specified format is native endian, 0 when
35353a5a1b3Sopenharmony_ci * not. Returns -1 when endianness does not apply to the
35453a5a1b3Sopenharmony_ci * specified format, or endianess is unknown. \since 0.9.16 */
35553a5a1b3Sopenharmony_ci#define pa_sample_format_is_ne(f) pa_sample_format_is_le(f)
35653a5a1b3Sopenharmony_ci/** Returns 1 when the specified format is reverse endian, 0 when
35753a5a1b3Sopenharmony_ci * native. Returns -1 when endianness does not apply to the
35853a5a1b3Sopenharmony_ci * specified format, or endianess is unknown. \since 0.9.16 */
35953a5a1b3Sopenharmony_ci#define pa_sample_format_is_re(f) pa_sample_format_is_be(f)
36053a5a1b3Sopenharmony_ci#endif
36153a5a1b3Sopenharmony_ci
36253a5a1b3Sopenharmony_ciPA_C_DECL_END
36353a5a1b3Sopenharmony_ci
36453a5a1b3Sopenharmony_ci#endif
365