From f3ff28fb2ac918eaf08f56f920dd627caf10f987 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 22 Mar 2020 10:20:41 -0700 Subject: [PATCH] Some type cleanup --- alc/effects/fshifter.cpp | 27 ++++++++++---------- alc/effects/pshifter.cpp | 54 +++++++++++++++++++--------------------- 2 files changed, 39 insertions(+), 42 deletions(-) diff --git a/alc/effects/fshifter.cpp b/alc/effects/fshifter.cpp index 2c4575a6..cb62adaa 100644 --- a/alc/effects/fshifter.cpp +++ b/alc/effects/fshifter.cpp @@ -61,20 +61,19 @@ alignas(16) const std::array HannWindow = InitHannWindow(); struct FshifterState final : public EffectState { /* Effect parameters */ - size_t mCount{}; - ALsizei mPhaseStep[2]{}; - ALsizei mPhase[2]{}; - ALdouble mSign[2]{}; + size_t mCount{}; + ALuint mPhaseStep[2]{}; + ALuint mPhase[2]{}; + double mSign[2]{}; - - /*Effects buffers*/ + /* Effects buffers */ double mInFIFO[HIL_SIZE]{}; complex_d mOutFIFO[HIL_STEP]{}; complex_d mOutputAccum[HIL_SIZE]{}; complex_d mAnalytic[HIL_SIZE]{}; complex_d mOutdata[BUFFERSIZE]{}; - alignas(16) ALfloat mBufferOut[BUFFERSIZE]{}; + alignas(16) float mBufferOut[BUFFERSIZE]{}; /* Effect gains for each output channel */ struct { @@ -95,8 +94,8 @@ ALboolean FshifterState::deviceUpdate(const ALCdevice*) /* (Re-)initializing parameters and clear the buffers. */ mCount = FIFO_LATENCY; - std::fill(std::begin(mPhaseStep), std::end(mPhaseStep), 0); - std::fill(std::begin(mPhase), std::end(mPhase), 0); + std::fill(std::begin(mPhaseStep), std::end(mPhaseStep), 0u); + std::fill(std::begin(mPhase), std::end(mPhase), 0u); std::fill(std::begin(mSign), std::end(mSign), 1.0); std::fill(std::begin(mInFIFO), std::end(mInFIFO), 0.0); std::fill(std::begin(mOutFIFO), std::end(mOutFIFO), complex_d{}); @@ -116,8 +115,8 @@ void FshifterState::update(const ALCcontext *context, const ALeffectslot *slot, { const ALCdevice *device{context->mDevice.get()}; - ALfloat step{props->Fshifter.Frequency / static_cast(device->Frequency)}; - mPhaseStep[0] = mPhaseStep[1] = fastf2i(minf(step, 0.5f) * FRACTIONONE); + const float step{props->Fshifter.Frequency / static_cast(device->Frequency)}; + mPhaseStep[0] = mPhaseStep[1] = fastf2u(minf(step, 1.0f) * FRACTIONONE); switch(props->Fshifter.LeftDirection) { @@ -135,7 +134,7 @@ void FshifterState::update(const ALCcontext *context, const ALeffectslot *slot, break; } - switch (props->Fshifter.RightDirection) + switch(props->Fshifter.RightDirection) { case AL_FREQUENCY_SHIFTER_DIRECTION_DOWN: mSign[1] = -1.0; @@ -202,8 +201,8 @@ void FshifterState::process(const size_t samplesToDo, const al::span::Tau())}; diff --git a/alc/effects/pshifter.cpp b/alc/effects/pshifter.cpp index 53b5318b..b547fc84 100644 --- a/alc/effects/pshifter.cpp +++ b/alc/effects/pshifter.cpp @@ -66,13 +66,13 @@ alignas(16) const std::array HannWindow = InitHannWindow(); struct ALphasor { - ALdouble Amplitude; - ALdouble Phase; + double Amplitude; + double Phase; }; struct ALfrequencyDomain { - ALdouble Amplitude; - ALdouble Frequency; + double Amplitude; + double Frequency; }; @@ -92,24 +92,24 @@ inline complex_d polar2rect(const ALphasor &number) struct PshifterState final : public EffectState { /* Effect parameters */ - size_t mCount; - ALuint mPitchShiftI; - ALfloat mPitchShift; - ALfloat mFreqPerBin; + size_t mCount; + ALuint mPitchShiftI; + double mPitchShift; + double mFreqPerBin; /* Effects buffers */ double mInFIFO[STFT_SIZE]; double mOutFIFO[STFT_STEP]; - ALdouble mLastPhase[STFT_HALF_SIZE+1]; - ALdouble mSumPhase[STFT_HALF_SIZE+1]; - ALdouble mOutputAccum[STFT_SIZE]; + double mLastPhase[STFT_HALF_SIZE+1]; + double mSumPhase[STFT_HALF_SIZE+1]; + double mOutputAccum[STFT_SIZE]; complex_d mFFTbuffer[STFT_SIZE]; ALfrequencyDomain mAnalysis_buffer[STFT_HALF_SIZE+1]; ALfrequencyDomain mSyntesis_buffer[STFT_HALF_SIZE+1]; - alignas(16) ALfloat mBufferOut[BUFFERSIZE]; + alignas(16) float mBufferOut[BUFFERSIZE]; /* Effect gains for each output channel */ ALfloat mCurrentGains[MAX_OUTPUT_CHANNELS]; @@ -128,11 +128,11 @@ ALboolean PshifterState::deviceUpdate(const ALCdevice *device) /* (Re-)initializing parameters and clear the buffers. */ mCount = FIFO_LATENCY; mPitchShiftI = FRACTIONONE; - mPitchShift = 1.0f; - mFreqPerBin = static_cast(device->Frequency) / float{STFT_SIZE}; + mPitchShift = 1.0; + mFreqPerBin = device->Frequency / double{STFT_SIZE}; - std::fill(std::begin(mInFIFO), std::end(mInFIFO), 0.0f); - std::fill(std::begin(mOutFIFO), std::end(mOutFIFO), 0.0f); + std::fill(std::begin(mInFIFO), std::end(mInFIFO), 0.0); + std::fill(std::begin(mOutFIFO), std::end(mOutFIFO), 0.0); std::fill(std::begin(mLastPhase), std::end(mLastPhase), 0.0); std::fill(std::begin(mSumPhase), std::end(mSumPhase), 0.0); std::fill(std::begin(mOutputAccum), std::end(mOutputAccum), 0.0); @@ -148,11 +148,10 @@ ALboolean PshifterState::deviceUpdate(const ALCdevice *device) void PshifterState::update(const ALCcontext*, const ALeffectslot *slot, const EffectProps *props, const EffectTarget target) { - const float pitch{std::pow(2.0f, - static_cast(props->Pshifter.CoarseTune*100 + props->Pshifter.FineTune) / 1200.0f - )}; + const int tune{props->Pshifter.CoarseTune*100 + props->Pshifter.FineTune}; + const float pitch{std::pow(2.0f, static_cast(tune) / 1200.0f)}; mPitchShiftI = fastf2u(pitch*FRACTIONONE); - mPitchShift = static_cast(mPitchShiftI) * (1.0f/FRACTIONONE); + mPitchShift = mPitchShiftI * double{1.0/FRACTIONONE}; ALfloat coeffs[MAX_AMBI_CHANNELS]; CalcDirectionCoeffs({0.0f, 0.0f, -1.0f}, 0.0f, coeffs); @@ -167,8 +166,8 @@ void PshifterState::process(const size_t samplesToDo, const al::span::Tau() / OVERSAMP}; - const ALdouble freq_per_bin{mFreqPerBin}; + static constexpr double expected{al::MathDefs::Tau() / OVERSAMP}; + const double freq_per_bin{mFreqPerBin}; for(size_t base{0u};base < samplesToDo;) { @@ -207,7 +206,7 @@ void PshifterState::process(const size_t samplesToDo, const al::span(k)*expected}; /* Map delta phase into +/- Pi interval */ int qpd{double2int(tmp / al::MathDefs::Pi())}; @@ -221,7 +220,7 @@ void PshifterState::process(const size_t samplesToDo, const al::span(k) + tmp) * freq_per_bin; /* Store actual phase[k] for the calculations in the next frame*/ mLastPhase[k] = component.Phase; @@ -249,10 +248,10 @@ void PshifterState::process(const size_t samplesToDo, const al::span