PulseAudio  14.0
sample.h
Go to the documentation of this file.
1 #ifndef foosamplehfoo
2 #define foosamplehfoo
3 
4 /***
5  This file is part of PulseAudio.
6 
7  Copyright 2004-2006 Lennart Poettering
8  Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9 
10  PulseAudio is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published
12  by the Free Software Foundation; either version 2.1 of the License,
13  or (at your option) any later version.
14 
15  PulseAudio is distributed in the hope that it will be useful, but
16  WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
22 ***/
23 
24 #include <inttypes.h>
25 #include <sys/types.h>
26 #include <sys/param.h>
27 
28 #include <pulse/gccmacro.h>
29 #include <pulse/cdecl.h>
30 #include <pulse/version.h>
31 
110 PA_C_DECL_BEGIN
111 
112 #if !defined(WORDS_BIGENDIAN)
113 
114 #if defined(__BYTE_ORDER)
115 #if __BYTE_ORDER == __BIG_ENDIAN
116 #define WORDS_BIGENDIAN
117 #endif
118 #endif
119 
120 /* On Sparc, WORDS_BIGENDIAN needs to be set if _BIG_ENDIAN is defined. */
121 #if defined(__sparc__) && defined(_BIG_ENDIAN)
122 #define WORDS_BIGENDIAN
123 #endif
124 
125 #endif
126 
128 #define PA_CHANNELS_MAX 32U
129 
131 #define PA_RATE_MAX (48000U*8U)
132 
134 typedef enum pa_sample_format {
135  PA_SAMPLE_U8,
174  /* Remeber to update
175  * https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/SupportedAudioFormats/
176  * when adding new formats! */
177 
181  PA_SAMPLE_INVALID = -1
184 
185 #ifdef WORDS_BIGENDIAN
186 
187 #define PA_SAMPLE_S16NE PA_SAMPLE_S16BE
188 
189 #define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32BE
190 
191 #define PA_SAMPLE_S32NE PA_SAMPLE_S32BE
192 
193 #define PA_SAMPLE_S24NE PA_SAMPLE_S24BE
194 
195 #define PA_SAMPLE_S24_32NE PA_SAMPLE_S24_32BE
196 
198 #define PA_SAMPLE_S16RE PA_SAMPLE_S16LE
199 
200 #define PA_SAMPLE_FLOAT32RE PA_SAMPLE_FLOAT32LE
201 
202 #define PA_SAMPLE_S32RE PA_SAMPLE_S32LE
203 
204 #define PA_SAMPLE_S24RE PA_SAMPLE_S24LE
205 
206 #define PA_SAMPLE_S24_32RE PA_SAMPLE_S24_32LE
207 #else
208 
209 #define PA_SAMPLE_S16NE PA_SAMPLE_S16LE
210 
211 #define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32LE
212 
213 #define PA_SAMPLE_S32NE PA_SAMPLE_S32LE
214 
215 #define PA_SAMPLE_S24NE PA_SAMPLE_S24LE
216 
217 #define PA_SAMPLE_S24_32NE PA_SAMPLE_S24_32LE
218 
220 #define PA_SAMPLE_S16RE PA_SAMPLE_S16BE
221 
222 #define PA_SAMPLE_FLOAT32RE PA_SAMPLE_FLOAT32BE
223 
224 #define PA_SAMPLE_S32RE PA_SAMPLE_S32BE
225 
226 #define PA_SAMPLE_S24RE PA_SAMPLE_S24BE
227 
228 #define PA_SAMPLE_S24_32RE PA_SAMPLE_S24_32BE
229 #endif
230 
232 #define PA_SAMPLE_FLOAT32 PA_SAMPLE_FLOAT32NE
233 
235 /* Allow clients to check with #ifdef for these sample formats */
236 #define PA_SAMPLE_U8 PA_SAMPLE_U8
237 #define PA_SAMPLE_ALAW PA_SAMPLE_ALAW
238 #define PA_SAMPLE_ULAW PA_SAMPLE_ULAW
239 #define PA_SAMPLE_S16LE PA_SAMPLE_S16LE
240 #define PA_SAMPLE_S16BE PA_SAMPLE_S16BE
241 #define PA_SAMPLE_FLOAT32LE PA_SAMPLE_FLOAT32LE
242 #define PA_SAMPLE_FLOAT32BE PA_SAMPLE_FLOAT32BE
243 #define PA_SAMPLE_S32LE PA_SAMPLE_S32LE
244 #define PA_SAMPLE_S32BE PA_SAMPLE_S32BE
245 #define PA_SAMPLE_S24LE PA_SAMPLE_S24LE
246 #define PA_SAMPLE_S24BE PA_SAMPLE_S24BE
247 #define PA_SAMPLE_S24_32LE PA_SAMPLE_S24_32LE
248 #define PA_SAMPLE_S24_32BE PA_SAMPLE_S24_32BE
249 
252 typedef struct pa_sample_spec {
256  uint32_t rate;
259  uint8_t channels;
262 
264 typedef uint64_t pa_usec_t;
265 
269 
272 
275 
279 
283 pa_usec_t pa_bytes_to_usec(uint64_t length, const pa_sample_spec *spec) PA_GCC_PURE;
284 
290 
295 
297 int pa_sample_format_valid(unsigned format) PA_GCC_PURE;
298 
301 
304 int pa_channels_valid(uint8_t channels) PA_GCC_PURE;
305 
308 
311 
314 
317 
323 #define PA_SAMPLE_SPEC_SNPRINT_MAX 32
324 
326 char* pa_sample_spec_snprint(char *s, size_t l, const pa_sample_spec *spec);
327 
333 #define PA_BYTES_SNPRINT_MAX 11
334 
336 char* pa_bytes_snprint(char *s, size_t l, unsigned v);
337 
342 
347 
348 #ifdef WORDS_BIGENDIAN
349 #define pa_sample_format_is_ne(f) pa_sample_format_is_be(f)
350 #define pa_sample_format_is_re(f) pa_sample_format_is_le(f)
351 #else
352 
355 #define pa_sample_format_is_ne(f) pa_sample_format_is_le(f)
356 
359 #define pa_sample_format_is_re(f) pa_sample_format_is_be(f)
360 #endif
361 
362 PA_C_DECL_END
363 
364 #endif
PA_SAMPLE_S24BE
@ PA_SAMPLE_S24BE
Signed 24 Bit PCM packed, big endian.
Definition: sample.h:165
PA_SAMPLE_U8
@ PA_SAMPLE_U8
Unsigned 8 Bit PCM.
Definition: sample.h:135
PA_SAMPLE_ULAW
@ PA_SAMPLE_ULAW
8 Bit mu-Law
Definition: sample.h:141
pa_sample_spec::channels
uint8_t channels
Audio channels.
Definition: sample.h:259
pa_frame_size
size_t pa_frame_size(const pa_sample_spec *spec) PA_GCC_PURE
Return the size of a frame with the specific sample type.
PA_SAMPLE_S32BE
@ PA_SAMPLE_S32BE
Signed 32 Bit PCM, big endian.
Definition: sample.h:159
pa_sample_format_t
enum pa_sample_format pa_sample_format_t
Sample format.
pa_sample_size_of_format
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.
PA_GCC_PURE
#define PA_GCC_PURE
This function's return value depends only the arguments list and global state.
Definition: gccmacro.h:73
PA_SAMPLE_INVALID
@ PA_SAMPLE_INVALID
An invalid value.
Definition: sample.h:181
pa_sample_format_to_string
const char * pa_sample_format_to_string(pa_sample_format_t f) PA_GCC_PURE
Return a descriptive string for the specified sample format.
pa_sample_size
size_t pa_sample_size(const pa_sample_spec *spec) PA_GCC_PURE
Return the size of a sample with the specific sample type.
pa_sample_format_valid
int pa_sample_format_valid(unsigned format) PA_GCC_PURE
Return non-zero if the given integer is a valid sample format.
PA_SAMPLE_S24_32LE
@ PA_SAMPLE_S24_32LE
Signed 24 Bit PCM in LSB of 32 Bit words, little endian (PC).
Definition: sample.h:168
PA_SAMPLE_S24LE
@ PA_SAMPLE_S24LE
Signed 24 Bit PCM packed, little endian (PC).
Definition: sample.h:162
pa_sample_rate_valid
int pa_sample_rate_valid(uint32_t rate) PA_GCC_PURE
Return non-zero if the rate is within the supported range.
pa_sample_spec::rate
uint32_t rate
The sample rate.
Definition: sample.h:256
pa_sample_spec
struct pa_sample_spec pa_sample_spec
A sample format and attribute specification.
pa_sample_spec_valid
int pa_sample_spec_valid(const pa_sample_spec *spec) PA_GCC_PURE
Return non-zero when the sample type specification is valid.
gccmacro.h
GCC attribute macros.
pa_usec_t
uint64_t pa_usec_t
Type for usec specifications (unsigned).
Definition: sample.h:264
pa_sample_spec_equal
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.
PA_SAMPLE_ALAW
@ PA_SAMPLE_ALAW
8 Bit a-Law
Definition: sample.h:138
pa_sample_spec
A sample format and attribute specification.
Definition: sample.h:252
pa_sample_format_is_be
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.
pa_sample_format_is_le
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.
PA_SAMPLE_MAX
@ PA_SAMPLE_MAX
Upper limit of valid sample types.
Definition: sample.h:178
PA_SAMPLE_FLOAT32LE
@ PA_SAMPLE_FLOAT32LE
32 Bit IEEE floating point, little endian (PC), range -1.0 to 1.0
Definition: sample.h:150
pa_sample_spec::format
pa_sample_format_t format
The sample format.
Definition: sample.h:253
pa_bytes_per_second
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...
PA_SAMPLE_S32LE
@ PA_SAMPLE_S32LE
Signed 32 Bit PCM, little endian (PC)
Definition: sample.h:156
PA_SAMPLE_S16BE
@ PA_SAMPLE_S16BE
Signed 16 Bit PCM, big endian.
Definition: sample.h:147
PA_SAMPLE_S24_32BE
@ PA_SAMPLE_S24_32BE
Signed 24 Bit PCM in LSB of 32 Bit words, big endian.
Definition: sample.h:171
pa_channels_valid
int pa_channels_valid(uint8_t channels) PA_GCC_PURE
Return non-zero if the channel count is within the supported range.
pa_parse_sample_format
pa_sample_format_t pa_parse_sample_format(const char *format) PA_GCC_PURE
Parse a sample format text.
pa_bytes_to_usec
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 typ...
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.
PA_SAMPLE_FLOAT32BE
@ PA_SAMPLE_FLOAT32BE
32 Bit IEEE floating point, big endian, range -1.0 to 1.0
Definition: sample.h:153
pa_sample_format
pa_sample_format
Sample format.
Definition: sample.h:134
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").
pa_usec_to_bytes
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,...
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.
PA_SAMPLE_S16LE
@ PA_SAMPLE_S16LE
Signed 16 Bit PCM, little endian (PC)
Definition: sample.h:144