]> code.delx.au - pulseaudio/blob - src/pulse/channelmap.h
channelmap: make sure a mask is generated is 64 bit int
[pulseaudio] / src / pulse / channelmap.h
1 #ifndef foochannelmaphfoo
2 #define foochannelmaphfoo
3
4 /***
5 This file is part of PulseAudio.
6
7 Copyright 2005-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, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 USA.
24 ***/
25
26 #include <pulse/sample.h>
27 #include <pulse/cdecl.h>
28 #include <pulse/gccmacro.h>
29 #include <pulse/version.h>
30
31 /** \page channelmap Channel Maps
32 *
33 * \section overv_sec Overview
34 *
35 * Channel maps provide a way to associate channels in a stream with a
36 * specific speaker position. This relieves applications of having to
37 * make sure their channel order is identical to the final output.
38 *
39 * \section init_sec Initialisation
40 *
41 * A channel map consists of an array of \ref pa_channel_position values,
42 * one for each channel. This array is stored together with a channel count
43 * in a pa_channel_map structure.
44 *
45 * Before filling the structure, the application must initialise it using
46 * pa_channel_map_init(). There are also a number of convenience functions
47 * for standard channel mappings:
48 *
49 * \li pa_channel_map_init_mono() - Create a channel map with only mono audio.
50 * \li pa_channel_map_init_stereo() - Create a standard stereo mapping.
51 * \li pa_channel_map_init_auto() - Create a standard channel map for a specific number of channels
52 * \li pa_channel_map_init_extend() - Similar to
53 * pa_channel_map_init_auto() but synthesize a channel map if no
54 * predefined one is known for the specified number of channels.
55 *
56 * \section conv_sec Convenience Functions
57 *
58 * The library contains a number of convenience functions for dealing with
59 * channel maps:
60 *
61 * \li pa_channel_map_valid() - Tests if a channel map is valid.
62 * \li pa_channel_map_equal() - Tests if two channel maps are identical.
63 * \li pa_channel_map_snprint() - Creates a textual description of a channel
64 * map.
65 */
66
67 /** \file
68 * Constants and routines for channel mapping handling */
69
70 PA_C_DECL_BEGIN
71
72 /** A list of channel labels */
73 typedef enum pa_channel_position {
74 PA_CHANNEL_POSITION_INVALID = -1,
75 PA_CHANNEL_POSITION_MONO = 0,
76
77 PA_CHANNEL_POSITION_FRONT_LEFT, /* Apple calls this 'Left' */
78 PA_CHANNEL_POSITION_FRONT_RIGHT, /* Apple calls this 'Right' */
79 PA_CHANNEL_POSITION_FRONT_CENTER, /* Apple calls this 'Center' */
80
81 /** \cond fulldocs */
82 PA_CHANNEL_POSITION_LEFT = PA_CHANNEL_POSITION_FRONT_LEFT,
83 PA_CHANNEL_POSITION_RIGHT = PA_CHANNEL_POSITION_FRONT_RIGHT,
84 PA_CHANNEL_POSITION_CENTER = PA_CHANNEL_POSITION_FRONT_CENTER,
85 /** \endcond */
86
87 PA_CHANNEL_POSITION_REAR_CENTER, /* Microsoft calls this 'Back Center', Apple calls this 'Center Surround' */
88 PA_CHANNEL_POSITION_REAR_LEFT, /* Microsoft calls this 'Back Left', Apple calls this 'Left Surround' */
89 PA_CHANNEL_POSITION_REAR_RIGHT, /* Microsoft calls this 'Back Right', Apple calls this 'Right Surround' */
90
91 PA_CHANNEL_POSITION_LFE, /* Microsoft calls this 'Low Frequency', Apple calls this 'LFEScreen' */
92 /** \cond fulldocs */
93 PA_CHANNEL_POSITION_SUBWOOFER = PA_CHANNEL_POSITION_LFE,
94 /** \endcond */
95
96 PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER, /* Apple calls this 'Left Center' */
97 PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER, /* Apple calls this 'Right Center */
98
99 PA_CHANNEL_POSITION_SIDE_LEFT, /* Apple calls this 'Left Surround Direct' */
100 PA_CHANNEL_POSITION_SIDE_RIGHT, /* Apple calls this 'Right Surround Direct' */
101
102 PA_CHANNEL_POSITION_AUX0,
103 PA_CHANNEL_POSITION_AUX1,
104 PA_CHANNEL_POSITION_AUX2,
105 PA_CHANNEL_POSITION_AUX3,
106 PA_CHANNEL_POSITION_AUX4,
107 PA_CHANNEL_POSITION_AUX5,
108 PA_CHANNEL_POSITION_AUX6,
109 PA_CHANNEL_POSITION_AUX7,
110 PA_CHANNEL_POSITION_AUX8,
111 PA_CHANNEL_POSITION_AUX9,
112 PA_CHANNEL_POSITION_AUX10,
113 PA_CHANNEL_POSITION_AUX11,
114 PA_CHANNEL_POSITION_AUX12,
115 PA_CHANNEL_POSITION_AUX13,
116 PA_CHANNEL_POSITION_AUX14,
117 PA_CHANNEL_POSITION_AUX15,
118 PA_CHANNEL_POSITION_AUX16,
119 PA_CHANNEL_POSITION_AUX17,
120 PA_CHANNEL_POSITION_AUX18,
121 PA_CHANNEL_POSITION_AUX19,
122 PA_CHANNEL_POSITION_AUX20,
123 PA_CHANNEL_POSITION_AUX21,
124 PA_CHANNEL_POSITION_AUX22,
125 PA_CHANNEL_POSITION_AUX23,
126 PA_CHANNEL_POSITION_AUX24,
127 PA_CHANNEL_POSITION_AUX25,
128 PA_CHANNEL_POSITION_AUX26,
129 PA_CHANNEL_POSITION_AUX27,
130 PA_CHANNEL_POSITION_AUX28,
131 PA_CHANNEL_POSITION_AUX29,
132 PA_CHANNEL_POSITION_AUX30,
133 PA_CHANNEL_POSITION_AUX31,
134
135 PA_CHANNEL_POSITION_TOP_CENTER, /* Apple calls this 'Top Center Surround' */
136
137 PA_CHANNEL_POSITION_TOP_FRONT_LEFT, /* Apple calls this 'Vertical Height Left' */
138 PA_CHANNEL_POSITION_TOP_FRONT_RIGHT, /* Apple calls this 'Vertical Height Right' */
139 PA_CHANNEL_POSITION_TOP_FRONT_CENTER, /* Apple calls this 'Vertical Height Center' */
140
141 PA_CHANNEL_POSITION_TOP_REAR_LEFT, /* Microsoft and Apple call this 'Top Back Left' */
142 PA_CHANNEL_POSITION_TOP_REAR_RIGHT, /* Microsoft and Apple call this 'Top Back Right' */
143 PA_CHANNEL_POSITION_TOP_REAR_CENTER, /* Microsoft and Apple call this 'Top Back Center' */
144
145 PA_CHANNEL_POSITION_MAX
146 } pa_channel_position_t;
147
148 /** \cond fulldocs */
149 #define PA_CHANNEL_POSITION_INVALID PA_CHANNEL_POSITION_INVALID
150 #define PA_CHANNEL_POSITION_MONO PA_CHANNEL_POSITION_MONO
151 #define PA_CHANNEL_POSITION_LEFT PA_CHANNEL_POSITION_LEFT
152 #define PA_CHANNEL_POSITION_RIGHT PA_CHANNEL_POSITION_RIGHT
153 #define PA_CHANNEL_POSITION_CENTER PA_CHANNEL_POSITION_CENTER
154 #define PA_CHANNEL_POSITION_FRONT_LEFT PA_CHANNEL_POSITION_FRONT_LEFT
155 #define PA_CHANNEL_POSITION_FRONT_RIGHT PA_CHANNEL_POSITION_FRONT_RIGHT
156 #define PA_CHANNEL_POSITION_FRONT_CENTER PA_CHANNEL_POSITION_FRONT_CENTER
157 #define PA_CHANNEL_POSITION_REAR_CENTER PA_CHANNEL_POSITION_REAR_CENTER
158 #define PA_CHANNEL_POSITION_REAR_LEFT PA_CHANNEL_POSITION_REAR_LEFT
159 #define PA_CHANNEL_POSITION_REAR_RIGHT PA_CHANNEL_POSITION_REAR_RIGHT
160 #define PA_CHANNEL_POSITION_LFE PA_CHANNEL_POSITION_LFE
161 #define PA_CHANNEL_POSITION_SUBWOOFER PA_CHANNEL_POSITION_SUBWOOFER
162 #define PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER
163 #define PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER
164 #define PA_CHANNEL_POSITION_SIDE_LEFT PA_CHANNEL_POSITION_SIDE_LEFT
165 #define PA_CHANNEL_POSITION_SIDE_RIGHT PA_CHANNEL_POSITION_SIDE_RIGHT
166 #define PA_CHANNEL_POSITION_AUX0 PA_CHANNEL_POSITION_AUX0
167 #define PA_CHANNEL_POSITION_AUX1 PA_CHANNEL_POSITION_AUX1
168 #define PA_CHANNEL_POSITION_AUX2 PA_CHANNEL_POSITION_AUX2
169 #define PA_CHANNEL_POSITION_AUX3 PA_CHANNEL_POSITION_AUX3
170 #define PA_CHANNEL_POSITION_AUX4 PA_CHANNEL_POSITION_AUX4
171 #define PA_CHANNEL_POSITION_AUX5 PA_CHANNEL_POSITION_AUX5
172 #define PA_CHANNEL_POSITION_AUX6 PA_CHANNEL_POSITION_AUX6
173 #define PA_CHANNEL_POSITION_AUX7 PA_CHANNEL_POSITION_AUX7
174 #define PA_CHANNEL_POSITION_AUX8 PA_CHANNEL_POSITION_AUX8
175 #define PA_CHANNEL_POSITION_AUX9 PA_CHANNEL_POSITION_AUX9
176 #define PA_CHANNEL_POSITION_AUX10 PA_CHANNEL_POSITION_AUX10
177 #define PA_CHANNEL_POSITION_AUX11 PA_CHANNEL_POSITION_AUX11
178 #define PA_CHANNEL_POSITION_AUX12 PA_CHANNEL_POSITION_AUX12
179 #define PA_CHANNEL_POSITION_AUX13 PA_CHANNEL_POSITION_AUX13
180 #define PA_CHANNEL_POSITION_AUX14 PA_CHANNEL_POSITION_AUX14
181 #define PA_CHANNEL_POSITION_AUX15 PA_CHANNEL_POSITION_AUX15
182 #define PA_CHANNEL_POSITION_AUX16 PA_CHANNEL_POSITION_AUX16
183 #define PA_CHANNEL_POSITION_AUX17 PA_CHANNEL_POSITION_AUX17
184 #define PA_CHANNEL_POSITION_AUX18 PA_CHANNEL_POSITION_AUX18
185 #define PA_CHANNEL_POSITION_AUX19 PA_CHANNEL_POSITION_AUX19
186 #define PA_CHANNEL_POSITION_AUX20 PA_CHANNEL_POSITION_AUX20
187 #define PA_CHANNEL_POSITION_AUX21 PA_CHANNEL_POSITION_AUX21
188 #define PA_CHANNEL_POSITION_AUX22 PA_CHANNEL_POSITION_AUX22
189 #define PA_CHANNEL_POSITION_AUX23 PA_CHANNEL_POSITION_AUX23
190 #define PA_CHANNEL_POSITION_AUX24 PA_CHANNEL_POSITION_AUX24
191 #define PA_CHANNEL_POSITION_AUX25 PA_CHANNEL_POSITION_AUX25
192 #define PA_CHANNEL_POSITION_AUX26 PA_CHANNEL_POSITION_AUX26
193 #define PA_CHANNEL_POSITION_AUX27 PA_CHANNEL_POSITION_AUX27
194 #define PA_CHANNEL_POSITION_AUX28 PA_CHANNEL_POSITION_AUX28
195 #define PA_CHANNEL_POSITION_AUX29 PA_CHANNEL_POSITION_AUX29
196 #define PA_CHANNEL_POSITION_AUX30 PA_CHANNEL_POSITION_AUX30
197 #define PA_CHANNEL_POSITION_AUX31 PA_CHANNEL_POSITION_AUX31
198 #define PA_CHANNEL_POSITION_TOP_CENTER PA_CHANNEL_POSITION_TOP_CENTER
199 #define PA_CHANNEL_POSITION_TOP_FRONT_LEFT PA_CHANNEL_POSITION_TOP_FRONT_LEFT
200 #define PA_CHANNEL_POSITION_TOP_FRONT_RIGHT PA_CHANNEL_POSITION_TOP_FRONT_RIGHT
201 #define PA_CHANNEL_POSITION_TOP_FRONT_CENTER PA_CHANNEL_POSITION_TOP_FRONT_CENTER
202 #define PA_CHANNEL_POSITION_TOP_REAR_LEFT PA_CHANNEL_POSITION_TOP_REAR_LEFT
203 #define PA_CHANNEL_POSITION_TOP_REAR_RIGHT PA_CHANNEL_POSITION_TOP_REAR_RIGHT
204 #define PA_CHANNEL_POSITION_TOP_REAR_CENTER PA_CHANNEL_POSITION_TOP_REAR_CENTER
205 #define PA_CHANNEL_POSITION_MAX PA_CHANNEL_POSITION_MAX
206 /** \endcond */
207
208 /** A mask of channel positions. \since 0.9.16 */
209 typedef uint64_t pa_channel_position_mask_t;
210
211 /** Makes a bit mask from a channel position. \since 0.9.16 */
212 #define PA_CHANNEL_POSITION_MASK(f) ((pa_channel_position_mask_t) (1ULL << (f)))
213
214 /** A list of channel mapping definitions for pa_channel_map_init_auto() */
215 typedef enum pa_channel_map_def {
216 PA_CHANNEL_MAP_AIFF,
217 /**< The mapping from RFC3551, which is based on AIFF-C */
218
219 PA_CHANNEL_MAP_ALSA,
220 /**< The default mapping used by ALSA */
221
222 PA_CHANNEL_MAP_AUX,
223 /**< Only aux channels */
224
225 PA_CHANNEL_MAP_WAVEEX,
226 /**< Microsoft's WAVEFORMATEXTENSIBLE mapping */
227
228 PA_CHANNEL_MAP_OSS,
229 /**< The default channel mapping used by OSS as defined in the OSS 4.0 API specs */
230
231 /**< Upper limit of valid channel mapping definitions */
232 PA_CHANNEL_MAP_DEF_MAX,
233
234 PA_CHANNEL_MAP_DEFAULT = PA_CHANNEL_MAP_AIFF
235 /**< The default channel map */
236 } pa_channel_map_def_t;
237
238 /** \cond fulldocs */
239 #define PA_CHANNEL_MAP_AIFF PA_CHANNEL_MAP_AIFF
240 #define PA_CHANNEL_MAP_ALSA PA_CHANNEL_MAP_ALSA
241 #define PA_CHANNEL_MAP_AUX PA_CHANNEL_MAP_AUX
242 #define PA_CHANNEL_MAP_WAVEEX PA_CHANNEL_MAP_WAVEEX
243 #define PA_CHANNEL_MAP_OSS PA_CHANNEL_MAP_OSS
244 #define PA_CHANNEL_MAP_DEF_MAX PA_CHANNEL_MAP_DEF_MAX
245 #define PA_CHANNEL_MAP_DEFAULT PA_CHANNEL_MAP_DEFAULT
246 /** \endcond */
247
248 /** A channel map which can be used to attach labels to specific
249 * channels of a stream. These values are relevant for conversion and
250 * mixing of streams */
251 typedef struct pa_channel_map {
252 uint8_t channels;
253 /**< Number of channels */
254
255 pa_channel_position_t map[PA_CHANNELS_MAX];
256 /**< Channel labels */
257 } pa_channel_map;
258
259 /** Initialize the specified channel map and return a pointer to
260 * it. The channel map will have a defined state but
261 * pa_channel_map_valid() will fail for it. */
262 pa_channel_map* pa_channel_map_init(pa_channel_map *m);
263
264 /** Initialize the specified channel map for monaural audio and return a pointer to it */
265 pa_channel_map* pa_channel_map_init_mono(pa_channel_map *m);
266
267 /** Initialize the specified channel map for stereophonic audio and return a pointer to it */
268 pa_channel_map* pa_channel_map_init_stereo(pa_channel_map *m);
269
270 /** Initialize the specified channel map for the specified number of
271 * channels using default labels and return a pointer to it. This call
272 * will fail (return NULL) if there is no default channel map known for this
273 * specific number of channels and mapping. */
274 pa_channel_map* pa_channel_map_init_auto(pa_channel_map *m, unsigned channels, pa_channel_map_def_t def);
275
276 /** Similar to pa_channel_map_init_auto() but instead of failing if no
277 * default mapping is known with the specified parameters it will
278 * synthesize a mapping based on a known mapping with fewer channels
279 * and fill up the rest with AUX0...AUX31 channels \since 0.9.11 */
280 pa_channel_map* pa_channel_map_init_extend(pa_channel_map *m, unsigned channels, pa_channel_map_def_t def);
281
282 /** Return a text label for the specified channel position */
283 const char* pa_channel_position_to_string(pa_channel_position_t pos) PA_GCC_PURE;
284
285 /* The inverse of pa_channel_position_to_string(). \since 0.9.16 */
286 pa_channel_position_t pa_channel_position_from_string(const char *s) PA_GCC_PURE;
287
288 /** Return a human readable text label for the specified channel position. \since 0.9.7 */
289 const char* pa_channel_position_to_pretty_string(pa_channel_position_t pos);
290
291 /** The maximum length of strings returned by
292 * pa_channel_map_snprint(). Please note that this value can change
293 * with any release without warning and without being considered API
294 * or ABI breakage. You should not use this definition anywhere where
295 * it might become part of an ABI. */
296 #define PA_CHANNEL_MAP_SNPRINT_MAX 336
297
298 /** Make a human readable string from the specified channel map */
299 char* pa_channel_map_snprint(char *s, size_t l, const pa_channel_map *map);
300
301 /** Parse a channel position list or well-known mapping name into a
302 * channel map structure. This turns the output of
303 * pa_channel_map_snprint() and pa_channel_map_to_name() back into a
304 * pa_channel_map */
305 pa_channel_map *pa_channel_map_parse(pa_channel_map *map, const char *s);
306
307 /** Compare two channel maps. Return 1 if both match. */
308 int pa_channel_map_equal(const pa_channel_map *a, const pa_channel_map *b) PA_GCC_PURE;
309
310 /** Return non-zero if the specified channel map is considered valid */
311 int pa_channel_map_valid(const pa_channel_map *map) PA_GCC_PURE;
312
313 /** Return non-zero if the specified channel map is compatible with
314 * the specified sample spec. \since 0.9.12 */
315 int pa_channel_map_compatible(const pa_channel_map *map, const pa_sample_spec *ss) PA_GCC_PURE;
316
317 /** Returns non-zero if every channel defined in b is also defined in a. \since 0.9.15 */
318 int pa_channel_map_superset(const pa_channel_map *a, const pa_channel_map *b) PA_GCC_PURE;
319
320 /** Returns non-zero if it makes sense to apply a volume 'balance'
321 * with this mapping, i.e. if there are left/right channels
322 * available. \since 0.9.15 */
323 int pa_channel_map_can_balance(const pa_channel_map *map) PA_GCC_PURE;
324
325 /** Returns non-zero if it makes sense to apply a volume 'fade'
326 * (i.e. 'balance' between front and rear) with this mapping, i.e. if
327 * there are front/rear channels available. \since 0.9.15 */
328 int pa_channel_map_can_fade(const pa_channel_map *map) PA_GCC_PURE;
329
330 /** Tries to find a well-known channel mapping name for this channel
331 * mapping. I.e. "stereo", "surround-71" and so on. If the channel
332 * mapping is unknown NULL will be returned. This name can be parsed
333 * with pa_channel_map_parse() \since 0.9.15 */
334 const char* pa_channel_map_to_name(const pa_channel_map *map) PA_GCC_PURE;
335
336 /** Tries to find a human readable text label for this channel
337 mapping. I.e. "Stereo", "Surround 7.1" and so on. If the channel
338 mapping is unknown NULL will be returned. \since 0.9.15 */
339 const char* pa_channel_map_to_pretty_name(const pa_channel_map *map) PA_GCC_PURE;
340
341 /** Returns TRUE if the specified channel position is available at
342 * least once in the channel map. \since 0.9.16 */
343 int pa_channel_map_has_position(const pa_channel_map *map, pa_channel_position_t p) PA_GCC_PURE;
344
345 /** Generates a bit mask from a channel map. \since 0.9.16 */
346 pa_channel_position_mask_t pa_channel_map_mask(const pa_channel_map *map) PA_GCC_PURE;
347
348 PA_C_DECL_END
349
350 #endif