PulseAudio  9.0
sample.h
Go to the documentation of this file.
00001 #ifndef foosamplehfoo
00002 #define foosamplehfoo
00003 
00004 /***
00005   This file is part of PulseAudio.
00006 
00007   Copyright 2004-2006 Lennart Poettering
00008   Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
00009 
00010   PulseAudio is free software; you can redistribute it and/or modify
00011   it under the terms of the GNU Lesser General Public License as published
00012   by the Free Software Foundation; either version 2.1 of the License,
00013   or (at your option) any later version.
00014 
00015   PulseAudio is distributed in the hope that it will be useful, but
00016   WITHOUT ANY WARRANTY; without even the implied warranty of
00017   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018   General Public License for more details.
00019 
00020   You should have received a copy of the GNU Lesser General Public License
00021   along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
00022 ***/
00023 
00024 #include <inttypes.h>
00025 #include <sys/types.h>
00026 #include <sys/param.h>
00027 
00028 #include <pulse/gccmacro.h>
00029 #include <pulse/cdecl.h>
00030 #include <pulse/version.h>
00031 
00110 PA_C_DECL_BEGIN
00111 
00112 #if !defined(WORDS_BIGENDIAN)
00113 
00114 #if defined(__BYTE_ORDER)
00115 #if __BYTE_ORDER == __BIG_ENDIAN
00116 #define WORDS_BIGENDIAN
00117 #endif
00118 #endif
00119 
00120 /* On Sparc, WORDS_BIGENDIAN needs to be set if _BIG_ENDIAN is defined. */
00121 #if defined(__sparc__) && defined(_BIG_ENDIAN)
00122 #define WORDS_BIGENDIAN
00123 #endif
00124 
00125 #endif
00126 
00128 #define PA_CHANNELS_MAX 32U
00129 
00131 #define PA_RATE_MAX (48000U*8U)
00132 
00134 typedef enum pa_sample_format {
00135     PA_SAMPLE_U8,
00138     PA_SAMPLE_ALAW,
00141     PA_SAMPLE_ULAW,
00144     PA_SAMPLE_S16LE,
00147     PA_SAMPLE_S16BE,
00150     PA_SAMPLE_FLOAT32LE,
00153     PA_SAMPLE_FLOAT32BE,
00156     PA_SAMPLE_S32LE,
00159     PA_SAMPLE_S32BE,
00162     PA_SAMPLE_S24LE,
00165     PA_SAMPLE_S24BE,
00168     PA_SAMPLE_S24_32LE,
00171     PA_SAMPLE_S24_32BE,
00174     PA_SAMPLE_MAX,
00177     PA_SAMPLE_INVALID = -1
00179 } pa_sample_format_t;
00180 
00181 #ifdef WORDS_BIGENDIAN
00182 
00183 #define PA_SAMPLE_S16NE PA_SAMPLE_S16BE
00184 
00185 #define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32BE
00186 
00187 #define PA_SAMPLE_S32NE PA_SAMPLE_S32BE
00188 
00189 #define PA_SAMPLE_S24NE PA_SAMPLE_S24BE
00190 
00191 #define PA_SAMPLE_S24_32NE PA_SAMPLE_S24_32BE
00192 
00194 #define PA_SAMPLE_S16RE PA_SAMPLE_S16LE
00195 
00196 #define PA_SAMPLE_FLOAT32RE PA_SAMPLE_FLOAT32LE
00197 
00198 #define PA_SAMPLE_S32RE PA_SAMPLE_S32LE
00199 
00200 #define PA_SAMPLE_S24RE PA_SAMPLE_S24LE
00201 
00202 #define PA_SAMPLE_S24_32RE PA_SAMPLE_S24_32LE
00203 #else
00204 
00205 #define PA_SAMPLE_S16NE PA_SAMPLE_S16LE
00206 
00207 #define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32LE
00208 
00209 #define PA_SAMPLE_S32NE PA_SAMPLE_S32LE
00210 
00211 #define PA_SAMPLE_S24NE PA_SAMPLE_S24LE
00212 
00213 #define PA_SAMPLE_S24_32NE PA_SAMPLE_S24_32LE
00214 
00216 #define PA_SAMPLE_S16RE PA_SAMPLE_S16BE
00217 
00218 #define PA_SAMPLE_FLOAT32RE PA_SAMPLE_FLOAT32BE
00219 
00220 #define PA_SAMPLE_S32RE PA_SAMPLE_S32BE
00221 
00222 #define PA_SAMPLE_S24RE PA_SAMPLE_S24BE
00223 
00224 #define PA_SAMPLE_S24_32RE PA_SAMPLE_S24_32BE
00225 #endif
00226 
00228 #define PA_SAMPLE_FLOAT32 PA_SAMPLE_FLOAT32NE
00229 
00231 /* Allow clients to check with #ifdef for these sample formats */
00232 #define PA_SAMPLE_U8 PA_SAMPLE_U8
00233 #define PA_SAMPLE_ALAW PA_SAMPLE_ALAW
00234 #define PA_SAMPLE_ULAW PA_SAMPLE_ULAW
00235 #define PA_SAMPLE_S16LE PA_SAMPLE_S16LE
00236 #define PA_SAMPLE_S16BE PA_SAMPLE_S16BE
00237 #define PA_SAMPLE_FLOAT32LE PA_SAMPLE_FLOAT32LE
00238 #define PA_SAMPLE_FLOAT32BE PA_SAMPLE_FLOAT32BE
00239 #define PA_SAMPLE_S32LE PA_SAMPLE_S32LE
00240 #define PA_SAMPLE_S32BE PA_SAMPLE_S32BE
00241 #define PA_SAMPLE_S24LE PA_SAMPLE_S24LE
00242 #define PA_SAMPLE_S24BE PA_SAMPLE_S24BE
00243 #define PA_SAMPLE_S24_32LE PA_SAMPLE_S24_32LE
00244 #define PA_SAMPLE_S24_32BE PA_SAMPLE_S24_32BE
00245 
00248 typedef struct pa_sample_spec {
00249     pa_sample_format_t format;
00252     uint32_t rate;
00255     uint8_t channels;
00257 } pa_sample_spec;
00258 
00260 typedef uint64_t pa_usec_t;
00261 
00263 size_t pa_bytes_per_second(const pa_sample_spec *spec) PA_GCC_PURE;
00264 
00266 size_t pa_frame_size(const pa_sample_spec *spec) PA_GCC_PURE;
00267 
00269 size_t pa_sample_size(const pa_sample_spec *spec) PA_GCC_PURE;
00270 
00273 size_t pa_sample_size_of_format(pa_sample_format_t f) PA_GCC_PURE;
00274 
00278 pa_usec_t pa_bytes_to_usec(uint64_t length, const pa_sample_spec *spec) PA_GCC_PURE;
00279 
00283 size_t pa_usec_to_bytes(pa_usec_t t, const pa_sample_spec *spec) PA_GCC_PURE;
00284 
00288 pa_sample_spec* pa_sample_spec_init(pa_sample_spec *spec);
00289 
00291 int pa_sample_format_valid(unsigned format) PA_GCC_PURE;
00292 
00294 int pa_sample_rate_valid(uint32_t rate) PA_GCC_PURE;
00295 
00298 int pa_channels_valid(uint8_t channels) PA_GCC_PURE;
00299 
00301 int pa_sample_spec_valid(const pa_sample_spec *spec) PA_GCC_PURE;
00302 
00304 int pa_sample_spec_equal(const pa_sample_spec*a, const pa_sample_spec*b) PA_GCC_PURE;
00305 
00307 const char *pa_sample_format_to_string(pa_sample_format_t f) PA_GCC_PURE;
00308 
00310 pa_sample_format_t pa_parse_sample_format(const char *format) PA_GCC_PURE;
00311 
00317 #define PA_SAMPLE_SPEC_SNPRINT_MAX 32
00318 
00320 char* pa_sample_spec_snprint(char *s, size_t l, const pa_sample_spec *spec);
00321 
00327 #define PA_BYTES_SNPRINT_MAX 11
00328 
00330 char* pa_bytes_snprint(char *s, size_t l, unsigned v);
00331 
00334 int pa_sample_format_is_le(pa_sample_format_t f) PA_GCC_PURE;
00335 
00338 int pa_sample_format_is_be(pa_sample_format_t f) PA_GCC_PURE;
00339 
00340 #ifdef WORDS_BIGENDIAN
00341 #define pa_sample_format_is_ne(f) pa_sample_format_is_be(f)
00342 #define pa_sample_format_is_re(f) pa_sample_format_is_le(f)
00343 #else
00344 
00346 #define pa_sample_format_is_ne(f) pa_sample_format_is_le(f)
00347 
00349 #define pa_sample_format_is_re(f) pa_sample_format_is_be(f)
00350 #endif
00351 
00352 PA_C_DECL_END
00353 
00354 #endif