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)
228 memset(o, 0, nSamples*outputChannels*
sizeof(
float));
230 if (simpleDecoderFactors) {
231 for (
int i = 0; i < nSamples; ++i) {
232 for (
int j = 0; j < 4; ++j) {
233 for (
int k = 0; k < outputChannels; ++k)
234 o[k] += simpleDecoderFactors[k*4 + j]*input[j][i];
241 const float *matrix_hi = decoderData->hf[order - 1];
242 const float *matrix_lo = decoderData->lf[order - 1];
243 for (
int i = 0; i < nSamples; ++i) {
245 for (
int j = 0; j < inputChannels; ++j)
246 buf[j] = filters[j]
.next(input[j][i]
);
247 for (
int j = 0; j < inputChannels; ++j) {
248 for (
int k = 0; k < outputChannels; ++k)
249 o[k] += matrix_lo[k*inputChannels + j]*buf[j]
.lf + matrix_hi[k*inputChannels + j]*buf[j]
.hf;
263 if (simpleDecoderFactors) {
264 for (
int i = 0; i < nSamples; ++i) {
266 for (
int k = 0; k < outputChannels; ++k) {
267 for (
int j = 0; j < 4; ++j)
268 o[k] += simpleDecoderFactors[k*4 + j]*input[j][i];
271 for (
int k = 0; k < outputChannels; ++k) {
272 o[k] += reverb[0][i]*reverbFactors[2*k] + reverb[1][i]*reverbFactors[2*k+1];
276 for (
int k = 0; k < outputChannels; ++k)
277 output[k] =
static_cast<
short>(o[k]*32768.);
278 output += outputChannels;
284 const float *matrix_hi = decoderData->hf[order - 1];
285 const float *matrix_lo = decoderData->lf[order - 1];
286 for (
int i = 0; i < nSamples; ++i) {
288 for (
int j = 0; j < inputChannels; ++j)
289 buf[j] = filters[j]
.next(input[j][i]
);
291 for (
int j = 0; j < inputChannels; ++j) {
292 for (
int k = 0; k < outputChannels; ++k)
293 o[k] += matrix_lo[k*inputChannels + j]*buf[j]
.lf + matrix_hi[k*inputChannels + j]*buf[j]
.hf;
296 for (
int k = 0; k < outputChannels; ++k) {
297 o[k] += reverb[0][i]*reverbFactors[2*k] + reverb[1][i]*reverbFactors[2*k+1];
300 for (
int k = 0; k < outputChannels; ++k)
301 output[k] =
static_cast<
short>(o[k]*32768.);
302 output += outputChannels;