26#if ! defined (DOXYGEN) && (JUCE_MAC || JUCE_IOS)
28struct CoreAudioLayouts
31 struct LayoutTagSpeakerList
33 AudioChannelLayoutTag tag;
34 AudioChannelSet::ChannelType channelTypes[16];
48 struct SpeakerLayoutTable : AudioChannelSet
50 template <
typename... Items>
51 static constexpr auto getArray (Items... items)
53 return std::array<LayoutTagSpeakerList,
sizeof... (items)> { { items... } };
56 static constexpr auto get()
58 using List = LayoutTagSpeakerList;
60 return getArray (List { kAudioChannelLayoutTag_Mono, { centre } },
61 List { kAudioChannelLayoutTag_Stereo, { left, right } },
62 List { kAudioChannelLayoutTag_MPEG_3_0_A, { left, right, centre } },
63 List { kAudioChannelLayoutTag_ITU_2_1, { left, right, centreSurround } },
64 List { kAudioChannelLayoutTag_MPEG_4_0_A, { left, right, centre, centreSurround } },
65 List { kAudioChannelLayoutTag_MPEG_5_0_A, { left, right, centre, leftSurround, rightSurround } },
66 List { kAudioChannelLayoutTag_MPEG_5_1_A, { left, right, centre, LFE, leftSurround, rightSurround } },
67 List { kAudioChannelLayoutTag_AudioUnit_6_0, { left, right, leftSurround, rightSurround, centre, centreSurround } },
68 List { kAudioChannelLayoutTag_MPEG_6_1_A, { left, right, centre, LFE, leftSurround, rightSurround, centreSurround } },
69 List { kAudioChannelLayoutTag_DTS_6_0_A, { leftSurroundSide, rightSurroundSide, left, right, leftSurround, rightSurround } },
70 List { kAudioChannelLayoutTag_DTS_6_1_A, { leftSurroundSide, rightSurroundSide, left, right, leftSurround, rightSurround, LFE } },
71 List { kAudioChannelLayoutTag_AudioUnit_7_0, { left, right, leftSurroundSide, rightSurroundSide, centre, leftSurroundRear, rightSurroundRear } },
72 List { kAudioChannelLayoutTag_AudioUnit_7_0_Front, { left, right, leftSurround, rightSurround, centre, leftCentre, rightCentre } },
73 List { kAudioChannelLayoutTag_MPEG_7_1_C, { left, right, centre, LFE, leftSurroundSide, rightSurroundSide, leftSurroundRear, rightSurroundRear } },
74 List { kAudioChannelLayoutTag_MPEG_7_1_A, { left, right, centre, LFE, leftSurround, rightSurround, leftCentre, rightCentre } },
75 List { kAudioChannelLayoutTag_Ambisonic_B_Format, { ambisonicW, ambisonicX, ambisonicY, ambisonicZ } },
76 List { kAudioChannelLayoutTag_Quadraphonic, { left, right, leftSurround, rightSurround } },
77 List { kAudioChannelLayoutTag_Pentagonal, { left, right, leftSurroundRear, rightSurroundRear, centre } },
78 List { kAudioChannelLayoutTag_Hexagonal, { left, right, leftSurroundRear, rightSurroundRear, centre, centreSurround } },
79 List { kAudioChannelLayoutTag_Octagonal, { left, right, leftSurround, rightSurround, centre, centreSurround, wideLeft, wideRight } },
81 #if defined (MAC_OS_VERSION_11_0)
82 List { kAudioChannelLayoutTag_Atmos_5_1_4, { left, right, centre, LFE, leftSurround, rightSurround, topFrontLeft, topFrontRight, topRearLeft, topRearRight } },
83 List { kAudioChannelLayoutTag_Atmos_7_1_2, { left, right, centre, LFE, leftSurroundSide, rightSurroundSide, leftSurroundRear, rightSurroundRear, topSideLeft, topSideRight } },
86 #if defined (MAC_OS_X_VERSION_10_15)
87 List { kAudioChannelLayoutTag_Atmos_5_1_2, { left, right, centre, LFE, leftSurround, rightSurround, topSideLeft, topSideRight } },
88 List { kAudioChannelLayoutTag_Atmos_7_1_4, { left, right, centre, LFE, leftSurroundSide, rightSurroundSide, leftSurroundRear, rightSurroundRear, topFrontLeft, topFrontRight, topRearLeft, topRearRight } },
89 List { kAudioChannelLayoutTag_Atmos_9_1_6, { left, right, centre, LFE, leftSurroundSide, rightSurroundSide, leftSurroundRear, rightSurroundRear, wideLeft, wideRight, topFrontLeft, topFrontRight, topSideLeft, topSideRight, topRearLeft, topRearRight } },
93 List { kAudioChannelLayoutTag_StereoHeadphones, { left, right } },
94 List { kAudioChannelLayoutTag_MatrixStereo, { left, right } },
95 List { kAudioChannelLayoutTag_MidSide, { centre, discreteChannel0 } },
96 List { kAudioChannelLayoutTag_XY, { ambisonicX, ambisonicY } },
97 List { kAudioChannelLayoutTag_Binaural, { left, right } },
98 List { kAudioChannelLayoutTag_Cube, { left, right, leftSurround, rightSurround, topFrontLeft, topFrontRight, topRearLeft, topRearRight } },
99 List { kAudioChannelLayoutTag_MPEG_3_0_B, { centre, left, right } },
100 List { kAudioChannelLayoutTag_MPEG_4_0_B, { centre, left, right, centreSurround } },
101 List { kAudioChannelLayoutTag_MPEG_5_0_B, { left, right, leftSurround, rightSurround, centre } },
102 List { kAudioChannelLayoutTag_MPEG_5_0_C, { left, centre, right, leftSurround, rightSurround } },
103 List { kAudioChannelLayoutTag_MPEG_5_0_D, { centre, left, right, leftSurround, rightSurround } },
104 List { kAudioChannelLayoutTag_MPEG_5_1_B, { left, right, leftSurround, rightSurround, centre, LFE } },
105 List { kAudioChannelLayoutTag_MPEG_5_1_C, { left, centre, right, leftSurround, rightSurround, LFE } },
106 List { kAudioChannelLayoutTag_MPEG_5_1_D, { centre, left, right, leftSurround, rightSurround, LFE } },
107 List { kAudioChannelLayoutTag_MPEG_7_1_B, { centre, leftCentre, rightCentre, left, right, leftSurround, rightSurround, LFE } },
108 List { kAudioChannelLayoutTag_Emagic_Default_7_1, { left, right, leftSurround, rightSurround, centre, LFE, leftCentre, rightCentre } },
109 List { kAudioChannelLayoutTag_SMPTE_DTV, { left, right, centre, LFE, leftSurround, rightSurround, discreteChannel0 , (ChannelType) (discreteChannel0 + 1) } },
110 List { kAudioChannelLayoutTag_ITU_2_2, { left, right, leftSurround, rightSurround } },
111 List { kAudioChannelLayoutTag_DVD_4, { left, right, LFE } },
112 List { kAudioChannelLayoutTag_DVD_5, { left, right, LFE, centreSurround } },
113 List { kAudioChannelLayoutTag_DVD_6, { left, right, LFE, leftSurround, rightSurround } },
114 List { kAudioChannelLayoutTag_DVD_10, { left, right, centre, LFE } },
115 List { kAudioChannelLayoutTag_DVD_11, { left, right, centre, LFE, centreSurround } },
116 List { kAudioChannelLayoutTag_DVD_18, { left, right, leftSurround, rightSurround, LFE } },
117 List { kAudioChannelLayoutTag_AAC_6_0, { centre, left, right, leftSurround, rightSurround, centreSurround } },
118 List { kAudioChannelLayoutTag_AAC_6_1, { centre, left, right, leftSurround, rightSurround, centreSurround, LFE } },
119 List { kAudioChannelLayoutTag_AAC_7_0, { centre, left, right, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear } },
120 List { kAudioChannelLayoutTag_AAC_7_1_B, { centre, left, right, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, LFE } },
121 List { kAudioChannelLayoutTag_AAC_7_1_C, { centre, left, right, leftSurround, rightSurround, LFE, topFrontLeft, topFrontRight } },
122 List { kAudioChannelLayoutTag_AAC_Octagonal, { centre, left, right, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, centreSurround } },
123 List { kAudioChannelLayoutTag_TMH_10_2_std, { left, right, centre, topFrontCentre, leftSurroundSide, rightSurroundSide, leftSurround, rightSurround, topFrontLeft, topFrontRight, wideLeft, wideRight, topRearCentre, centreSurround, LFE, LFE2 } },
124 List { kAudioChannelLayoutTag_AC3_1_0_1, { centre, LFE } },
125 List { kAudioChannelLayoutTag_AC3_3_0, { left, centre, right } },
126 List { kAudioChannelLayoutTag_AC3_3_1, { left, centre, right, centreSurround } },
127 List { kAudioChannelLayoutTag_AC3_3_0_1, { left, centre, right, LFE } },
128 List { kAudioChannelLayoutTag_AC3_2_1_1, { left, right, centreSurround, LFE } },
129 List { kAudioChannelLayoutTag_AC3_3_1_1, { left, centre, right, centreSurround, LFE } },
130 List { kAudioChannelLayoutTag_EAC_6_0_A, { left, centre, right, leftSurround, rightSurround, centreSurround } },
131 List { kAudioChannelLayoutTag_EAC_7_0_A, { left, centre, right, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear } },
132 List { kAudioChannelLayoutTag_EAC3_6_1_A, { left, centre, right, leftSurround, rightSurround, LFE, centreSurround } },
133 List { kAudioChannelLayoutTag_EAC3_6_1_B, { left, centre, right, leftSurround, rightSurround, LFE, centreSurround } },
134 List { kAudioChannelLayoutTag_EAC3_6_1_C, { left, centre, right, leftSurround, rightSurround, LFE, topFrontCentre } },
135 List { kAudioChannelLayoutTag_EAC3_7_1_A, { left, centre, right, leftSurround, rightSurround, LFE, leftSurroundRear, rightSurroundRear } },
136 List { kAudioChannelLayoutTag_EAC3_7_1_B, { left, centre, right, leftSurround, rightSurround, LFE, leftCentre, rightCentre } },
137 List { kAudioChannelLayoutTag_EAC3_7_1_C, { left, centre, right, leftSurround, rightSurround, LFE, leftSurroundSide, rightSurroundSide } },
138 List { kAudioChannelLayoutTag_EAC3_7_1_D, { left, centre, right, leftSurround, rightSurround, LFE, wideLeft, wideRight } },
139 List { kAudioChannelLayoutTag_EAC3_7_1_E, { left, centre, right, leftSurround, rightSurround, LFE, topFrontLeft, topFrontRight } },
140 List { kAudioChannelLayoutTag_EAC3_7_1_F, { left, centre, right, leftSurround, rightSurround, LFE, centreSurround, topMiddle } },
141 List { kAudioChannelLayoutTag_EAC3_7_1_G, { left, centre, right, leftSurround, rightSurround, LFE, centreSurround, topFrontCentre } },
142 List { kAudioChannelLayoutTag_EAC3_7_1_H, { left, centre, right, leftSurround, rightSurround, LFE, centreSurround, topFrontCentre } },
143 List { kAudioChannelLayoutTag_DTS_3_1, { centre, left, right, LFE } },
144 List { kAudioChannelLayoutTag_DTS_4_1, { centre, left, right, centreSurround, LFE } },
145 List { kAudioChannelLayoutTag_DTS_6_0_B, { centre, left, right, leftSurroundRear, rightSurroundRear, centreSurround } },
146 List { kAudioChannelLayoutTag_DTS_6_0_C, { centre, centreSurround, left, right, leftSurroundRear, rightSurroundRear } },
147 List { kAudioChannelLayoutTag_DTS_6_1_B, { centre, left, right, leftSurroundRear, rightSurroundRear, centreSurround, LFE } },
148 List { kAudioChannelLayoutTag_DTS_6_1_C, { centre, centreSurround, left, right, leftSurroundRear, rightSurroundRear, LFE } },
149 List { kAudioChannelLayoutTag_DTS_6_1_D, { centre, left, right, leftSurround, rightSurround, LFE, centreSurround } },
150 List { kAudioChannelLayoutTag_DTS_7_0, { leftCentre, centre, rightCentre, left, right, leftSurround, rightSurround } },
151 List { kAudioChannelLayoutTag_DTS_7_1, { leftCentre, centre, rightCentre, left, right, leftSurround, rightSurround, LFE } },
152 List { kAudioChannelLayoutTag_DTS_8_0_A, { leftCentre, rightCentre, left, right, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear } },
153 List { kAudioChannelLayoutTag_DTS_8_0_B, { leftCentre, centre, rightCentre, left, right, leftSurround, centreSurround, rightSurround } },
154 List { kAudioChannelLayoutTag_DTS_8_1_A, { leftCentre, rightCentre, left, right, leftSurround, rightSurround, leftSurroundRear, rightSurroundRear, LFE } },
155 List { kAudioChannelLayoutTag_DTS_8_1_B, { leftCentre, centre, rightCentre, left, right, leftSurround, centreSurround, rightSurround, LFE } });
163 coreAudioHOASN3DLayoutTag = (190U<<16) | 0
171 static AudioChannelSet fromCoreAudio (
const AudioChannelLayout& layout)
180 static AudioChannelSet fromCoreAudio (AudioChannelLayoutTag layoutTag)
189 static AudioChannelLayoutTag toCoreAudio (
const AudioChannelSet& set)
191 if (set.getAmbisonicOrder() >= 0)
192 return coreAudioHOASN3DLayoutTag |
static_cast<unsigned> (set.size());
194 for (
const auto& item : SpeakerLayoutTable::get())
196 AudioChannelSet caSet;
198 for (
int i = 0; i < numElementsInArray (item.channelTypes)
200 caSet.addChannel (item.channelTypes[i]);
206 return kAudioChannelLayoutTag_DiscreteInOrder |
static_cast<AudioChannelLayoutTag
> (set.size());
209 static const Array<AudioChannelLayoutTag>& getKnownCoreAudioTags()
211 static Array<AudioChannelLayoutTag> tags (createKnownCoreAudioTags());
217 static Array<AudioChannelSet::ChannelType> getCoreAudioLayoutChannels (
const AudioChannelLayout& layout)
219 switch (layout.mChannelLayoutTag & 0xffff0000)
221 case kAudioChannelLayoutTag_UseChannelBitmap:
223 case kAudioChannelLayoutTag_UseChannelDescriptions:
225 Array<AudioChannelSet::ChannelType> channels;
227 for (UInt32 i = 0; i < layout.mNumberChannelDescriptions; ++i)
228 channels.addIfNotAlreadyThere (getChannelTypeFromAudioChannelLabel (layout.mChannelDescriptions[i].mChannelLabel));
232 for (
int j = 0; channels.size() <
static_cast<int> (layout.mNumberChannelDescriptions); ++j)
237 case kAudioChannelLayoutTag_DiscreteInOrder:
243 return getSpeakerLayoutForCoreAudioTag (layout.mChannelLayoutTag);
246 static Array<AudioChannelSet::ChannelType> getSpeakerLayoutForCoreAudioTag (AudioChannelLayoutTag tag)
250 jassert (tag != kAudioChannelLayoutTag_UseChannelBitmap && tag != kAudioChannelLayoutTag_UseChannelDescriptions);
252 Array<AudioChannelSet::ChannelType> speakers;
254 for (
const auto& item : SpeakerLayoutTable::get())
258 for (
int i = 0; i < numElementsInArray (item.channelTypes)
260 speakers.add (item.channelTypes[i]);
266 const auto numChannels = tag & 0xffff;
268 if (tag >= coreAudioHOASN3DLayoutTag && tag <= (coreAudioHOASN3DLayoutTag | 0xffff))
272 if (ambisonicOrder != -1)
276 for (UInt32 i = 0; i < numChannels; ++i)
283 static Array<AudioChannelLayoutTag> createKnownCoreAudioTags()
285 Array<AudioChannelLayoutTag> tags;
287 for (
const auto& item : SpeakerLayoutTable::get())
288 tags.addIfNotAlreadyThere (item.tag);
290 for (
unsigned order = 0; order <= 5; ++order)
291 tags.addIfNotAlreadyThere (coreAudioHOASN3DLayoutTag | ((order + 1) * (order + 1)));
299 if (label >= kAudioChannelLabel_Discrete_0 && label <= kAudioChannelLabel_Discrete_65535)
301 const unsigned int discreteChannelNum = label - kAudioChannelLabel_Discrete_0;
307 case kAudioChannelLabel_Center:
309 case kAudioChannelLabel_Left:
311 case kAudioChannelLabel_Right:
static int getAmbisonicOrderForNumChannels(int numChannels, int maxOrderToCheck=7)
static AudioChannelSet JUCE_CALLTYPE channelSetWithChannels(const Array< ChannelType > &)
static AudioChannelSet JUCE_CALLTYPE ambisonic(int order=1)
static AudioChannelSet JUCE_CALLTYPE discreteChannels(int numChannels)
static AudioChannelSet JUCE_CALLTYPE fromWaveChannelMask(int32 dwChannelMask)