diff options
author | Chris Robinson <[email protected]> | 2020-03-22 10:20:41 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-03-22 10:41:02 -0700 |
commit | f3ff28fb2ac918eaf08f56f920dd627caf10f987 (patch) | |
tree | e482db0b0c1732516b7bc9dbbc424a481400ad98 /alc/effects | |
parent | d30d9a2c9f74f1bbede11c1f7f8b7a6aada2bf7b (diff) |
Some type cleanup
Diffstat (limited to 'alc/effects')
-rw-r--r-- | alc/effects/fshifter.cpp | 27 | ||||
-rw-r--r-- | 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<double,HIL_SIZE> 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<ALfloat>(device->Frequency)}; - mPhaseStep[0] = mPhaseStep[1] = fastf2i(minf(step, 0.5f) * FRACTIONONE); + const float step{props->Fshifter.Frequency / static_cast<float>(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<const Float ALfloat *RESTRICT BufferOut{mBufferOut}; for(ALsizei c{0};c < 2;++c) { - const int phase_step{mPhaseStep[c]}; - int phase_idx{mPhase[c]}; + const ALuint phase_step{mPhaseStep[c]}; + ALuint phase_idx{mPhase[c]}; for(size_t k{0};k < samplesToDo;++k) { const double phase{phase_idx * ((1.0 / FRACTIONONE) * al::MathDefs<double>::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<double,STFT_SIZE> 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<float>(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<ALfloat>(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<float>(tune) / 1200.0f)}; mPitchShiftI = fastf2u(pitch*FRACTIONONE); - mPitchShift = static_cast<float>(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<const Float * http://blogs.zynaptiq.com/bernsee/pitch-shifting-using-the-ft/ */ - static constexpr ALdouble expected{al::MathDefs<double>::Tau() / OVERSAMP}; - const ALdouble freq_per_bin{mFreqPerBin}; + static constexpr double expected{al::MathDefs<double>::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<const Float ALphasor component{rect2polar(mFFTbuffer[k])}; /* Compute phase difference and subtract expected phase difference */ - double tmp{(component.Phase - mLastPhase[k]) - k*expected}; + double tmp{(component.Phase - mLastPhase[k]) - static_cast<double>(k)*expected}; /* Map delta phase into +/- Pi interval */ int qpd{double2int(tmp / al::MathDefs<double>::Pi())}; @@ -221,7 +220,7 @@ void PshifterState::process(const size_t samplesToDo, const al::span<const Float * amplitude and true frequency in analysis buffer. */ mAnalysis_buffer[k].Amplitude = 2.0 * component.Amplitude; - mAnalysis_buffer[k].Frequency = (k + tmp) * freq_per_bin; + mAnalysis_buffer[k].Frequency = (static_cast<double>(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<const Float for(size_t k{0u};k < STFT_HALF_SIZE+1;k++) { /* Compute bin deviation from scaled freq */ - const double tmp{mSyntesis_buffer[k].Frequency/freq_per_bin - k}; + const double tmp{mSyntesis_buffer[k].Frequency / freq_per_bin}; /* Calculate actual delta phase and accumulate it to get bin phase */ - mSumPhase[k] += (k + tmp) * expected; + mSumPhase[k] += tmp * expected; ALphasor component; component.Amplitude = mSyntesis_buffer[k].Amplitude; @@ -270,8 +269,7 @@ void PshifterState::process(const size_t samplesToDo, const al::span<const Float /* Windowing and add to output */ for(size_t k{0u};k < STFT_SIZE;k++) - mOutputAccum[k] += HannWindow[k] * mFFTbuffer[k].real() / - (0.5 * STFT_HALF_SIZE * OVERSAMP); + mOutputAccum[k] += HannWindow[k]*mFFTbuffer[k].real() * (2.0/STFT_HALF_SIZE/OVERSAMP); /* Shift accumulator, input & output FIFO */ std::copy_n(mOutputAccum, STFT_STEP, mOutFIFO); |