55 { QAudioFormat::ChannelConfigSurround5Dot0,
56 { decoderMatrix_5dot0_1_lf, decoderMatrix_5dot0_2_lf, decoderMatrix_5dot0_3_lf },
57 { decoderMatrix_5dot0_1_hf, decoderMatrix_5dot0_2_hf, decoderMatrix_5dot0_3_hf },
59 { QAudioFormat::ChannelConfigSurround5Dot1,
60 { decoderMatrix_5dot1_1_lf, decoderMatrix_5dot1_2_lf, decoderMatrix_5dot1_3_lf },
61 { decoderMatrix_5dot1_1_hf, decoderMatrix_5dot1_2_hf, decoderMatrix_5dot1_3_hf },
63 { QAudioFormat::ChannelConfigSurround7Dot0,
64 { decoderMatrix_7dot0_1_lf, decoderMatrix_7dot0_2_lf, decoderMatrix_7dot0_3_lf },
65 { decoderMatrix_7dot0_1_hf, decoderMatrix_7dot0_2_hf, decoderMatrix_7dot0_3_hf },
67 { QAudioFormat::ChannelConfigSurround7Dot1,
68 { decoderMatrix_7dot1_1_lf, decoderMatrix_7dot1_2_lf, decoderMatrix_7dot1_3_lf },
69 { decoderMatrix_7dot1_1_hf, decoderMatrix_7dot1_2_hf, decoderMatrix_7dot1_3_hf },
139 : order(ambisonicOrder)
141 Q_ASSERT(order > 0 && order <= 3);
142 inputChannels = (order + 1) * (order + 1);
143 outputChannels = format.channelCount();
145 channelConfig = format.channelConfig();
146 if (channelConfig == QAudioFormat::ChannelConfigUnknown)
147 channelConfig = QAudioFormat::defaultChannelConfigForChannelCount(format.channelCount());
149 if (channelConfig == QAudioFormat::ChannelConfigMono ||
150 channelConfig == QAudioFormat::ChannelConfigStereo ||
151 channelConfig == QAudioFormat::ChannelConfig2Dot1 ||
152 channelConfig == QAudioFormat::ChannelConfig3Dot0 ||
153 channelConfig == QAudioFormat::ChannelConfig3Dot1) {
163 simpleDecoderFactors =
new float[4*outputChannels];
164 float *r =
new float[2*outputChannels];
165 float *f = simpleDecoderFactors;
167 if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::FrontLeft)) {
168 f[0] = 0.5f; f[1] = 0.5f; f[2] = 0.; f[3] = 0.f;
170 r[0] = 1.; r[1] = 0.;
173 if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::FrontRight)) {
174 f[0] = 0.5f; f[1] = -0.5f; f[2] = 0.; f[3] = 0.f;
176 r[0] = 0.; r[1] = 1.;
179 if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::FrontCenter)) {
180 f[0] = 0.5f; f[1] = -0.f; f[2] = 0.; f[3] = 0.5f;
182 r[0] = .5; r[1] = .5;
185 if (channelConfig & QAudioFormat::channelConfig(QAudioFormat::LFE)) {
186 f[0] = 0.5f; f[1] = -0.f; f[2] = 0.; f[3] = 0.0f;
188 r[0] = 0.; r[1] = 0.;
193 Q_ASSERT((f - simpleDecoderFactors) == 4*outputChannels);
194 Q_ASSERT((r - reverbFactors) == 2*outputChannels);
199 for (
const auto &d : decoderMap) {
200 if (d.config == channelConfig) {
202 reverbFactors = decoderData->reverb;
213 for (
int i = 0; i < inputChannels; ++i)
231 memset(o, 0, nSamples*outputChannels*
sizeof(
float));
233 if (simpleDecoderFactors) {
234 for (
int i = 0; i < nSamples; ++i) {
235 for (
int j = 0; j < 4; ++j) {
236 for (
int k = 0; k < outputChannels; ++k)
237 o[k] += simpleDecoderFactors[k*4 + j]*input[j][i];
244 const float *matrix_hi = decoderData->hf[order - 1];
245 const float *matrix_lo = decoderData->lf[order - 1];
246 for (
int i = 0; i < nSamples; ++i) {
248 for (
int j = 0; j < inputChannels; ++j)
249 buf[j] = filters[j]
.next(input[j][i]
);
250 for (
int j = 0; j < inputChannels; ++j) {
251 for (
int k = 0; k < outputChannels; ++k)
252 o[k] += matrix_lo[k*inputChannels + j]*buf[j]
.lf + matrix_hi[k*inputChannels + j]*buf[j]
.hf;
266 if (simpleDecoderFactors) {
267 for (
int i = 0; i < nSamples; ++i) {
269 for (
int k = 0; k < outputChannels; ++k) {
270 for (
int j = 0; j < 4; ++j)
271 o[k] += simpleDecoderFactors[k*4 + j]*input[j][i];
274 for (
int k = 0; k < outputChannels; ++k) {
275 o[k] += reverb[0][i]*reverbFactors[2*k] + reverb[1][i]*reverbFactors[2*k+1];
279 for (
int k = 0; k < outputChannels; ++k)
280 output[k] =
static_cast<
short>(o[k]*32768.);
281 output += outputChannels;
289 const float *matrix_hi = decoderData->hf[order - 1];
290 const float *matrix_lo = decoderData->lf[order - 1];
291 for (
int i = 0; i < nSamples; ++i) {
293 for (
int j = 0; j < inputChannels; ++j)
294 buf[j] = filters[j]
.next(input[j][i]
);
296 for (
int j = 0; j < inputChannels; ++j) {
297 for (
int k = 0; k < outputChannels; ++k)
298 o[k] += matrix_lo[k*inputChannels + j]*buf[j]
.lf + matrix_hi[k*inputChannels + j]*buf[j]
.hf;
301 for (
int k = 0; k < outputChannels; ++k) {
302 o[k] += reverb[0][i]*reverbFactors[2*k] + reverb[1][i]*reverbFactors[2*k+1];
305 for (
int k = 0; k < outputChannels; ++k)
306 output[k] =
static_cast<
short>(o[k]*32768.);
307 output += outputChannels;