Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
channel_tables.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_tables.h
10
//! @brief Channel tables.
11
12
#ifndef ROC_AUDIO_CHANNEL_TABLES_H_
13
#define ROC_AUDIO_CHANNEL_TABLES_H_
14
15
#include "
roc_audio/channel_defs.h
"
16
#include "
roc_audio/sample.h
"
17
18
namespace
roc
{
19
namespace
audio
{
20
21
//! Defines string name for channel position.
22
struct
ChannelPositionName
{
23
//! Channel name.
24
const
char
*
name
;
25
26
//! Channel position (numeric identifier).
27
ChannelPosition
pos
;
28
};
29
30
//! Defines string name for pre-defined channel mask.
31
struct
ChannelMaskName
{
32
//! Mask name.
33
const
char
*
name
;
34
35
//! Bitmask of enabled channels.
36
ChannelMask
mask
;
37
};
38
39
//! Defines multiplication coefficient for a pair of channels.
40
struct
ChannelMapRule
{
41
//! Index of output channel.
42
ChannelPosition
out_ch
;
43
44
//! Index of input channel.
45
ChannelPosition
in_ch
;
46
47
//! Multiplication coefficient.
48
//! @remarks
49
//! output channel is a sum of input channels multiplied
50
//! by corresponding coefficients.
51
sample_t
coeff
;
52
};
53
54
//! Defines multiplication matrix for two channel masks.
55
//!
56
//! Instead of defining the whole matrix, it defines a list of pairs of
57
//! output and input channel numbers and corresponding coefficients.
58
//!
59
//! Such representation allows more compact definition in the source
60
//! code. The actual matrix is built by channel mapper at runtime.
61
struct
ChannelMapTable
{
62
//! Table name.
63
const
char
*
name
;
64
65
//! Channel mask of input stream.
66
ChannelMask
in_mask
;
67
//! Channel mask of output stream.
68
ChannelMask
out_mask
;
69
70
//! Transformation rules.
71
//! Rules are used to fill channel mapping matrix.
72
ChannelMapRule
rules
[32];
73
};
74
75
//! Defines ordered list of channels.
76
struct
ChannelOrderTable
{
77
//! Order name.
78
const
char
*
name
;
79
80
//! Order identifier.
81
ChannelOrder
order
;
82
83
//! List of channels.
84
//! Last channel is equal to ChanPos_Max.
85
ChannelPosition
chans
[
ChanPos_Max
+ 1];
86
};
87
88
//! Defines mapping between channel position and its name.
89
extern
const
ChannelPositionName
ChanPositionNames
[
ChanPos_Max
];
90
91
//! Defines mapping between channel mask and its name.
92
extern
const
ChannelMaskName
ChanMaskNames
[17];
93
94
//! Defines mapping of channel order identifier to list of channel positions
95
//! in corresponding order.
96
//!
97
//! When channel order is applied, the list of channels is filtered, and only
98
//! channels present in channel mask are kept. The resulting filtered list
99
//! defines how channels are placed in memory.
100
//!
101
//! This allows us to define single list that for multiple channel masks.
102
//! For example, ITU/SMPTE defines order for each channel mask (5.x, 7.x),
103
//! but we define only one list ChanOrder_Smpte, and after filtering it
104
//! becomes suitable for each of the masks.
105
//!
106
//! The opposite is also true: if some channel is missing from the order's
107
//! list, it is considered unsupported by the order and is zeroized.
108
//!
109
//! Links:
110
//! https://www.itu.int/dms_pubrec/itu-r/rec/bs/R-REC-BS.2102-0-201701-I!!PDF-E.pdf
111
extern
const
ChannelOrderTable
ChanOrderTables
[
ChanOrder_Max
];
112
113
//! Defines list of mappings between all supported surround channel mask pairs.
114
//!
115
//! Channel mapper will search for appropriate mapping in this list,
116
//! based on input and output channel masks.
117
//!
118
//! These tables define downmixing coefficients for mapping between different
119
//! surround channel sets. They are used for both downmixing and upmixing.
120
//!
121
//! Mappings should be ordered from smaller to larger masks, because channel mapper
122
//! will use the very first pair that covers both output and input masks.
123
//!
124
//! Only downmixing mappings are defined. Upmixing mappings are derived
125
//! automatically from them.
126
//!
127
//! Technically, some of the mappings are actually partially downmixing, and
128
//! partially upmixing, for example mapping from 6.x to 5.1.x downmixes some
129
//! channels and upmixes others. However, for convenience, we still call it
130
//! "downmixing" because we consider 6.x to be a "larger" channel set than 5.x.
131
//!
132
//! For groups of similar layouts, when possible, mappings are defined only for
133
//! the most complete layout, and are automatically reused for the rest. For example,
134
//! mappings for 5.1.2 may be automatically used for 5.1 and 5.0.
135
//!
136
//! These tables were originally based on the following documents
137
//! (and then extended to cover more combinations):
138
//! - ITU-R BS.775-1, ANNEX 4
139
//! - A/52, Digital Audio Compression (AC-3) (E-AC-3) Standard, sections 6.1.12 and 7.8
140
//!
141
//! Useful links:
142
//! https://www.itu.int/dms_pubrec/itu-r/rec/bs/R-REC-BS.775-1-199407-S!!PDF-E.pdf
143
//! https://prdatsc.wpenginepowered.com/wp-content/uploads/2021/04/A52-2018.pdf
144
//! https://www.audiokinetic.com/en/library/edge/?source=Help&id=downmix_tables
145
//! https://trac.ffmpeg.org/wiki/AudioChannelManipulation
146
//! https://superuser.com/questions/852400
147
extern
const
ChannelMapTable
ChanMapTables
[71];
148
149
}
// namespace audio
150
}
// namespace roc
151
152
#endif
// ROC_AUDIO_CHANNEL_TABLES_H_
channel_defs.h
Channel layout, order, and positions.
roc::audio
Audio frames and audio processing.
roc::audio::ChanMaskNames
const ChannelMaskName ChanMaskNames[17]
Defines mapping between channel mask and its name.
roc::audio::ChannelPosition
ChannelPosition
Surround channel position.
Definition
channel_defs.h:86
roc::audio::ChanPos_Max
@ ChanPos_Max
Maximum value of enum.
Definition
channel_defs.h:141
roc::audio::sample_t
float sample_t
Raw audio sample.
Definition
sample.h:22
roc::audio::ChanPositionNames
const ChannelPositionName ChanPositionNames[ChanPos_Max]
Defines mapping between channel position and its name.
roc::audio::ChanOrderTables
const ChannelOrderTable ChanOrderTables[ChanOrder_Max]
Defines mapping of channel order identifier to list of channel positions in corresponding order.
roc::audio::ChanMapTables
const ChannelMapTable ChanMapTables[71]
Defines list of mappings between all supported surround channel mask pairs.
roc::audio::ChannelMask
uint32_t ChannelMask
Channel mask.
Definition
channel_defs.h:148
roc::audio::ChannelOrder
ChannelOrder
Surround channel order.
Definition
channel_defs.h:49
roc::audio::ChanOrder_Max
@ ChanOrder_Max
Maximum value of enum.
Definition
channel_defs.h:76
roc
Root namespace.
sample.h
Audio sample.
roc::audio::ChannelMapRule
Defines multiplication coefficient for a pair of channels.
Definition
channel_tables.h:40
roc::audio::ChannelMapRule::in_ch
ChannelPosition in_ch
Index of input channel.
Definition
channel_tables.h:45
roc::audio::ChannelMapRule::coeff
sample_t coeff
Multiplication coefficient.
Definition
channel_tables.h:51
roc::audio::ChannelMapRule::out_ch
ChannelPosition out_ch
Index of output channel.
Definition
channel_tables.h:42
roc::audio::ChannelMapTable
Defines multiplication matrix for two channel masks.
Definition
channel_tables.h:61
roc::audio::ChannelMapTable::name
const char * name
Table name.
Definition
channel_tables.h:63
roc::audio::ChannelMapTable::out_mask
ChannelMask out_mask
Channel mask of output stream.
Definition
channel_tables.h:68
roc::audio::ChannelMapTable::in_mask
ChannelMask in_mask
Channel mask of input stream.
Definition
channel_tables.h:66
roc::audio::ChannelMapTable::rules
ChannelMapRule rules[32]
Transformation rules. Rules are used to fill channel mapping matrix.
Definition
channel_tables.h:72
roc::audio::ChannelMaskName
Defines string name for pre-defined channel mask.
Definition
channel_tables.h:31
roc::audio::ChannelMaskName::mask
ChannelMask mask
Bitmask of enabled channels.
Definition
channel_tables.h:36
roc::audio::ChannelMaskName::name
const char * name
Mask name.
Definition
channel_tables.h:33
roc::audio::ChannelOrderTable
Defines ordered list of channels.
Definition
channel_tables.h:76
roc::audio::ChannelOrderTable::name
const char * name
Order name.
Definition
channel_tables.h:78
roc::audio::ChannelOrderTable::chans
ChannelPosition chans[ChanPos_Max+1]
List of channels. Last channel is equal to ChanPos_Max.
Definition
channel_tables.h:85
roc::audio::ChannelOrderTable::order
ChannelOrder order
Order identifier.
Definition
channel_tables.h:81
roc::audio::ChannelPositionName
Defines string name for channel position.
Definition
channel_tables.h:22
roc::audio::ChannelPositionName::name
const char * name
Channel name.
Definition
channel_tables.h:24
roc::audio::ChannelPositionName::pos
ChannelPosition pos
Channel position (numeric identifier).
Definition
channel_tables.h:27
roc_audio
channel_tables.h
Generated by
1.17.0