Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
channel_defs.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_audio/channel_defs.h
10 //! @brief Channel layout, order, and positions.
11 
12 #ifndef ROC_AUDIO_CHANNEL_DEFS_H_
13 #define ROC_AUDIO_CHANNEL_DEFS_H_
14 
15 #include "roc_core/stddefs.h"
16 
17 namespace roc {
18 namespace audio {
19 
20 //! Channel layout.
21 //! Defines meaning of channels in ChannelSet.
22 //! ChannelMapper uses channel layout to decide how to perform mapping.
24  //! Channel layout is not set.
25  //! @remarks
26  //! This is never valid and indicates that ChannelSet is not fully initialized.
28 
29  //! Multi-channel mono / stereo / surround sound.
30  //! @remarks
31  //! The meaning of channel index is defined by ChannelPosition enum.
32  //! Channels are mapped according to their position in space, e.g. if
33  //! top-left channel is missing, it can be mixed from front-left and
34  //! side-left channels.
36 
37  //! Multi-channel multi-track sound.
38  //! @remarks
39  //! There is no special meaning of channels, they are considered to be
40  //! independent tracks. Channels are mapped according to their numbers;
41  //! channel N is mapped to channel N and nothing else.
43 };
44 
45 //! Surround channel order.
46 //! @remarks
47 //! Should be used with ChannelLayout_Surround.
48 //! Defines order in which channels from ChannelSet are (de)serialized.
50  //! Channel order is not set.
51  //! @remarks
52  //! For ChanLayout_Surround, this is never valid and indicates that ChannelSet
53  //! is not fully initialized. For ChanLayout_Multitrack, in contrast, this is
54  //! the only valid value.
56 
57  //! ITU/SMPTE channel order.
58  //! Order: FL, FR, FC, LFE, BL, BR, BC, SL, SR, TFL, TFR, TBL, TBR, TML, TMR.
59  //! @remarks
60  //! This order is actually a superset of what is defined by SMPTE, but when
61  //! filtered by actual masks like 5.1 or 7.1, it produces orderings equal
62  //! to what is defined in the standard.
63  //! When used with masks 2.x - 5.x (but not 6.x), it is also compatible with
64  //! the channel order from AIFF-C, which is used by default in RTP/AVP, as
65  //! defined in RFC 3551.
67 
68  //! ALSA channel order.
69  //! Order: FL, FR, BL, BR, FC, LFE, SL, SR, BC.
70  //! @remarks
71  //! This order is used by ALSA hardware devices.
72  //! ALSA supports only 9 channels.
74 
75  //! Maximum value of enum.
77 };
78 
79 //! Surround channel position.
80 //! @remarks
81 //! Should be used with ChannelLayout_Surround.
82 //! Defines meaning of channel indices for mono / stereo / surround sound.
83 //! @note
84 //! Despite mono, stereo, and 3.x technically are not surround layouts, in
85 //! the code base they are considered a special case of surround.
87  //! @name Front speakers.
88  //! @remarks
89  //! Placed in the front of the user.
90  //! FLC and FRC are typically used for 3-channel center speaker.
91  // @{
92  ChanPos_FrontLeft, //!< Front left (FL).
93  ChanPos_FrontLeftOfCenter, //!< Front left of center (FLC).
94  ChanPos_FrontCenter, //!< Front center (FC).
95  ChanPos_FrontRightOfCenter, //!< Front right of center (FRC).
96  ChanPos_FrontRight, //!< Front right (FR).
97  // @}
98 
99  //! @name Surround speakers.
100  //! @remarks
101  //! Placed on the sides of the user (in surround 7.x).
102  //! Also known as "mid" speakers.
103  // @{
104  ChanPos_SideLeft, //!< Side left (SL).
105  ChanPos_SideRight, //!< Side right (SR).
106  // @}
107 
108  //! @name Back speakers.
109  //! @remarks
110  //! Placed behind the user.
111  //! Also known as "rear" speakers.
112  // @{
113  ChanPos_BackLeft, //!< Back left (BL).
114  ChanPos_BackCenter, //!< Back center (BC).
115  ChanPos_BackRight, //!< Back right (BR).
116  // @}
117 
118  //! @name Top speakers.
119  //! @remarks
120  //! Placed above the user.
121  //! Also known as "height" or "overhead" speakers.
122  //! TFC and TBC are typically used for 3-channel overhead soundbars.
123  // @{
124  ChanPos_TopFrontLeft, //!< Top front left (TFL).
125  ChanPos_TopFrontRight, //!< Top front right (TFR).
126 
127  ChanPos_TopMidLeft, //!< Top middle left (TML).
128  ChanPos_TopMidRight, //!< Top middle right (TMR).
129 
130  ChanPos_TopBackLeft, //!< Top rear left (TBL).
131  ChanPos_TopBackRight, //!< Top rear right (TBR).
132  // @}
133 
134  //! Low frequency speaker (LFE).
135  //! @remarks
136  //! Placed anywhere.
137  //! Also known as "subwoofer" or "SW" speaker.
139 
140  //! Maximum value of enum.
142 };
143 
144 //! Channel mask.
145 //! @remarks
146 //! Used to construct short channel sets (up to 32 channels)
147 //! for ChanLayout_Surround layout.
148 typedef uint32_t ChannelMask;
149 
150 //! Mono.
151 //! Mask: FC.
152 //! @code
153 //! +----------------------+
154 //! | FC |
155 //! | user |
156 //! +----------------------+
157 //! @endcode
158 static const ChannelMask ChanMask_Surround_Mono = //
159  (1 << ChanPos_FrontCenter);
160 
161 //! Mono + subwoofer.
162 //! Mask: FC | LFE.
163 //! @code
164 //! +----------------------+
165 //! | FC |
166 //! | user |
167 //! | LFE |
168 //! +----------------------+
169 //! @endcode
170 static const ChannelMask ChanMask_Surround_1_1 = //
171  ChanMask_Surround_Mono //
172  | (1 << ChanPos_LowFrequency);
173 
174 //! 3-channel center speaker + subwoofer.
175 //! Mask: FLC, FC, FRC | LFE.
176 //! @code
177 //! +----------------------+
178 //! | FLC|FC|FRC |
179 //! | user |
180 //! | LFE |
181 //! +----------------------+
182 //! @endcode
183 static const ChannelMask ChanMask_Surround_1_1_3c = //
184  ChanMask_Surround_1_1 | //
186 
187 //! Stereo.
188 //! Mask: FL, FR.
189 //! @code
190 //! +----------------------+
191 //! | FL FR |
192 //! | user |
193 //! +----------------------+
194 //! @endcode
195 static const ChannelMask ChanMask_Surround_Stereo = //
196  (1 << ChanPos_FrontLeft) | (1 << ChanPos_FrontRight);
197 
198 //! Stereo + subwoofer.
199 //! Mask: FL, FR | LFE.
200 //! +----------------------+
201 //! | FL FR |
202 //! | user |
203 //! | LFE |
204 //! +----------------------+
205 //! @endcode
206 static const ChannelMask ChanMask_Surround_2_1 = //
207  ChanMask_Surround_Stereo //
208  | (1 << ChanPos_LowFrequency);
209 
210 //! Three front speakers.
211 //! Mask: FL, FC, FR.
212 //! @code
213 //! +----------------------+
214 //! | FL FC FR |
215 //! | user |
216 //! +----------------------+
217 //! @endcode
218 static const ChannelMask ChanMask_Surround_3_0 =
220 
221 //! Three front speakers + subwoofer.
222 //! Mask: FL, FC, FR | LFE.
223 //! @code
224 //! +----------------------+
225 //! | FL FC FR |
226 //! | user |
227 //! | LFE |
228 //! +----------------------+
229 //! @endcode
230 static const ChannelMask ChanMask_Surround_3_1 = //
231  ChanMask_Surround_3_0 //
232  | (1 << ChanPos_LowFrequency);
233 
234 //! Three front speakers + subwoofer, with 3-channel center speaker.
235 //! Mask: FL, FLC, FC, FRC, FR | LFE.
236 //! @code
237 //! +----------------------+
238 //! | FL FLC|FC|FRC FR |
239 //! | user |
240 //! | LFE |
241 //! +----------------------+
242 //! @endcode
243 static const ChannelMask ChanMask_Surround_3_1_3c = //
244  ChanMask_Surround_3_1 //
246 
247 //! Surround 4.0.
248 //! Mask: FL, FR, BL, BR.
249 //! @code
250 //! +----------------------+
251 //! | FL FR |
252 //! | user |
253 //! | BL BR |
254 //! +----------------------+
255 //! @endcode
256 static const ChannelMask ChanMask_Surround_4_0 = //
257  (1 << ChanPos_FrontLeft) | (1 << ChanPos_FrontRight) //
258  | (1 << ChanPos_BackLeft) | (1 << ChanPos_BackRight);
259 
260 //! Surround 4.1.
261 //! Mask: FL, FR, BL, BR | LFE.
262 //! @code
263 //! +----------------------+
264 //! | FL FR |
265 //! | user |
266 //! | LFE |
267 //! | BL BR |
268 //! +----------------------+
269 //! @endcode
270 static const ChannelMask ChanMask_Surround_4_1 = //
271  ChanMask_Surround_4_0 //
272  | (1 << ChanPos_LowFrequency);
273 
274 //! Surround 5.0.
275 //! Mask: FL, FC, FR, BL, BR.
276 //! @code
277 //! +----------------------+
278 //! | FL FC FR |
279 //! | user |
280 //! | BL BR |
281 //! +----------------------+
282 //! @endcode
283 static const ChannelMask ChanMask_Surround_5_0 = //
284  (1 << ChanPos_FrontLeft) | (1 << ChanPos_FrontCenter) | (1 << ChanPos_FrontRight) //
285  | (1 << ChanPos_BackLeft) | (1 << ChanPos_BackRight);
286 
287 //! Surround 5.1.
288 //! Mask: FL, FC, FR, BL, BR | LFE.
289 //! @code
290 //! +----------------------+
291 //! | FL FC FR |
292 //! | user |
293 //! | LFE |
294 //! | BL BR |
295 //! +----------------------+
296 //! @endcode
297 static const ChannelMask ChanMask_Surround_5_1 = //
298  ChanMask_Surround_5_0 //
299  | (1 << ChanPos_LowFrequency);
300 
301 //! Surround 5.1, with 3-channel center speaker.
302 //! Mask: FL, FLC, FC, FRC, FR, BL, BR | LFE.
303 //! @code
304 //! +----------------------+
305 //! | FL FLC|FC|FRC FR |
306 //! | user |
307 //! | LFE |
308 //! | BL BR |
309 //! +----------------------+
310 //! @endcode
311 static const ChannelMask ChanMask_Surround_5_1_3c = //
312  ChanMask_Surround_5_1 //
314 
315 //! Surround 5.1.2.
316 //! Mask: FL, FC, FR, BL, BR | LFE | TML, TMR.
317 //! @code
318 //! +----------------------+
319 //! | FL FC FR |
320 //! | |
321 //! | TML user TMR |
322 //! | LFE |
323 //! | BL BR |
324 //! +----------------------+
325 //! @endcode
326 static const ChannelMask ChanMask_Surround_5_1_2 = //
327  ChanMask_Surround_5_1 //
328  | (1 << ChanPos_TopMidLeft) | (1 << ChanPos_TopMidRight);
329 
330 //! Surround 5.1.2, with 3-channel center speaker.
331 //! Mask: FL, FLC, FC, FRC, FR, BL, BR | LFE | TML, TMR.
332 //! @code
333 //! +----------------------+
334 //! | FL FLC|FC|FRC FR |
335 //! | |
336 //! | TML user TMR |
337 //! | LFE |
338 //! | BL BR |
339 //! +----------------------+
340 //! @endcode
341 static const ChannelMask ChanMask_Surround_5_1_2_3c = //
342  ChanMask_Surround_5_1_2 //
344 
345 //! Surround 5.1.4.
346 //! Mask: FL, FC, FR, BL, BR | LFE | TFL, TFR, TBL, TBR.
347 //! @code
348 //! +----------------------+
349 //! | FL FC FR |
350 //! | TFL TFR |
351 //! | user |
352 //! | LFE |
353 //! | TBL TBR |
354 //! | BL BR |
355 //! +----------------------+
356 //! @endcode
357 static const ChannelMask ChanMask_Surround_5_1_4 = //
358  ChanMask_Surround_5_1 //
360  | (1 << ChanPos_TopBackLeft) | (1 << ChanPos_TopBackRight);
361 
362 //! Surround 5.1.4, with 3-channel center speaker.
363 //! Mask: FL, FLC, FC, FRC, FR, BL, BR | LFE | TFL, TFR, TBL, TBR.
364 //! @code
365 //! +----------------------+
366 //! | FL FLC|FC|FRC FR |
367 //! | TFL TFR |
368 //! | user |
369 //! | LFE |
370 //! | TBL TBR |
371 //! | BL BR |
372 //! +----------------------+
373 //! @endcode
374 static const ChannelMask ChanMask_Surround_5_1_4_3c = //
375  ChanMask_Surround_5_1_4 //
377 
378 //! Surround 6.0.
379 //! Mask: FL, FC, FR, BL, BC, BR.
380 //! @code
381 //! +----------------------+
382 //! | FL FC FR |
383 //! | user |
384 //! | BL BC BR |
385 //! +----------------------+
386 //! @endcode
387 static const ChannelMask ChanMask_Surround_6_0 = //
388  (1 << ChanPos_FrontLeft) | (1 << ChanPos_FrontCenter) | (1 << ChanPos_FrontRight) //
389  | (1 << ChanPos_BackLeft) | (1 << ChanPos_BackCenter) | (1 << ChanPos_BackRight);
390 
391 //! Surround 6.1.
392 //! Mask: FL, FC, FR, BL, BC, BR | LFE.
393 //! @code
394 //! +----------------------+
395 //! | FL FC FR |
396 //! | user |
397 //! | LFE |
398 //! | BL BC BR |
399 //! +----------------------+
400 //! @endcode
401 static const ChannelMask ChanMask_Surround_6_1 = //
402  ChanMask_Surround_6_0 //
403  | (1 << ChanPos_LowFrequency);
404 
405 //! Surround 6.1, with 3-channel center speaker.
406 //! Mask: FL, FLC, FC, FRC, FR, BL, BC, BR | LFE.
407 //! @code
408 //! +----------------------+
409 //! | FL FLC|FC|FRC FR |
410 //! | user |
411 //! | LFE |
412 //! | BL BC BR |
413 //! +----------------------+
414 //! @endcode
415 static const ChannelMask ChanMask_Surround_6_1_3c = //
416  ChanMask_Surround_6_1 //
418 
419 //! Surround 7.0.
420 //! Mask: FL, FC, FR, SL, SR, BL, BR.
421 //! @code
422 //! +----------------------+
423 //! | FL FC FR |
424 //! | SL user SR |
425 //! | BL BR |
426 //! +----------------------+
427 //! @endcode
428 static const ChannelMask ChanMask_Surround_7_0 = //
429  (1 << ChanPos_FrontLeft) | (1 << ChanPos_FrontCenter) | (1 << ChanPos_FrontRight) //
430  | (1 << ChanPos_SideLeft) | (1 << ChanPos_SideRight) //
431  | (1 << ChanPos_BackLeft) | (1 << ChanPos_BackRight);
432 
433 //! Surround 7.1.
434 //! Mask: FL, FC, FR, SL, SR, BL, BR | LFE.
435 //! @code
436 //! +----------------------+
437 //! | FL FC FR |
438 //! | SL user SR |
439 //! | LFE |
440 //! | BL BR |
441 //! +----------------------+
442 //! @endcode
443 static const ChannelMask ChanMask_Surround_7_1 = //
444  ChanMask_Surround_7_0 //
445  | (1 << ChanPos_LowFrequency);
446 
447 //! Surround 7.1, with 3-channel center speaker.
448 //! Mask: FL, FLC, FC, FRC, FR, SL, SR, BL, BR | LFE.
449 //! @code
450 //! +----------------------+
451 //! | FL FLC|FC|FRC FR |
452 //! | SL user SR |
453 //! | LFE |
454 //! | BL BR |
455 //! +----------------------+
456 //! @endcode
457 static const ChannelMask ChanMask_Surround_7_1_3c = //
458  ChanMask_Surround_7_1 //
460 
461 //! Surround 7.1.2.
462 //! Mask: FL, FC, FR, SL, SR, BL, BR | LFE | TML, TMR.
463 //! @code
464 //! +----------------------+
465 //! | FL FC FR |
466 //! | |
467 //! | TML TMR |
468 //! | SL user SR |
469 //! | LFE |
470 //! | BL BR |
471 //! +----------------------+
472 //! @endcode
473 static const ChannelMask ChanMask_Surround_7_1_2 = //
474  ChanMask_Surround_7_1 //
475  | (1 << ChanPos_TopMidLeft) | (1 << ChanPos_TopMidRight);
476 
477 //! Surround 7.1.2, with 3-channel center speaker.
478 //! Mask: FL, FLC, FC, FRC, FR, SL, SR, BL, BR | LFE | TML, TMR.
479 //! @code
480 //! +----------------------+
481 //! | FL FLC|FC|FRC FR |
482 //! | |
483 //! | TML TMR |
484 //! | SL user SR |
485 //! | LFE |
486 //! | BL BR |
487 //! +----------------------+
488 //! @endcode
489 static const ChannelMask ChanMask_Surround_7_1_2_3c = //
490  ChanMask_Surround_7_1_2 //
492 
493 //! Surround 7.1.4.
494 //! Mask: FL, FC, FR, SL, SR, BL, BR | LFE | TFL, TFR, TBL, TBR.
495 //! @code
496 //! +----------------------+
497 //! | FL FC FR |
498 //! | TFL TFR |
499 //! | SL user SR |
500 //! | LFE |
501 //! | TBL TBR |
502 //! | BL BR |
503 //! +----------------------+
504 //! @endcode
505 static const ChannelMask ChanMask_Surround_7_1_4 = //
506  ChanMask_Surround_7_1 //
508  | (1 << ChanPos_TopBackLeft) | (1 << ChanPos_TopBackRight);
509 
510 //! Surround 7.1.4, with 3-channel center speaker.
511 //! Mask: FL, FLC, FC, FRC, FR, SL, SR, BL, BR | LFE | TFL, TFR, TBL, TBR.
512 //! @code
513 //! +----------------------+
514 //! | FL FLC|FC|FRC FR |
515 //! | TFL TFR |
516 //! | SL user SR |
517 //! | LFE |
518 //! | TBL TBR |
519 //! | BL BR |
520 //! +----------------------+
521 //! @endcode
522 static const ChannelMask ChanMask_Surround_7_1_4_3c = //
523  ChanMask_Surround_7_1_4 //
525 
526 //! Get string name of channel layout.
528 
529 //! Get string name of channel order.
531 
532 //! Get string name from channel position.
534 
535 //! Get string name from channel mask.
537 
538 } // namespace audio
539 } // namespace roc
540 
541 #endif // ROC_AUDIO_CHANNEL_DEFS_H_
const char * channel_order_to_str(ChannelOrder)
Get string name of channel order.
const char * channel_mask_to_str(ChannelMask)
Get string name from channel mask.
ChannelPosition
Surround channel position.
Definition: channel_defs.h:86
@ ChanPos_SideLeft
Side left (SL).
Definition: channel_defs.h:104
@ ChanPos_FrontLeftOfCenter
Front left of center (FLC).
Definition: channel_defs.h:93
@ ChanPos_Max
Maximum value of enum.
Definition: channel_defs.h:141
@ ChanPos_TopBackLeft
Top rear left (TBL).
Definition: channel_defs.h:130
@ ChanPos_FrontCenter
Front center (FC).
Definition: channel_defs.h:94
@ ChanPos_FrontLeft
Front left (FL).
Definition: channel_defs.h:92
@ ChanPos_LowFrequency
Low frequency speaker (LFE).
Definition: channel_defs.h:138
@ ChanPos_TopFrontLeft
Top front left (TFL).
Definition: channel_defs.h:124
@ ChanPos_FrontRight
Front right (FR).
Definition: channel_defs.h:96
@ ChanPos_BackRight
Back right (BR).
Definition: channel_defs.h:115
@ ChanPos_TopBackRight
Top rear right (TBR).
Definition: channel_defs.h:131
@ ChanPos_SideRight
Side right (SR).
Definition: channel_defs.h:105
@ ChanPos_BackLeft
Back left (BL).
Definition: channel_defs.h:113
@ ChanPos_TopMidRight
Top middle right (TMR).
Definition: channel_defs.h:128
@ ChanPos_BackCenter
Back center (BC).
Definition: channel_defs.h:114
@ ChanPos_FrontRightOfCenter
Front right of center (FRC).
Definition: channel_defs.h:95
@ ChanPos_TopMidLeft
Top middle left (TML).
Definition: channel_defs.h:127
@ ChanPos_TopFrontRight
Top front right (TFR).
Definition: channel_defs.h:125
const char * channel_pos_to_str(ChannelPosition)
Get string name from channel position.
ChannelLayout
Channel layout. Defines meaning of channels in ChannelSet. ChannelMapper uses channel layout to decid...
Definition: channel_defs.h:23
@ ChanLayout_Multitrack
Multi-channel multi-track sound.
Definition: channel_defs.h:42
@ ChanLayout_None
Channel layout is not set.
Definition: channel_defs.h:27
@ ChanLayout_Surround
Multi-channel mono / stereo / surround sound.
Definition: channel_defs.h:35
uint32_t ChannelMask
Channel mask.
Definition: channel_defs.h:148
const char * channel_layout_to_str(ChannelLayout)
Get string name of channel layout.
ChannelOrder
Surround channel order.
Definition: channel_defs.h:49
@ ChanOrder_Max
Maximum value of enum.
Definition: channel_defs.h:76
@ ChanOrder_None
Channel order is not set.
Definition: channel_defs.h:55
@ ChanOrder_Smpte
ITU/SMPTE channel order. Order: FL, FR, FC, LFE, BL, BR, BC, SL, SR, TFL, TFR, TBL,...
Definition: channel_defs.h:66
@ ChanOrder_Alsa
ALSA channel order. Order: FL, FR, BL, BR, FC, LFE, SL, SR, BC.
Definition: channel_defs.h:73
Root namespace.
Commonly used types and functions.