diff options
author | Chris Robinson <[email protected]> | 2018-05-03 21:43:53 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-05-03 22:02:32 -0700 |
commit | ac8dbd7a56e4ca0ccfbef61b89bdb55775abea6a (patch) | |
tree | d4b67b98a59bb7812460df8c2426e3dfccefff84 /Alc/effects | |
parent | d8a659c6f2db425729a33b0649f467c14ef18a9b (diff) |
Add a specific function for truncating float-to-int conversions
Diffstat (limited to 'Alc/effects')
-rw-r--r-- | Alc/effects/chorus.c | 10 | ||||
-rw-r--r-- | Alc/effects/echo.c | 8 | ||||
-rw-r--r-- | Alc/effects/modulator.c | 3 | ||||
-rw-r--r-- | Alc/effects/reverb.c | 20 |
4 files changed, 20 insertions, 21 deletions
diff --git a/Alc/effects/chorus.c b/Alc/effects/chorus.c index 3710d936..ffb2b572 100644 --- a/Alc/effects/chorus.c +++ b/Alc/effects/chorus.c @@ -98,7 +98,7 @@ static ALboolean ALchorusState_deviceUpdate(ALchorusState *state, ALCdevice *Dev const ALfloat max_delay = maxf(AL_CHORUS_MAX_DELAY, AL_FLANGER_MAX_DELAY); ALsizei maxlen; - maxlen = NextPowerOf2(fastf2i(max_delay*2.0f*Device->Frequency) + 1); + maxlen = NextPowerOf2(float2int(max_delay*2.0f*Device->Frequency) + 1u); if(maxlen <= 0) return AL_FALSE; if(maxlen != state->BufferLength) @@ -140,7 +140,7 @@ static ALvoid ALchorusState_update(ALchorusState *state, const ALCcontext *Conte /* The LFO depth is scaled to be relative to the sample delay. Clamp the * delay and depth to allow enough padding for resampling. */ - state->delay = maxi(fastf2i(props->Chorus.Delay*frequency*FRACTIONONE + 0.5f), + state->delay = maxi(float2int(props->Chorus.Delay*frequency*FRACTIONONE + 0.5f), mindelay); state->depth = minf(props->Chorus.Depth * state->delay, (ALfloat)(state->delay - mindelay)); @@ -167,10 +167,10 @@ static ALvoid ALchorusState_update(ALchorusState *state, const ALCcontext *Conte /* Calculate LFO coefficient (number of samples per cycle). Limit the * max range to avoid overflow when calculating the displacement. */ - ALsizei lfo_range = mini(fastf2i(frequency/rate + 0.5f), INT_MAX/360 - 180); + ALsizei lfo_range = float2int(minf(frequency/rate + 0.5f, (ALfloat)(INT_MAX/360 - 180))); - state->lfo_offset = fastf2i((ALfloat)state->lfo_offset/state->lfo_range* - lfo_range + 0.5f) % lfo_range; + state->lfo_offset = float2int((ALfloat)state->lfo_offset/state->lfo_range* + lfo_range + 0.5f) % lfo_range; state->lfo_range = lfo_range; switch(state->waveform) { diff --git a/Alc/effects/echo.c b/Alc/effects/echo.c index a98ed933..676b17e8 100644 --- a/Alc/effects/echo.c +++ b/Alc/effects/echo.c @@ -92,8 +92,8 @@ static ALboolean ALechoState_deviceUpdate(ALechoState *state, ALCdevice *Device) // Use the next power of 2 for the buffer length, so the tap offsets can be // wrapped using a mask instead of a modulo - maxlen = fastf2i(AL_ECHO_MAX_DELAY*Device->Frequency + 0.5f) + - fastf2i(AL_ECHO_MAX_LRDELAY*Device->Frequency + 0.5f); + maxlen = float2int(AL_ECHO_MAX_DELAY*Device->Frequency + 0.5f) + + float2int(AL_ECHO_MAX_LRDELAY*Device->Frequency + 0.5f); maxlen = NextPowerOf2(maxlen); if(maxlen <= 0) return AL_FALSE; @@ -120,8 +120,8 @@ static ALvoid ALechoState_update(ALechoState *state, const ALCcontext *context, ALfloat coeffs[MAX_AMBI_COEFFS]; ALfloat gainhf, lrpan, spread; - state->Tap[0].delay = maxi(fastf2i(props->Echo.Delay*frequency + 0.5f), 1); - state->Tap[1].delay = fastf2i(props->Echo.LRDelay*frequency + 0.5f); + state->Tap[0].delay = maxi(float2int(props->Echo.Delay*frequency + 0.5f), 1); + state->Tap[1].delay = float2int(props->Echo.LRDelay*frequency + 0.5f); state->Tap[1].delay += state->Tap[0].delay; spread = props->Echo.Spread; diff --git a/Alc/effects/modulator.c b/Alc/effects/modulator.c index f97f7572..7f1a2cad 100644 --- a/Alc/effects/modulator.c +++ b/Alc/effects/modulator.c @@ -137,8 +137,7 @@ static ALvoid ALmodulatorState_update(ALmodulatorState *state, const ALCcontext else /*if(Slot->Params.EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SQUARE)*/ state->GetSamples = ModulateSquare; - state->step = fastf2i(props->Modulator.Frequency*WAVEFORM_FRACONE / - device->Frequency); + state->step = float2int(props->Modulator.Frequency*WAVEFORM_FRACONE/device->Frequency + 0.5f); state->step = clampi(state->step, 1, WAVEFORM_FRACONE-1); /* Custom filter coeffs, which match the old version instead of a low-shelf. */ diff --git a/Alc/effects/reverb.c b/Alc/effects/reverb.c index 9fc65a48..12e78bdf 100644 --- a/Alc/effects/reverb.c +++ b/Alc/effects/reverb.c @@ -463,7 +463,7 @@ static ALuint CalcLineLength(const ALfloat length, const ptrdiff_t offset, const /* All line lengths are powers of 2, calculated from their lengths in * seconds, rounded up. */ - samples = fastf2i(ceilf(length*frequency)); + samples = float2int(ceilf(length*frequency)); samples = NextPowerOf2(samples + extra); /* All lines share a single sample buffer. */ @@ -565,9 +565,9 @@ static ALboolean ALreverbState_deviceUpdate(ALreverbState *State, ALCdevice *Dev multiplier = CalcDelayLengthMult(AL_EAXREVERB_MAX_DENSITY); /* The late feed taps are set a fixed position past the latest delay tap. */ - State->LateFeedTap = fastf2i((AL_EAXREVERB_MAX_REFLECTIONS_DELAY + - EARLY_TAP_LENGTHS[NUM_LINES-1]*multiplier) * - frequency); + State->LateFeedTap = float2int((AL_EAXREVERB_MAX_REFLECTIONS_DELAY + + EARLY_TAP_LENGTHS[NUM_LINES-1]*multiplier) * + frequency); return AL_TRUE; } @@ -949,13 +949,13 @@ static ALvoid UpdateDelayLine(const ALfloat earlyDelay, const ALfloat lateDelay, for(i = 0;i < NUM_LINES;i++) { length = earlyDelay + EARLY_TAP_LENGTHS[i]*multiplier; - State->EarlyDelayTap[i][1] = fastf2i(length * frequency); + State->EarlyDelayTap[i][1] = float2int(length * frequency); length = EARLY_TAP_LENGTHS[i]*multiplier; State->EarlyDelayCoeff[i] = CalcDecayCoeff(length, decayTime); length = lateDelay + (LATE_LINE_LENGTHS[i] - LATE_LINE_LENGTHS[0])*0.25f*multiplier; - State->LateDelayTap[i][1] = State->LateFeedTap + fastf2i(length * frequency); + State->LateDelayTap[i][1] = State->LateFeedTap + float2int(length * frequency); } } @@ -973,13 +973,13 @@ static ALvoid UpdateEarlyLines(const ALfloat density, const ALfloat decayTime, c length = EARLY_ALLPASS_LENGTHS[i] * multiplier; /* Calculate the delay offset for each all-pass line. */ - Early->VecAp.Offset[i][1] = fastf2i(length * frequency); + Early->VecAp.Offset[i][1] = float2int(length * frequency); /* Calculate the length (in seconds) of each delay line. */ length = EARLY_LINE_LENGTHS[i] * multiplier; /* Calculate the delay offset for each delay line. */ - Early->Offset[i][1] = fastf2i(length * frequency); + Early->Offset[i][1] = float2int(length * frequency); /* Calculate the gain (coefficient) for each line. */ Early->Coeff[i] = CalcDecayCoeff(length, decayTime); @@ -1026,7 +1026,7 @@ static ALvoid UpdateLateLines(const ALfloat density, const ALfloat diffusion, co length = LATE_ALLPASS_LENGTHS[i] * multiplier; /* Calculate the delay offset for each all-pass line. */ - Late->VecAp.Offset[i][1] = fastf2i(length * frequency); + Late->VecAp.Offset[i][1] = float2int(length * frequency); /* Calculate the length (in seconds) of each delay line. This also * applies the echo transformation. As the EAX echo depth approaches @@ -1036,7 +1036,7 @@ static ALvoid UpdateLateLines(const ALfloat density, const ALfloat diffusion, co length = lerp(LATE_LINE_LENGTHS[i] * multiplier, echoTime, echoDepth); /* Calculate the delay offset for each delay line. */ - Late->Offset[i][1] = fastf2i(length*frequency + 0.5f); + Late->Offset[i][1] = float2int(length*frequency + 0.5f); /* Approximate the absorption that the vector all-pass would exhibit * given the current diffusion so we don't have to process a full T60 |