diff options
author | Chris Robinson <[email protected]> | 2018-12-12 04:22:11 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-12-12 04:22:11 -0800 |
commit | 5a283c66eef69f5fd573d55f2411703968355eac (patch) | |
tree | 3bf5420d895ba6fc26f21cd7808a53332a2f2c44 /Alc/effects | |
parent | 19c5c41c704d121b126b3b496278970bdd35c512 (diff) |
Use proper classes for Vector and Matrix types
Diffstat (limited to 'Alc/effects')
-rw-r--r-- | Alc/effects/autowah.cpp | 2 | ||||
-rw-r--r-- | Alc/effects/compressor.cpp | 3 | ||||
-rw-r--r-- | Alc/effects/equalizer.cpp | 2 | ||||
-rw-r--r-- | Alc/effects/modulator.cpp | 2 | ||||
-rw-r--r-- | Alc/effects/reverb.cpp | 82 |
5 files changed, 43 insertions, 48 deletions
diff --git a/Alc/effects/autowah.cpp b/Alc/effects/autowah.cpp index 8e789652..19c247a9 100644 --- a/Alc/effects/autowah.cpp +++ b/Alc/effects/autowah.cpp @@ -122,7 +122,7 @@ void ALautowahState::update(const ALCcontext *context, const ALeffectslot *slot, mOutBuffer = device->FOAOut.Buffer; mOutChannels = device->FOAOut.NumChannels; for(i = 0;i < MAX_EFFECT_CHANNELS;i++) - ComputePanGains(&device->FOAOut, aluMatrixf::Identity.m[i], slot->Params.Gain, + ComputePanGains(&device->FOAOut, alu::Matrix::Identity()[i].data(), slot->Params.Gain, mChans[i].TargetGains); } diff --git a/Alc/effects/compressor.cpp b/Alc/effects/compressor.cpp index c8bdef15..31210264 100644 --- a/Alc/effects/compressor.cpp +++ b/Alc/effects/compressor.cpp @@ -81,7 +81,8 @@ void ALcompressorState::update(const ALCcontext *context, const ALeffectslot *sl mOutBuffer = device->FOAOut.Buffer; mOutChannels = device->FOAOut.NumChannels; for(ALsizei i{0};i < 4;i++) - ComputePanGains(&device->FOAOut, aluMatrixf::Identity.m[i], slot->Params.Gain, mGain[i]); + ComputePanGains(&device->FOAOut, alu::Matrix::Identity()[i].data(), + slot->Params.Gain, mGain[i]); } void ALcompressorState::process(ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels) diff --git a/Alc/effects/equalizer.cpp b/Alc/effects/equalizer.cpp index 85c0882c..2c46c2f3 100644 --- a/Alc/effects/equalizer.cpp +++ b/Alc/effects/equalizer.cpp @@ -155,7 +155,7 @@ void ALequalizerState::update(const ALCcontext *context, const ALeffectslot *slo mOutBuffer = device->FOAOut.Buffer; mOutChannels = device->FOAOut.NumChannels; for(i = 0;i < MAX_EFFECT_CHANNELS;i++) - ComputePanGains(&device->FOAOut, aluMatrixf::Identity.m[i], slot->Params.Gain, + ComputePanGains(&device->FOAOut, alu::Matrix::Identity()[i].data(), slot->Params.Gain, mChans[i].TargetGains); } diff --git a/Alc/effects/modulator.cpp b/Alc/effects/modulator.cpp index 3d41bb65..bf584898 100644 --- a/Alc/effects/modulator.cpp +++ b/Alc/effects/modulator.cpp @@ -134,7 +134,7 @@ void ALmodulatorState::update(const ALCcontext *context, const ALeffectslot *slo mOutBuffer = device->FOAOut.Buffer; mOutChannels = device->FOAOut.NumChannels; for(i = 0;i < MAX_EFFECT_CHANNELS;i++) - ComputePanGains(&device->FOAOut, aluMatrixf::Identity.m[i], slot->Params.Gain, + ComputePanGains(&device->FOAOut, alu::Matrix::Identity()[i].data(), slot->Params.Gain, mChans[i].TargetGains); } diff --git a/Alc/effects/reverb.cpp b/Alc/effects/reverb.cpp index b5e6dd94..70324dad 100644 --- a/Alc/effects/reverb.cpp +++ b/Alc/effects/reverb.cpp @@ -68,20 +68,20 @@ ALfloat ReverbBoost = 1.0f; * tetrahedron, but it's close enough. Should the model be extended to 8-lines * in the future, true opposites can be used. */ -static const aluMatrixf B2A = {{ - { 0.288675134595f, 0.288675134595f, 0.288675134595f, 0.288675134595f }, - { 0.288675134595f, -0.288675134595f, -0.288675134595f, 0.288675134595f }, - { 0.288675134595f, 0.288675134595f, -0.288675134595f, -0.288675134595f }, - { 0.288675134595f, -0.288675134595f, 0.288675134595f, -0.288675134595f } -}}; +static constexpr alu::Matrix B2A{ + 0.288675134595f, 0.288675134595f, 0.288675134595f, 0.288675134595f, + 0.288675134595f, -0.288675134595f, -0.288675134595f, 0.288675134595f, + 0.288675134595f, 0.288675134595f, -0.288675134595f, -0.288675134595f, + 0.288675134595f, -0.288675134595f, 0.288675134595f, -0.288675134595f +}; /* Converts A-Format to B-Format. */ -static const aluMatrixf A2B = {{ - { 0.866025403785f, 0.866025403785f, 0.866025403785f, 0.866025403785f }, - { 0.866025403785f, -0.866025403785f, 0.866025403785f, -0.866025403785f }, - { 0.866025403785f, -0.866025403785f, -0.866025403785f, 0.866025403785f }, - { 0.866025403785f, 0.866025403785f, -0.866025403785f, -0.866025403785f } -}}; +static constexpr alu::Matrix A2B{ + 0.866025403785f, 0.866025403785f, 0.866025403785f, 0.866025403785f, + 0.866025403785f, -0.866025403785f, 0.866025403785f, -0.866025403785f, + 0.866025403785f, -0.866025403785f, -0.866025403785f, 0.866025403785f, + 0.866025403785f, 0.866025403785f, -0.866025403785f, -0.866025403785f +}; static const ALfloat FadeStep = 1.0f / FADE_SAMPLES; @@ -755,12 +755,8 @@ static ALvoid UpdateLateLines(const ALfloat density, const ALfloat diffusion, co * focal strength. This function results in a B-Format transformation matrix * that spatially focuses the signal in the desired direction. */ -static aluMatrixf GetTransformFromVector(const ALfloat *vec) +static alu::Matrix GetTransformFromVector(const ALfloat *vec) { - aluMatrixf focus; - ALfloat norm[3]; - ALfloat mag; - /* Normalize the panning vector according to the N3D scale, which has an * extra sqrt(3) term on the directional components. Converting from OpenAL * to B-Format also requires negating X (ACN 1) and Z (ACN 3). Note however @@ -768,7 +764,8 @@ static aluMatrixf GetTransformFromVector(const ALfloat *vec) * rest of OpenAL which use right-handed. This is fixed by negating Z, * which cancels out with the B-Format Z negation. */ - mag = sqrtf(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]); + ALfloat norm[3]; + ALfloat mag{sqrtf(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2])}; if(mag > 1.0f) { norm[0] = vec[0] / mag * -SQRTF_3; @@ -787,50 +784,47 @@ static aluMatrixf GetTransformFromVector(const ALfloat *vec) norm[2] = vec[2] * SQRTF_3; } - aluMatrixfSet(&focus, + return alu::Matrix{ 1.0f, 0.0f, 0.0f, 0.0f, norm[0], 1.0f-mag, 0.0f, 0.0f, norm[1], 0.0f, 1.0f-mag, 0.0f, norm[2], 0.0f, 0.0f, 1.0f-mag - ); - - return focus; + }; } /* Update the early and late 3D panning gains. */ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *ReflectionsPan, const ALfloat *LateReverbPan, const ALfloat earlyGain, const ALfloat lateGain, ReverbState *State) { - aluMatrixf transform, rot; - ALsizei i; - State->mOutBuffer = Device->FOAOut.Buffer; State->mOutChannels = Device->FOAOut.NumChannels; - /* Note: _res is transposed. */ -#define MATRIX_MULT(_res, _m1, _m2) do { \ - int row, col; \ - for(col = 0;col < 4;col++) \ - { \ - for(row = 0;row < 4;row++) \ - _res.m[col][row] = _m1.m[row][0]*_m2.m[0][col] + _m1.m[row][1]*_m2.m[1][col] + \ - _m1.m[row][2]*_m2.m[2][col] + _m1.m[row][3]*_m2.m[3][col]; \ - } \ -} while(0) + /* Note: ret is transposed. */ + auto MatrixMult = [](const alu::Matrix &m1, const alu::Matrix &m2) noexcept -> alu::Matrix + { + alu::Matrix ret; + for(int col{0};col < 4;col++) + { + for(int row{0};row < 4;row++) + ret[col][row] = m1[row][0]*m2[0][col] + m1[row][1]*m2[1][col] + + m1[row][2]*m2[2][col] + m1[row][3]*m2[3][col]; + } + return ret; + }; + /* Create a matrix that first converts A-Format to B-Format, then * transforms the B-Format signal according to the panning vector. */ - rot = GetTransformFromVector(ReflectionsPan); - MATRIX_MULT(transform, rot, A2B); - for(i = 0;i < MAX_EFFECT_CHANNELS;i++) - ComputePanGains(&Device->FOAOut, transform.m[i], earlyGain, + alu::Matrix rot{GetTransformFromVector(ReflectionsPan)}; + alu::Matrix transform{MatrixMult(rot, A2B)}; + for(ALsizei i{0};i < MAX_EFFECT_CHANNELS;i++) + ComputePanGains(&Device->FOAOut, transform[i].data(), earlyGain, State->mEarly.PanGain[i]); rot = GetTransformFromVector(LateReverbPan); - MATRIX_MULT(transform, rot, A2B); - for(i = 0;i < MAX_EFFECT_CHANNELS;i++) - ComputePanGains(&Device->FOAOut, transform.m[i], lateGain, + transform = MatrixMult(rot, A2B); + for(ALsizei i{0};i < MAX_EFFECT_CHANNELS;i++) + ComputePanGains(&Device->FOAOut, transform[i].data(), lateGain, State->mLate.PanGain[i]); -#undef MATRIX_MULT } void ReverbState::update(const ALCcontext *Context, const ALeffectslot *Slot, const ALeffectProps *props) @@ -1380,7 +1374,7 @@ void ReverbState::process(ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesI for(c = 0;c < NUM_LINES;c++) { std::fill(std::begin(afmt[c]), std::end(afmt[c]), 0.0f); - MixRowSamples(afmt[c], B2A.m[c], + MixRowSamples(afmt[c], B2A[c].data(), SamplesIn, MAX_EFFECT_CHANNELS, base, todo ); } |