]>
code.delx.au - pulseaudio/blob - polyp/sample.h
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>
32 * Constants and routines for sample type handling */
37 enum pa_sample_format
{
38 PA_SAMPLE_U8
, /**< Unsigned 8 Bit PCM */
39 PA_SAMPLE_ALAW
, /**< 8 Bit a-Law */
40 PA_SAMPLE_ULAW
, /**< 8 Bit mu-Law */
41 PA_SAMPLE_S16LE
, /**< Signed 16 Bit PCM, little endian (PC) */
42 PA_SAMPLE_S16BE
, /**< Signed 16 Bit PCM, big endian */
43 PA_SAMPLE_FLOAT32LE
, /**< 32 Bit IEEE floating point, little endian, range -1..1 */
44 PA_SAMPLE_FLOAT32BE
, /**< 32 Bit IEEE floating point, big endian, range -1..1 */
45 PA_SAMPLE_MAX
/**< Upper limit of valid sample types */
48 #ifdef WORDS_BIGENDIAN
49 /** Signed 16 Bit PCM, native endian */
50 #define PA_SAMPLE_S16NE PA_SAMPLE_S16BE
51 /** 32 Bit IEEE floating point, native endian */
52 #define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32BE
54 /** Signed 16 Bit PCM, native endian */
55 #define PA_SAMPLE_S16NE PA_SAMPLE_S16LE
56 /** 32 Bit IEEE floating point, native endian */
57 #define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32LE
60 /** A Shortcut for PA_SAMPLE_FLOAT32NE */
61 #define PA_SAMPLE_FLOAT32 PA_SAMPLE_FLOAT32NE
63 /** A sample format and attribute specification */
64 struct pa_sample_spec
{
65 enum pa_sample_format format
; /**< The sample format */
66 uint32_t rate
; /**< The sample rate. (e.g. 44100) */
67 uint8_t channels
; /**< Audio channels. (1 for mono, 2 for stereo, ...) */
70 /** Type for usec specifications. May be either 32 or 64 bit, depending on the architecture */
71 typedef uint64_t pa_usec_t
;
73 /** Return the amount of bytes playback of a second of audio with the speicified sample type takes */
74 size_t pa_bytes_per_second(const struct pa_sample_spec
*spec
);
76 /** Return the size of a frame with the specific sample type */
77 size_t pa_frame_size(const struct pa_sample_spec
*spec
);
79 /** Calculate the time the specified bytes take to play with the specified sample type */
80 pa_usec_t
pa_bytes_to_usec(size_t length
, const struct pa_sample_spec
*spec
);
82 /** Return non-zero when the sample type specification is valid */
83 int pa_sample_spec_valid(const struct pa_sample_spec
*spec
);
85 /** Return non-zero when the two sample type specifications match */
86 int pa_sample_spec_equal(const struct pa_sample_spec
*a
, const struct pa_sample_spec
*b
);
88 /** Maximum required string length for pa_sample_spec_snprint() */
89 #define PA_SAMPLE_SNPRINT_MAX_LENGTH 32
91 /** Pretty print a sample type specification to a string */
92 void pa_sample_spec_snprint(char *s
, size_t l
, const struct pa_sample_spec
*spec
);
94 /** Volume specification: 0: silence; < 256: diminished volume; 256: normal volume; > 256 amplified volume */
95 typedef uint32_t pa_volume_t
;
97 /** Normal volume (100%) */
98 #define PA_VOLUME_NORM (0x100)
100 /** Muted volume (0%) */
101 #define PA_VOLUME_MUTED (0)
103 /** Multiply two volumes specifications, return the result. This uses PA_VOLUME_NORM as neutral element of multiplication. */
104 pa_volume_t
pa_volume_multiply(pa_volume_t a
, pa_volume_t b
);
106 /** Convert volume from decibel to linear level. \since 0.4 */
107 pa_volume_t
pa_volume_from_dB(double f
);
109 /** Convert volume from linear level to decibel. \since 0.4 */
110 double pa_volume_to_dB(pa_volume_t v
);
113 #define PA_DECIBEL_MININFTY (-INFINITY)
115 /** This value is used as minus infinity when using pa_volume_{to,from}_dB(). \since 0.4 */
116 #define PA_DECIBEL_MININFTY (-200)
119 /** Pretty print a byte size value. (i.e. "2.5 MB") */
120 void pa_bytes_snprint(char *s
, size_t l
, off_t v
);