]> code.delx.au - pulseaudio/blob - polyp/sample.h
latency work
[pulseaudio] / polyp / sample.h
1 #ifndef foosamplehfoo
2 #define foosamplehfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of polypaudio.
8
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.
13
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.
18
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
22 USA.
23 ***/
24
25 #include <inttypes.h>
26 #include <sys/types.h>
27
28 #include "cdecl.h"
29
30 /** \file
31 * Constants and routines for sample type handling */
32
33 PA_C_DECL_BEGIN
34
35 /** Sample format */
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 */
45 };
46
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
52 #else
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
57 #endif
58
59 /** A Shortcut for PA_SAMPLE_FLOAT32NE */
60 #define PA_SAMPLE_FLOAT32 PA_SAMPLE_FLOAT32NE
61
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, ...) */
67 };
68
69 /** Type for usec specifications */
70 typedef uint32_t pa_usec_t;
71
72 /** Return the amount of bytes playback of a second of audio with the speicified sample type takes */
73 size_t pa_bytes_per_second(const struct pa_sample_spec *spec);
74
75 /** Return the size of a frame with the specific sample type */
76 size_t pa_frame_size(const struct pa_sample_spec *spec);
77
78 /** Calculate the time the specified bytes take to play with the specified sample type */
79 pa_usec_t pa_bytes_to_usec(size_t length, const struct pa_sample_spec *spec);
80
81 /** Return non-zero when the sample type specification is valid */
82 int pa_sample_spec_valid(const struct pa_sample_spec *spec);
83
84 /** Return non-zero when the two sample type specifications match */
85 int pa_sample_spec_equal(const struct pa_sample_spec*a, const struct pa_sample_spec*b);
86
87 /** Maximum required string length for pa_sample_spec_snprint() */
88 #define PA_SAMPLE_SNPRINT_MAX_LENGTH 32
89
90 /** Pretty print a sample type specification to a string */
91 void pa_sample_spec_snprint(char *s, size_t l, const struct pa_sample_spec *spec);
92
93 /** Volume specification: 0: silence; < 256: diminished volume; 256: normal volume; > 256 amplified volume */
94 typedef uint32_t pa_volume_t;
95
96 /** Normal volume (100%) */
97 #define PA_VOLUME_NORM (0x100)
98
99 /** Muted volume (0%) */
100 #define PA_VOLUME_MUTED (0)
101
102 /** Multiply two volumes specifications, return the result. This uses PA_VOLUME_NORM as neutral element of multiplication. */
103 pa_volume_t pa_volume_multiply(pa_volume_t a, pa_volume_t b);
104
105 PA_C_DECL_END
106
107 #endif