summaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-11-26 01:07:54 -0800
committerChris Robinson <[email protected]>2010-11-26 01:07:54 -0800
commitde8b7fbc5fa76327bba59a620fa2c6d946d226db (patch)
tree35df890590493b3a459030240f96f205f2fc6b82 /Alc
parent98d78f7ff9a3636567273e4384731debca2ec79f (diff)
Share the interpolation functions and use them in the reverb effect
Diffstat (limited to 'Alc')
-rw-r--r--Alc/alcReverb.c28
-rw-r--r--Alc/mixer.c32
2 files changed, 23 insertions, 37 deletions
diff --git a/Alc/alcReverb.c b/Alc/alcReverb.c
index 02f07f9a..ed81665a 100644
--- a/Alc/alcReverb.c
+++ b/Alc/alcReverb.c
@@ -700,8 +700,8 @@ static __inline ALfloat EAXModulation(ALverbState *State, ALfloat in)
// The depth determines the range over which to read the input samples
// from, so it must be filtered to reduce the distortion caused by even
// small parameter changes.
- State->Mod.Filter += (State->Mod.Depth - State->Mod.Filter) *
- State->Mod.Coeff;
+ State->Mod.Filter = lerp(State->Mod.Filter, State->Mod.Depth,
+ State->Mod.Coeff);
// Calculate the read offset and fraction between it and the next sample.
frac = (1.0f + (State->Mod.Filter * sinus));
@@ -719,7 +719,7 @@ static __inline ALfloat EAXModulation(ALverbState *State, ALfloat in)
// The output is obtained by linearly interpolating the two samples that
// were acquired above.
- return out0 + ((out1 - out0) * frac);
+ return lerp(out0, out1, frac);
}
// Delay line output routine for early reflections.
@@ -796,9 +796,9 @@ static __inline ALfloat LateDelayLineOut(ALverbState *State, ALuint index)
// Low-pass filter input/output routine for late reverb.
static __inline ALfloat LateLowPassInOut(ALverbState *State, ALuint index, ALfloat in)
{
- State->Late.LpSample[index] = in +
- ((State->Late.LpSample[index] - in) * State->Late.LpCoeff[index]);
- return State->Late.LpSample[index];
+ in = lerp(in, State->Late.LpSample[index], State->Late.LpCoeff[index]);
+ State->Late.LpSample[index] = in;
+ return in;
}
// Given four decorrelated input samples, this function produces four-channel
@@ -853,10 +853,10 @@ static __inline ALvoid LateReverb(ALverbState *State, ALfloat *in, ALfloat *out)
* the cyclical delay line coefficients. Thus only the y coefficient is
* applied when mixing, and is modified to be: y / x.
*/
- f[0] = d[0] + (State->Late.MixCoeff * ( d[1] - d[2] + d[3]));
- f[1] = d[1] + (State->Late.MixCoeff * (-d[0] + d[2] + d[3]));
- f[2] = d[2] + (State->Late.MixCoeff * ( d[0] - d[1] + d[3]));
- f[3] = d[3] + (State->Late.MixCoeff * (-d[0] - d[1] - d[2]));
+ f[0] = d[0] + (State->Late.MixCoeff * ( d[1] + -d[2] + d[3]));
+ f[1] = d[1] + (State->Late.MixCoeff * (-d[0] + d[2] + d[3]));
+ f[2] = d[2] + (State->Late.MixCoeff * ( d[0] + -d[1] + d[3]));
+ f[3] = d[3] + (State->Late.MixCoeff * (-d[0] + -d[1] + -d[2] ));
// Output the results of the matrix for all four channels, attenuated by
// the late reverb gain (which is attenuated by the 'x' mix coefficient).
@@ -893,14 +893,14 @@ static __inline ALvoid EAXEcho(ALverbState *State, ALfloat in, ALfloat *late)
// Mix the energy-attenuated input with the output and pass it through
// the echo low-pass filter.
feed += State->Echo.DensityGain * in;
- feed += ((State->Echo.LpSample - feed) * State->Echo.LpCoeff);
+ feed = lerp(feed, State->Echo.LpSample, State->Echo.LpCoeff);
State->Echo.LpSample = feed;
// Then the echo all-pass filter.
feed = AllpassInOut(&State->Echo.ApDelay,
- State->Offset - State->Echo.ApOffset,
- State->Offset, feed, State->Echo.ApFeedCoeff,
- State->Echo.ApCoeff);
+ State->Offset - State->Echo.ApOffset,
+ State->Offset, feed, State->Echo.ApFeedCoeff,
+ State->Echo.ApCoeff);
// Feed the delay with the mixed and filtered sample.
DelayLineIn(&State->Echo.Delay, State->Offset, feed);
diff --git a/Alc/mixer.c b/Alc/mixer.c
index f16a2e0c..74af356d 100644
--- a/Alc/mixer.c
+++ b/Alc/mixer.c
@@ -37,43 +37,29 @@
#include "bs2b.h"
-static __inline ALdouble lerp(ALdouble val1, ALdouble val2, ALint frac)
-{
- val1 += ((val2-val1) * (frac * (1.0/(1<<FRACTIONBITS))));
- return val1;
-}
-static __inline ALdouble cubic(ALdouble val0, ALdouble val1, ALdouble val2, ALdouble val3, ALint frac)
-{
- ALdouble mu = frac * (1.0/(1<<FRACTIONBITS));
- ALdouble mu2 = mu*mu;
- ALdouble a0 = -0.5*val0 + 1.5*val1 + -1.5*val2 + 0.5*val3;
- ALdouble a1 = val0 + -2.5*val1 + 2.0*val2 + -0.5*val3;
- ALdouble a2 = -0.5*val0 + 0.5*val2;
- ALdouble a3 = val1;
-
- return a0*mu*mu2 + a1*mu2 + a2*mu + a3;
-}
-
static __inline ALdouble point32(const ALfloat *vals, ALint step, ALint frac)
{ return vals[0]; (void)step; (void)frac; }
static __inline ALdouble lerp32(const ALfloat *vals, ALint step, ALint frac)
-{ return lerp(vals[0], vals[step], frac); }
+{ return lerp(vals[0], vals[step], frac * (1.0/(1<<FRACTIONBITS))); }
static __inline ALdouble cubic32(const ALfloat *vals, ALint step, ALint frac)
-{ return cubic(vals[-step], vals[0], vals[step], vals[step+step], frac); }
+{ return cubic(vals[-step], vals[0], vals[step], vals[step+step],
+ frac * (1.0/(1<<FRACTIONBITS))); }
static __inline ALdouble point16(const ALshort *vals, ALint step, ALint frac)
{ return vals[0] / 32767.0; (void)step; (void)frac; }
static __inline ALdouble lerp16(const ALshort *vals, ALint step, ALint frac)
-{ return lerp(vals[0], vals[step], frac) / 32767.0; }
+{ return lerp(vals[0], vals[step], frac * (1.0/(1<<FRACTIONBITS))) / 32767.0; }
static __inline ALdouble cubic16(const ALshort *vals, ALint step, ALint frac)
-{ return cubic(vals[-step], vals[0], vals[step], vals[step+step], frac) / 32767.0; }
+{ return cubic(vals[-step], vals[0], vals[step], vals[step+step],
+ frac * (1.0/(1<<FRACTIONBITS))) / 32767.0; }
static __inline ALdouble point8(const ALubyte *vals, ALint step, ALint frac)
{ return (vals[0]-128.0) / 127.0; (void)step; (void)frac; }
static __inline ALdouble lerp8(const ALubyte *vals, ALint step, ALint frac)
-{ return (lerp(vals[0], vals[step], frac)-128.0) / 127.0; }
+{ return (lerp(vals[0], vals[step], frac * (1.0/(1<<FRACTIONBITS)))-128.0) / 127.0; }
static __inline ALdouble cubic8(const ALubyte *vals, ALint step, ALint frac)
-{ return (cubic(vals[-step], vals[0], vals[step], vals[step+step], frac)-128.0) / 127.0; }
+{ return (cubic(vals[-step], vals[0], vals[step], vals[step+step],
+ frac * (1.0/(1<<FRACTIONBITS)))-128.0) / 127.0; }
#define DECL_TEMPLATE(T, sampler) \