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