Use a properly-defined history for the FILTER struct

This commit is contained in:
Chris Robinson 2013-05-21 07:10:24 -07:00
parent 3ee0f8feb9
commit e4186f4903
7 changed files with 28 additions and 33 deletions

View File

@ -254,6 +254,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALboolean DirectChannels;
ALfloat hwidth = 0.0f;
ALfloat Pitch;
ALfloat coeff;
ALfloat cw;
ALint i, c;
@ -459,11 +460,14 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
/* We use two chained one-pole filters, so we need to take the
* square root of the squared gain, which is the same as the base
* gain. */
ALSource->Params.Direct.iirFilter.coeff = lpCoeffCalc(DryGainHF, cw);
coeff = lpCoeffCalc(DryGainHF, cw);
for(c = 0;c < num_channels;c++)
ALSource->Params.Direct.Filter[c].coeff = lpCoeffCalc(DryGainHF, cw);
for(i = 0;i < NumSends;i++)
{
ALfloat a = lpCoeffCalc(WetGainHF[i], cw);
ALSource->Params.Send[i].iirFilter.coeff = a;
coeff = lpCoeffCalc(WetGainHF[i], cw);
for(c = 0;c < num_channels;c++)
ALSource->Params.Send[i].Filter[c].coeff = coeff;
}
}
@ -903,11 +907,11 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
/* Update filter coefficients. */
cw = cosf(F_PI*2.0f * LOWPASSFREQREF / Frequency);
ALSource->Params.Direct.iirFilter.coeff = lpCoeffCalc(DryGainHF, cw);
ALSource->Params.Direct.Filter[0].coeff = lpCoeffCalc(DryGainHF, cw);
for(i = 0;i < NumSends;i++)
{
ALfloat a = lpCoeffCalc(WetGainHF[i], cw);
ALSource->Params.Send[i].iirFilter.coeff = a;
ALSource->Params.Send[i].Filter[0].coeff = a;
}
}

View File

@ -48,7 +48,6 @@ typedef struct ALechoState {
ALfloat FeedGain;
FILTER iirFilter;
ALfloat history[2];
} ALechoState;
static ALvoid ALechoState_Destroy(ALechoState *state)
@ -144,7 +143,7 @@ static ALvoid ALechoState_Process(ALechoState *state, ALuint SamplesToDo, const
// Apply damping and feedback gain to the second tap, and mix in the
// new sample
smp = lpFilter2P(&state->iirFilter, 0, temps[i][1]+SamplesIn[i]);
smp = lpFilter2P(&state->iirFilter, temps[i][1]+SamplesIn[i]);
state->SampleBuffer[offset&mask] = smp * state->FeedGain;
}

View File

@ -45,7 +45,6 @@ typedef struct ALmodulatorState {
ALfloat Gain[MaxChannels];
FILTER iirFilter;
ALfloat history[1];
} ALmodulatorState;
#define WAVEFORM_FRACBITS 24
@ -68,9 +67,9 @@ static __inline ALfloat Square(ALuint index)
}
static __inline ALfloat hpFilter1P(FILTER *iir, ALuint offset, ALfloat input)
static __inline ALfloat hpFilter1P(FILTER *iir, ALfloat input)
{
ALfloat *history = &iir->history[offset];
ALfloat *history = iir->history;
ALfloat a = iir->coeff;
ALfloat output = input;
@ -100,7 +99,7 @@ static void Process##func(ALmodulatorState *state, ALuint SamplesToDo, \
{ \
ALfloat samp; \
samp = SamplesIn[base+i]; \
samp = hpFilter1P(&state->iirFilter, 0, samp); \
samp = hpFilter1P(&state->iirFilter, samp); \
\
index += step; \
index &= WAVEFORM_FRACMASK; \

View File

@ -51,7 +51,6 @@ typedef struct ALreverbState {
// Master effect low-pass filter (2 chained 1-pole filters).
FILTER LpFilter;
ALfloat LpHistory[2];
struct {
// Modulator delay line.
@ -483,7 +482,7 @@ static __inline ALvoid VerbPass(ALreverbState *State, ALfloat in, ALfloat *RESTR
ALfloat feed, late[4], taps[4];
// Low-pass filter the incoming sample.
in = lpFilter2P(&State->LpFilter, 0, in);
in = lpFilter2P(&State->LpFilter, in);
// Feed the initial delay line.
DelayLineIn(&State->Delay, State->Offset, in);
@ -522,7 +521,7 @@ static __inline ALvoid EAXVerbPass(ALreverbState *State, ALfloat in, ALfloat *RE
ALfloat feed, taps[4];
// Low-pass filter the incoming sample.
in = lpFilter2P(&State->LpFilter, 0, in);
in = lpFilter2P(&State->LpFilter, in);
// Perform any modulation on the input.
in = EAXModulation(State, in);

View File

@ -84,13 +84,13 @@ static void SilenceData(ALfloat *dst, ALuint samples)
}
static void Filter2P(FILTER *filter, ALuint chan, ALfloat *RESTRICT dst,
const ALfloat *RESTRICT src, ALuint numsamples)
static void Filter2P(FILTER *filter, ALfloat *RESTRICT dst, const ALfloat *RESTRICT src,
ALuint numsamples)
{
ALuint i;
for(i = 0;i < numsamples;i++)
dst[i] = lpFilter2P(filter, chan, src[i]);
dst[i] = lpFilter2PC(filter, chan, src[i]);
dst[i] = lpFilter2P(filter, src[i]);
dst[i] = lpFilter2PC(filter, src[i]);
}
@ -328,7 +328,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
{
DirectParams *directparms = &Source->Params.Direct;
Filter2P(&directparms->iirFilter, chan, SrcData, ResampledData,
Filter2P(&directparms->Filter[chan], SrcData, ResampledData,
DstBufferSize);
Source->Params.DryMix(directparms, SrcData, chan, OutPos,
SamplesToDo, DstBufferSize);
@ -340,7 +340,7 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
if(!sendparms->Slot)
continue;
Filter2P(&sendparms->iirFilter, chan, SrcData, ResampledData,
Filter2P(&sendparms->Filter[chan], SrcData, ResampledData,
DstBufferSize);
Source->Params.WetMix(sendparms, SrcData, OutPos,
SamplesToDo, DstBufferSize);

View File

@ -11,16 +11,12 @@ extern "C" {
typedef struct {
ALfloat coeff;
#ifndef _MSC_VER
ALfloat history[0];
#else
ALfloat history[1];
#endif
ALfloat history[2];
} FILTER;
static __inline ALfloat lpFilter2P(FILTER *iir, ALuint offset, ALfloat input)
static __inline ALfloat lpFilter2P(FILTER *iir, ALfloat input)
{
ALfloat *history = &iir->history[offset*2];
ALfloat *history = iir->history;
ALfloat a = iir->coeff;
ALfloat output = input;
@ -32,9 +28,9 @@ static __inline ALfloat lpFilter2P(FILTER *iir, ALuint offset, ALfloat input)
return output;
}
static __inline ALfloat lpFilter2PC(const FILTER *iir, ALuint offset, ALfloat input)
static __inline ALfloat lpFilter2PC(const FILTER *iir, ALfloat input)
{
const ALfloat *history = &iir->history[offset*2];
const ALfloat *history = iir->history;
ALfloat a = iir->coeff;
ALfloat output = input;

View File

@ -62,8 +62,7 @@ typedef struct DirectParams {
ALfloat Gains[MaxChannels][MaxChannels];
/* A low-pass filter, using 2 chained one-pole filters. */
FILTER iirFilter;
ALfloat history[MaxChannels*2];
FILTER Filter[MaxChannels];
} DirectParams;
typedef struct SendParams {
@ -74,8 +73,7 @@ typedef struct SendParams {
ALfloat Gain;
/* A low-pass filter, using 2 chained one-pole filters. */
FILTER iirFilter;
ALfloat history[MaxChannels*2];
FILTER Filter[MaxChannels];
} SendParams;