]>
code.delx.au - pulseaudio/blob - polyp/sample.h
459f8a302dc75f8eaeca5b7b955557ef6c5c27b9
7 This file is part of polypaudio.
9 polypaudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published
11 by the Free Software Foundation; either version 2 of the License,
12 or (at your option) any later version.
14 polypaudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with polypaudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <sys/types.h>
31 * Constants and routines for sample type handling */
36 enum pa_sample_format
{
37 PA_SAMPLE_U8
, /**< Unsigned 8 Bit PCM */
38 PA_SAMPLE_ALAW
, /**< 8 Bit a-Law */
39 PA_SAMPLE_ULAW
, /**< 8 Bit mu-Law */
40 PA_SAMPLE_S16LE
, /**< Signed 16 Bit PCM, little endian (PC) */
41 PA_SAMPLE_S16BE
, /**< Signed 16 Bit PCM, big endian */
42 PA_SAMPLE_FLOAT32LE
, /**< 32 Bit IEEE floating point, little endian, range -1..1 */
43 PA_SAMPLE_FLOAT32BE
, /**< 32 Bit IEEE floating point, big endian, range -1..1 */
44 PA_SAMPLE_MAX
/**< Upper limit of valid sample types */
47 #ifdef WORDS_BIGENDIAN
48 /** Signed 16 Bit PCM, native endian */
49 #define PA_SAMPLE_S16NE PA_SAMPLE_S16BE
50 /** 32 Bit IEEE floating point, native endian */
51 #define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32BE
53 /** Signed 16 Bit PCM, native endian */
54 #define PA_SAMPLE_S16NE PA_SAMPLE_S16LE
55 /** 32 Bit IEEE floating point, native endian */
56 #define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32LE
59 /** A Shortcut for PA_SAMPLE_FLOAT32NE */
60 #define PA_SAMPLE_FLOAT32 PA_SAMPLE_FLOAT32NE
62 /** A sample format and attribute specification */
63 struct pa_sample_spec
{
64 enum pa_sample_format format
; /**< The sample format */
65 uint32_t rate
; /**< The sample rate. (e.g. 44100) */
66 uint8_t channels
; /**< Audio channels. (1 for mono, 2 for stereo, ...) */
69 /** Return the amount of bytes playback of a second of audio with the speicified sample type takes */
70 size_t pa_bytes_per_second(const struct pa_sample_spec
*spec
);
72 /** Return the size of a frame with the specific sample type */
73 size_t pa_frame_size(const struct pa_sample_spec
*spec
);
75 /** Calculate the time the specified bytes take to play with the specified sample type */
76 uint32_t pa_bytes_to_usec(size_t length
, const struct pa_sample_spec
*spec
);
78 /** Return non-zero when the sample type specification is valid */
79 int pa_sample_spec_valid(const struct pa_sample_spec
*spec
);
81 /** Return non-zero when the two sample type specifications match */
82 int pa_sample_spec_equal(const struct pa_sample_spec
*a
, const struct pa_sample_spec
*b
);
84 /** Maximum required string length for pa_sample_spec_snprint() */
85 #define PA_SAMPLE_SNPRINT_MAX_LENGTH 32
87 /** Pretty print a sample type specification to a string */
88 void pa_sample_spec_snprint(char *s
, size_t l
, const struct pa_sample_spec
*spec
);
90 /** Volume specification: 0: silence; < 256: diminished volume; 256: normal volume; > 256 amplified volume */
91 typedef uint32_t pa_volume_t
;
93 /** Normal volume (100%) */
94 #define PA_VOLUME_NORM (0x100)
96 /** Muted volume (0%) */
97 #define PA_VOLUME_MUTED (0)
99 /** Multiply two volumes specifications, return the result. This uses PA_VOLUME_NORM as neutral element of multiplication. */
100 pa_volume_t
pa_volume_multiply(pa_volume_t a
, pa_volume_t b
);