Add a specific function for truncating float-to-int conversions
This commit is contained in:
@@ -352,25 +352,20 @@ void aluSelectPostProcess(ALCdevice *device)
|
||||
*/
|
||||
void BsincPrepare(const ALuint increment, BsincState *state, const BSincTable *table)
|
||||
{
|
||||
ALfloat sf;
|
||||
ALsizei si;
|
||||
ALfloat sf = 0.0f;
|
||||
ALsizei si = BSINC_SCALE_COUNT-1;
|
||||
|
||||
if(increment > FRACTIONONE)
|
||||
{
|
||||
sf = (ALfloat)FRACTIONONE / increment;
|
||||
sf = maxf(0.0f, (BSINC_SCALE_COUNT-1) * (sf-table->scaleBase) * table->scaleRange);
|
||||
si = fastf2i(sf);
|
||||
si = float2int(sf);
|
||||
/* The interpolation factor is fit to this diagonally-symmetric curve
|
||||
* to reduce the transition ripple caused by interpolating different
|
||||
* scales of the sinc function.
|
||||
*/
|
||||
sf = 1.0f - cosf(asinf(sf - si));
|
||||
}
|
||||
else
|
||||
{
|
||||
sf = 0.0f;
|
||||
si = BSINC_SCALE_COUNT - 1;
|
||||
}
|
||||
|
||||
state->sf = sf;
|
||||
state->m = table->m[si];
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
+4
-4
@@ -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;
|
||||
|
||||
@@ -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. */
|
||||
|
||||
+10
-10
@@ -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
|
||||
|
||||
@@ -124,6 +124,7 @@ DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_GUID, 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x
|
||||
extern inline ALuint NextPowerOf2(ALuint value);
|
||||
extern inline size_t RoundUp(size_t value, size_t r);
|
||||
extern inline ALint fastf2i(ALfloat f);
|
||||
extern inline int float2int(float f);
|
||||
#ifndef __GNUC__
|
||||
#if defined(HAVE_BITSCANFORWARD64_INTRINSIC)
|
||||
extern inline int msvc64_ctz64(ALuint64 v);
|
||||
|
||||
+9
-11
@@ -74,31 +74,29 @@ static struct HrtfEntry *LoadedHrtfs = NULL;
|
||||
|
||||
|
||||
/* Calculate the elevation index given the polar elevation in radians. This
|
||||
* will return an index between 0 and (evcount - 1). Assumes the FPU is in
|
||||
* round-to-zero mode.
|
||||
* will return an index between 0 and (evcount - 1).
|
||||
*/
|
||||
static ALsizei CalcEvIndex(ALsizei evcount, ALfloat ev, ALfloat *mu)
|
||||
{
|
||||
ALsizei idx;
|
||||
ev = (F_PI_2+ev) * (evcount-1) / F_PI;
|
||||
idx = mini(fastf2i(ev), evcount-1);
|
||||
idx = float2int(ev);
|
||||
|
||||
*mu = ev - idx;
|
||||
return idx;
|
||||
return mini(idx, evcount-1);
|
||||
}
|
||||
|
||||
/* Calculate the azimuth index given the polar azimuth in radians. This will
|
||||
* return an index between 0 and (azcount - 1). Assumes the FPU is in round-to-
|
||||
* zero mode.
|
||||
* return an index between 0 and (azcount - 1).
|
||||
*/
|
||||
static ALsizei CalcAzIndex(ALsizei azcount, ALfloat az, ALfloat *mu)
|
||||
{
|
||||
ALsizei idx;
|
||||
az = (F_TAU+az) * azcount / F_TAU;
|
||||
|
||||
idx = fastf2i(az) % azcount;
|
||||
*mu = az - floorf(az);
|
||||
return idx;
|
||||
idx = float2int(az);
|
||||
*mu = az - idx;
|
||||
return idx % azcount;
|
||||
}
|
||||
|
||||
/* Calculates static HRIR coefficients and delays for the given polar elevation
|
||||
@@ -158,11 +156,11 @@ void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth,
|
||||
blend[3] = ( emu) * ( amu[1]) * dirfact;
|
||||
|
||||
/* Calculate the blended HRIR delays. */
|
||||
delays[0] = fastf2i(
|
||||
delays[0] = float2int(
|
||||
Hrtf->delays[idx[0]][0]*blend[0] + Hrtf->delays[idx[1]][0]*blend[1] +
|
||||
Hrtf->delays[idx[2]][0]*blend[2] + Hrtf->delays[idx[3]][0]*blend[3] + 0.5f
|
||||
);
|
||||
delays[1] = fastf2i(
|
||||
delays[1] = float2int(
|
||||
Hrtf->delays[idx[0]][1]*blend[0] + Hrtf->delays[idx[1]][1]*blend[1] +
|
||||
Hrtf->delays[idx[2]][1]*blend[2] + Hrtf->delays[idx[3]][1]*blend[3] + 0.5f
|
||||
);
|
||||
|
||||
@@ -260,6 +260,13 @@ inline ALint fastf2i(ALfloat f)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Converts float-to-int using standard behavior (truncation). */
|
||||
inline int float2int(float f)
|
||||
{
|
||||
/* TODO: Make a more efficient method for x87. */
|
||||
return (ALint)f;
|
||||
}
|
||||
|
||||
|
||||
enum DevProbe {
|
||||
ALL_DEVICE_PROBE,
|
||||
|
||||
Reference in New Issue
Block a user