channelmap.h 17 KB

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