58 { QAudioFormat::ChannelConfigSurround5Dot0,
59 {{ decoderMatrix_5dot0_1_lf, decoderMatrix_5dot0_2_lf, decoderMatrix_5dot0_3_lf }},
60 {{ decoderMatrix_5dot0_1_hf, decoderMatrix_5dot0_2_hf, decoderMatrix_5dot0_3_hf }},
62 { QAudioFormat::ChannelConfigSurround5Dot1,
63 {{ decoderMatrix_5dot1_1_lf, decoderMatrix_5dot1_2_lf, decoderMatrix_5dot1_3_lf }},
64 {{ decoderMatrix_5dot1_1_hf, decoderMatrix_5dot1_2_hf, decoderMatrix_5dot1_3_hf }},
66 { QAudioFormat::ChannelConfigSurround7Dot0,
67 {{ decoderMatrix_7dot0_1_lf, decoderMatrix_7dot0_2_lf, decoderMatrix_7dot0_3_lf }},
68 {{ decoderMatrix_7dot0_1_hf, decoderMatrix_7dot0_2_hf, decoderMatrix_7dot0_3_hf }},
70 { QAudioFormat::ChannelConfigSurround7Dot1,
71 {{ decoderMatrix_7dot1_1_lf, decoderMatrix_7dot1_2_lf, decoderMatrix_7dot1_3_lf }},
72 {{ decoderMatrix_7dot1_1_hf, decoderMatrix_7dot1_2_hf, decoderMatrix_7dot1_3_hf }},
163 int numberOfOutputChannels,
164 QAudioFormat::ChannelConfig channelCfg)
166 order(ambisonicOrder),
167 inputChannels(inputChannelsForAmbisonicOrder(ambisonicOrder)),
168 outputChannels(numberOfOutputChannels)
170 if (channelConfig == QAudioFormat::ChannelConfigMono ||
171 channelConfig == QAudioFormat::ChannelConfigStereo ||
172 channelConfig == QAudioFormat::ChannelConfig2Dot1 ||
173 channelConfig == QAudioFormat::ChannelConfig3Dot0 ||
174 channelConfig == QAudioFormat::ChannelConfig3Dot1) {
184 simpleDecoderFactors = std::make_unique<
float[]>(4 * outputChannels);
185 m_reverbFactorsOwned = std::make_unique<
float[]>(2 * outputChannels);
186 reverbFactors = m_reverbFactorsOwned.get();
187 float *f = simpleDecoderFactors.get();
188 float *r = m_reverbFactorsOwned.get();
189 if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::FrontLeft)) {
190 f[0] = 0.5f; f[1] = 0.5f; f[2] = 0.; f[3] = 0.f;
192 r[0] = 1.; r[1] = 0.;
195 if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::FrontRight)) {
196 f[0] = 0.5f; f[1] = -0.5f; f[2] = 0.; f[3] = 0.f;
198 r[0] = 0.; r[1] = 1.;
201 if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::FrontCenter)) {
202 f[0] = 0.5f; f[1] = -0.f; f[2] = 0.; f[3] = 0.5f;
204 r[0] = .5; r[1] = .5;
207 if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::LFE)) {
208 f[0] = 0.5f; f[1] = -0.f; f[2] = 0.; f[3] = 0.0f;
210 r[0] = 0.; r[1] = 0.;
215 Q_ASSERT((f - simpleDecoderFactors.get()) == 4 * outputChannels);
216 Q_ASSERT((r - reverbFactors) == 2*outputChannels);
221 for (
const auto &d : decoderMap) {
222 if (d.config == channelConfig) {
224 reverbFactors = decoderData->reverb;
231 filters = std::make_unique<QAmbisonicDecoderFilter[]>(inputChannels);
232 for (
int i = 0; i < inputChannels; ++i)
233 filters[i].configure(sampleRate);
240 const int nSamples =
int(output.size()) / outputChannels;
241 std::fill(output.begin(), output.end(), 0.f);
242 float *o = output.data();
244 if (simpleDecoderFactors) {
245 for (
int i = 0; i < nSamples; ++i) {
246 for (
int j = 0; j < 4; ++j) {
247 for (
int k = 0; k < outputChannels; ++k)
248 o[k] += simpleDecoderFactors[k*4 + j]*input[j][i];
255 const float *matrix_hi = decoderData->hf[order - 1];
256 const float *matrix_lo = decoderData->lf[order - 1];
257 for (
int i = 0; i < nSamples; ++i) {
259 for (
int j = 0; j < inputChannels; ++j)
260 buf[j] = filters[j].next(input[j][i]);
261 for (
int j = 0; j < inputChannels; ++j) {
262 for (
int k = 0; k < outputChannels; ++k)
263 o[k] += matrix_lo[k*inputChannels + j]*buf[j].lf + matrix_hi[k*inputChannels + j]*buf[j].hf;
270 QSpan<
const float *, 2> reverb, QSpan<
float> output)
272 Q_ASSERT(outputChannels > 0);
273 Q_ASSERT(
int(output.size()) % outputChannels == 0);
274 const int nSamples =
int(output.size()) / outputChannels;
276 std::fill(output.begin(), output.end(), 0.f);
277 float *o = output.data();
279 if (simpleDecoderFactors) {
280 for (
int i = 0; i < nSamples; ++i) {
281 for (
int k = 0; k < outputChannels; ++k) {
282 for (
int j = 0; j < 4; ++j)
283 o[k] += simpleDecoderFactors[k*4 + j]*input[j][i];
286 for (
int k = 0; k < outputChannels; ++k)
287 o[k] += reverb[0][i] * reverbFactors[2 * k]
288 + reverb[1][i] * reverbFactors[2 * k + 1];
298 const float *matrix_hi = decoderData->hf[order - 1];
299 const float *matrix_lo = decoderData->lf[order - 1];
300 for (
int i = 0; i < nSamples; ++i) {
302 for (
int j = 0; j < inputChannels; ++j)
303 buf[j] = filters[j].next(input[j][i]);
304 for (
int j = 0; j < inputChannels; ++j) {
305 for (
int k = 0; k < outputChannels; ++k)
306 o[k] += matrix_lo[k*inputChannels + j]*buf[j].lf + matrix_hi[k*inputChannels + j]*buf[j].hf;
309 for (
int k = 0; k < outputChannels; ++k)
310 o[k] += reverb[0][i]*reverbFactors[2*k] + reverb[1][i]*reverbFactors[2*k+1];