diff options
author | Chris Robinson <[email protected]> | 2018-05-03 17:06:55 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-05-03 17:06:55 -0700 |
commit | af90d89b6bea2f5fb7dae930ed6d6e420568f2a9 (patch) | |
tree | 6a37e6a85e36aef9a4276dcc6e605ac2048a0330 /Alc/effects | |
parent | a19296e3cfb8b6b9e617576aba20c7d40d77dff9 (diff) |
Use a fixed-point scale for the pitch shifter frequency index
Diffstat (limited to 'Alc/effects')
-rw-r--r-- | Alc/effects/pshifter.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Alc/effects/pshifter.c b/Alc/effects/pshifter.c index e8be0be7..61857343 100644 --- a/Alc/effects/pshifter.c +++ b/Alc/effects/pshifter.c @@ -57,6 +57,7 @@ typedef struct ALpshifterState { /* Effect parameters */ ALsizei count; + ALsizei PitchShiftI; ALfloat PitchShift; ALfloat FreqPerBin; @@ -259,9 +260,10 @@ static ALvoid ALpshifterState_Destruct(ALpshifterState *state) static ALboolean ALpshifterState_deviceUpdate(ALpshifterState *state, ALCdevice *device) { /* (Re-)initializing parameters and clear the buffers. */ - state->count = FIFO_LATENCY; - state->PitchShift = 1.0f; - state->FreqPerBin = device->Frequency / (ALfloat)STFT_SIZE; + state->count = FIFO_LATENCY; + state->PitchShiftI = FRACTIONONE; + state->PitchShift = 1.0f; + state->FreqPerBin = device->Frequency / (ALfloat)STFT_SIZE; memset(state->InFIFO, 0, sizeof(state->InFIFO)); memset(state->OutFIFO, 0, sizeof(state->OutFIFO)); @@ -282,10 +284,13 @@ static ALvoid ALpshifterState_update(ALpshifterState *state, const ALCcontext *c { const ALCdevice *device = context->Device; ALfloat coeffs[MAX_AMBI_COEFFS]; + float pitch; - state->PitchShift = powf(2.0f, + pitch = powf(2.0f, (ALfloat)(props->Pshifter.CoarseTune*100 + props->Pshifter.FineTune) / 1200.0f ); + state->PitchShiftI = (ALsizei)(pitch*FRACTIONONE + 0.5f); + state->PitchShift = state->PitchShiftI * (1.0f/FRACTIONONE); CalcAngleCoeffs(0.0f, 0.0f, 0.0f, coeffs); ComputeDryPanGains(&device->Dry, coeffs, slot->Params.Gain, state->TargetGains); @@ -371,7 +376,7 @@ static ALvoid ALpshifterState_process(ALpshifterState *state, ALsizei SamplesToD for(k = 0;k < STFT_HALF_SIZE+1;k++) { - j = fastf2i((ALfloat)k * state->PitchShift); + j = (k*state->PitchShiftI) >> FRACTIONBITS; if(j >= STFT_HALF_SIZE+1) break; state->Syntesis_buffer[j].Amplitude += state->Analysis_buffer[k].Amplitude; |