From e0466766d7f9e3017c3bb8fc39a132ee05a357d6 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 25 Mar 2016 23:25:13 -0700 Subject: Include any first-order scaling in the FOAOut coefficients --- Alc/ALc.c | 2 -- Alc/ALu.c | 14 ++------------ Alc/effects/compressor.c | 10 ++++------ Alc/effects/equalizer.c | 7 +++---- Alc/effects/modulator.c | 11 +++++------ Alc/panning.c | 47 ++++++++++++++++++++++++++++++++--------------- OpenAL32/Include/alMain.h | 2 -- 7 files changed, 46 insertions(+), 47 deletions(-) diff --git a/Alc/ALc.c b/Alc/ALc.c index e6c37546..6389270c 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -2173,8 +2173,6 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) { device->FOAOut.Buffer = device->Dry.Buffer; device->FOAOut.NumChannels = device->Dry.NumChannels; - memcpy(device->FOAOut.AmbiCoeffs, device->Dry.AmbiCoeffs, - sizeof(device->FOAOut.AmbiCoeffs)); } SetMixerFPUMode(&oldMode); diff --git a/Alc/ALu.c b/Alc/ALu.c index b5791f53..c83efce8 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -507,10 +507,8 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A aluCrossproduct(N, V, U); aluNormalize(U); - /* Build a rotate + conversion matrix (B-Format -> N3D), and include - * scaling for first-order content on second- or third-order output. - */ - scale = Device->Dry.AmbiScale * 1.732050808f; + /* Build a rotate + conversion matrix (B-Format -> N3D). */ + scale = 1.732050808f; aluMatrixfSet(&matrix, 1.414213562f, 0.0f, 0.0f, 0.0f, 0.0f, -N[0]*scale, N[1]*scale, -N[2]*scale, @@ -524,14 +522,6 @@ ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const A ComputeFirstOrderGains(Device->FOAOut.AmbiCoeffs, Device->FOAOut.NumChannels, matrix.m[c], DryGain, voice->Direct.Gains[c].Target); - /* Rebuild the matrix, without the second- or third-order output - * scaling (effects take first-order content, and will do the scaling - * themselves when mixing to the output). - */ - scale = 1.732050808f; - aluMatrixfSetRow(&matrix, 1, 0.0f, -N[0]*scale, N[1]*scale, -N[2]*scale); - aluMatrixfSetRow(&matrix, 2, 0.0f, U[0]*scale, -U[1]*scale, U[2]*scale); - aluMatrixfSetRow(&matrix, 3, 0.0f, -V[0]*scale, V[1]*scale, -V[2]*scale); for(i = 0;i < NumSends;i++) { if(!SendSlots[i]) diff --git a/Alc/effects/compressor.c b/Alc/effects/compressor.c index 6358f672..4e1d55f1 100644 --- a/Alc/effects/compressor.c +++ b/Alc/effects/compressor.c @@ -58,17 +58,15 @@ static ALboolean ALcompressorState_deviceUpdate(ALcompressorState *state, ALCdev static ALvoid ALcompressorState_update(ALcompressorState *state, const ALCdevice *device, const ALeffectslot *slot) { aluMatrixf matrix; - ALfloat scale; ALuint i; state->Enabled = slot->EffectProps.Compressor.OnOff; - scale = device->Dry.AmbiScale; aluMatrixfSet(&matrix, - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, scale, 0.0f, 0.0f, - 0.0f, 0.0f, scale, 0.0f, - 0.0f, 0.0f, 0.0f, scale + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f ); STATIC_CAST(ALeffectState,state)->OutBuffer = device->FOAOut.Buffer; diff --git a/Alc/effects/equalizer.c b/Alc/effects/equalizer.c index ffc9830f..f3383bd2 100644 --- a/Alc/effects/equalizer.c +++ b/Alc/effects/equalizer.c @@ -103,12 +103,11 @@ static ALvoid ALequalizerState_update(ALequalizerState *state, const ALCdevice * aluMatrixf matrix; ALuint i; - gain = device->Dry.AmbiScale; aluMatrixfSet(&matrix, 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, gain, 0.0f, 0.0f, - 0.0f, 0.0f, gain, 0.0f, - 0.0f, 0.0f, 0.0f, gain + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f ); STATIC_CAST(ALeffectState,state)->OutBuffer = device->FOAOut.Buffer; diff --git a/Alc/effects/modulator.c b/Alc/effects/modulator.c index c283d4b0..03e0d458 100644 --- a/Alc/effects/modulator.c +++ b/Alc/effects/modulator.c @@ -93,8 +93,8 @@ static ALboolean ALmodulatorState_deviceUpdate(ALmodulatorState *UNUSED(state), static ALvoid ALmodulatorState_update(ALmodulatorState *state, const ALCdevice *Device, const ALeffectslot *Slot) { - ALfloat scale, cw, a; aluMatrixf matrix; + ALfloat cw, a; ALuint i; if(Slot->EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SINUSOID) @@ -122,12 +122,11 @@ static ALvoid ALmodulatorState_update(ALmodulatorState *state, const ALCdevice * state->Filter[i].process = ALfilterState_processC; } - scale = Device->Dry.AmbiScale; aluMatrixfSet(&matrix, - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, scale, 0.0f, 0.0f, - 0.0f, 0.0f, scale, 0.0f, - 0.0f, 0.0f, 0.0f, scale + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f ); STATIC_CAST(ALeffectState,state)->OutBuffer = Device->FOAOut.Buffer; diff --git a/Alc/panning.c b/Alc/panning.c index 676896d8..7fb62c5b 100644 --- a/Alc/panning.c +++ b/Alc/panning.c @@ -388,7 +388,7 @@ static bool LoadChannelSetup(ALCdevice *device) ALfloat ambiscale = 1.0f; const char *fname; AmbDecConf conf; - size_t i; + ALuint i, j; layout = GetChannelLayoutName(device->FmtChans); if(!layout) return false; @@ -429,8 +429,8 @@ static bool LoadChannelSetup(ALCdevice *device) for(i = 0;i < conf.NumSpeakers;i++) { ALuint chan = speakermap[i]; - ALuint j, k = 0; ALfloat gain; + ALuint k = 0; for(j = 0;j < MAX_AMBI_COEFFS;j++) chanmap[i].Config[j] = 0.0f; @@ -449,7 +449,14 @@ static bool LoadChannelSetup(ALCdevice *device) SetChannelMap(device->Dry.ChannelName, device->Dry.AmbiCoeffs, chanmap, conf.NumSpeakers, &device->Dry.NumChannels, AL_FALSE); - device->Dry.AmbiScale = ambiscale; + + memset(device->FOAOut.AmbiCoeffs, 0, sizeof(device->FOAOut.AmbiCoeffs)); + for(i = 0;i < device->Dry.NumChannels;i++) + { + device->FOAOut.AmbiCoeffs[i][0] = device->Dry.AmbiCoeffs[i][0]; + for(j = 1;j < 4;j++) + device->FOAOut.AmbiCoeffs[i][j] = device->Dry.AmbiCoeffs[i][j] * ambiscale; + } ambdec_deinit(&conf); return true; @@ -522,11 +529,10 @@ ALvoid aluInitPanning(ALCdevice *device) { Aux3, { 0.0f, 0.0f, 0.0f, 1.0f } }, }; const ChannelMap *chanmap = NULL; - ALfloat ambiscale = 1.0f; + ALfloat ambiscale; size_t count = 0; - ALuint i; + ALuint i, j; - device->Dry.AmbiScale = 1.0f; memset(device->Dry.AmbiCoeffs, 0, sizeof(device->Dry.AmbiCoeffs)); device->Dry.NumChannels = 0; @@ -549,7 +555,6 @@ ALvoid aluInitPanning(ALCdevice *device) count = COUNTOF(Cube8Cfg); chanmap = Cube8Cfg; - ambiscale = FIRST_ORDER_SCALE; for(i = 0;i < count;i++) device->Dry.ChannelName[i] = chanmap[i].ChanName; @@ -557,7 +562,9 @@ ALvoid aluInitPanning(ALCdevice *device) device->Dry.ChannelName[i] = InvalidChannel; SetChannelMap(device->Dry.ChannelName, device->Dry.AmbiCoeffs, chanmap, count, &device->Dry.NumChannels, AL_TRUE); - device->Dry.AmbiScale = ambiscale; + + memcpy(device->FOAOut.AmbiCoeffs, device->Dry.AmbiCoeffs, + sizeof(device->FOAOut.AmbiCoeffs)); for(i = 0;i < device->Dry.NumChannels;i++) { @@ -571,7 +578,6 @@ ALvoid aluInitPanning(ALCdevice *device) { count = COUNTOF(BFormat2D); chanmap = BFormat2D; - ambiscale = FIRST_ORDER_SCALE; for(i = 0;i < count;i++) device->Dry.ChannelName[i] = chanmap[i].ChanName; @@ -579,7 +585,9 @@ ALvoid aluInitPanning(ALCdevice *device) device->Dry.ChannelName[i] = InvalidChannel; SetChannelMap(device->Dry.ChannelName, device->Dry.AmbiCoeffs, chanmap, count, &device->Dry.NumChannels, AL_TRUE); - device->Dry.AmbiScale = ambiscale; + + memcpy(device->FOAOut.AmbiCoeffs, device->Dry.AmbiCoeffs, + sizeof(device->FOAOut.AmbiCoeffs)); return; } @@ -647,7 +655,6 @@ ALvoid aluInitPanning(ALCdevice *device) count = (conf.ChanMask > 0xf) ? COUNTOF(Ambi2D) : 3; chanmap = Ambi2D; } - ambiscale = 1.0f; for(i = 0;i < count;i++) device->Dry.ChannelName[i] = chanmap[i].ChanName; @@ -655,7 +662,6 @@ ALvoid aluInitPanning(ALCdevice *device) device->Dry.ChannelName[i] = InvalidChannel; SetChannelMap(device->Dry.ChannelName, device->Dry.AmbiCoeffs, chanmap, count, &device->Dry.NumChannels, AL_FALSE); - device->Dry.AmbiScale = ambiscale; TRACE("Enabling %s-band %s-order ambisonic decoder\n", (conf.FreqBands == 1) ? "single" : "dual", @@ -664,7 +670,10 @@ ALvoid aluInitPanning(ALCdevice *device) bformatdec_reset(device->AmbiDecoder, &conf, count, device->Frequency, speakermap); ambdec_deinit(&conf); - if(bformatdec_getOrder(device->AmbiDecoder) >= 2) + if(bformatdec_getOrder(device->AmbiDecoder) < 2) + memcpy(device->FOAOut.AmbiCoeffs, device->Dry.AmbiCoeffs, + sizeof(device->FOAOut.AmbiCoeffs)); + else { memset(device->FOAOut.AmbiCoeffs, 0, sizeof(device->FOAOut.AmbiCoeffs)); device->FOAOut.AmbiCoeffs[0][0] = 1.0f; @@ -687,6 +696,7 @@ ALvoid aluInitPanning(ALCdevice *device) if(LoadChannelSetup(device)) return; + ambiscale = 1.0f; switch(device->FmtChans) { case DevFmtMono: @@ -734,13 +744,20 @@ ALvoid aluInitPanning(ALCdevice *device) case DevFmtBFormat3D: count = COUNTOF(BFormat3D); chanmap = BFormat3D; - ambiscale = 1.0f; + ambiscale = FIRST_ORDER_SCALE; break; } SetChannelMap(device->Dry.ChannelName, device->Dry.AmbiCoeffs, chanmap, count, &device->Dry.NumChannels, AL_TRUE); - device->Dry.AmbiScale = ambiscale; + + memset(device->FOAOut.AmbiCoeffs, 0, sizeof(device->FOAOut.AmbiCoeffs)); + for(i = 0;i < device->Dry.NumChannels;i++) + { + device->FOAOut.AmbiCoeffs[i][0] = device->Dry.AmbiCoeffs[i][0]; + for(j = 1;j < 4;j++) + device->FOAOut.AmbiCoeffs[i][j] = device->Dry.AmbiCoeffs[i][j] * ambiscale; + } } void aluInitEffectPanning(ALeffectslot *slot) diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 71620c3f..4c737f02 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -504,8 +504,6 @@ struct ALCdevice_struct enum Channel ChannelName[MAX_OUTPUT_CHANNELS]; /* Ambisonic coefficients for mixing to the dry buffer. */ ChannelConfig AmbiCoeffs[MAX_OUTPUT_CHANNELS]; - /* Scale for first-order XYZ inputs using AmbiCoeffs. */ - ALfloat AmbiScale; /* Dry buffer will be aliased by the virtual or real output. */ ALfloat (*Buffer)[BUFFERSIZE]; -- cgit v1.2.3