2007-12-17 15:43:35 -08:00
|
|
|
#ifndef _AL_FILTER_H_
|
|
|
|
#define _AL_FILTER_H_
|
|
|
|
|
|
|
|
#include "AL/al.h"
|
2008-12-10 11:54:13 -08:00
|
|
|
#include "alu.h"
|
2007-12-17 15:43:35 -08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2008-07-25 19:31:12 -07:00
|
|
|
typedef struct {
|
2008-10-02 22:20:42 -07:00
|
|
|
ALfloat coeff;
|
2009-06-06 23:33:53 -07:00
|
|
|
#ifndef _MSC_VER
|
2009-04-16 05:43:09 -07:00
|
|
|
ALfloat history[0];
|
2009-06-06 23:33:53 -07:00
|
|
|
#else
|
|
|
|
ALfloat history[1];
|
|
|
|
#endif
|
2008-07-25 19:31:12 -07:00
|
|
|
} FILTER;
|
2011-05-03 16:18:46 -07:00
|
|
|
/*
|
2009-05-16 23:34:26 -07:00
|
|
|
static __inline ALfloat lpFilter4P(FILTER *iir, ALuint offset, ALfloat input)
|
|
|
|
{
|
|
|
|
ALfloat *history = &iir->history[offset];
|
|
|
|
ALfloat a = iir->coeff;
|
|
|
|
ALfloat output = input;
|
|
|
|
|
|
|
|
output = output + (history[0]-output)*a;
|
|
|
|
history[0] = output;
|
|
|
|
output = output + (history[1]-output)*a;
|
|
|
|
history[1] = output;
|
|
|
|
output = output + (history[2]-output)*a;
|
|
|
|
history[2] = output;
|
|
|
|
output = output + (history[3]-output)*a;
|
|
|
|
history[3] = output;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
2011-05-03 16:18:46 -07:00
|
|
|
*/
|
2009-05-16 23:34:26 -07:00
|
|
|
static __inline ALfloat lpFilter2P(FILTER *iir, ALuint offset, ALfloat input)
|
|
|
|
{
|
|
|
|
ALfloat *history = &iir->history[offset];
|
|
|
|
ALfloat a = iir->coeff;
|
|
|
|
ALfloat output = input;
|
|
|
|
|
|
|
|
output = output + (history[0]-output)*a;
|
|
|
|
history[0] = output;
|
|
|
|
output = output + (history[1]-output)*a;
|
|
|
|
history[1] = output;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2009-11-22 21:20:27 -08:00
|
|
|
static __inline ALfloat lpFilter1P(FILTER *iir, ALuint offset, ALfloat input)
|
|
|
|
{
|
|
|
|
ALfloat *history = &iir->history[offset];
|
|
|
|
ALfloat a = iir->coeff;
|
|
|
|
ALfloat output = input;
|
|
|
|
|
|
|
|
output = output + (history[0]-output)*a;
|
|
|
|
history[0] = output;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
2011-05-03 16:18:46 -07:00
|
|
|
/*
|
2010-08-14 22:59:55 -07:00
|
|
|
static __inline ALfloat lpFilter4PC(const FILTER *iir, ALuint offset, ALfloat input)
|
|
|
|
{
|
|
|
|
const ALfloat *history = &iir->history[offset];
|
|
|
|
ALfloat a = iir->coeff;
|
|
|
|
ALfloat output = input;
|
|
|
|
|
|
|
|
output = output + (history[0]-output)*a;
|
|
|
|
output = output + (history[1]-output)*a;
|
|
|
|
output = output + (history[2]-output)*a;
|
|
|
|
output = output + (history[3]-output)*a;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
2011-05-03 16:18:46 -07:00
|
|
|
*/
|
2010-08-14 22:59:55 -07:00
|
|
|
static __inline ALfloat lpFilter2PC(const FILTER *iir, ALuint offset, ALfloat input)
|
|
|
|
{
|
|
|
|
const ALfloat *history = &iir->history[offset];
|
|
|
|
ALfloat a = iir->coeff;
|
|
|
|
ALfloat output = input;
|
|
|
|
|
|
|
|
output = output + (history[0]-output)*a;
|
|
|
|
output = output + (history[1]-output)*a;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline ALfloat lpFilter1PC(FILTER *iir, ALuint offset, ALfloat input)
|
|
|
|
{
|
|
|
|
const ALfloat *history = &iir->history[offset];
|
|
|
|
ALfloat a = iir->coeff;
|
|
|
|
ALfloat output = input;
|
|
|
|
|
|
|
|
output = output + (history[0]-output)*a;
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2009-12-09 07:21:59 -08:00
|
|
|
/* Calculates the low-pass filter coefficient given the pre-scaled gain and
|
|
|
|
* cos(w) value. Note that g should be pre-scaled (sqr(gain) for one-pole,
|
|
|
|
* sqrt(gain) for four-pole, etc) */
|
2011-05-18 18:42:25 -07:00
|
|
|
ALfloat lpCoeffCalc(ALfloat g, ALfloat cw);
|
2009-05-16 23:34:26 -07:00
|
|
|
|
2007-12-17 22:42:38 -08:00
|
|
|
|
2009-08-15 09:39:18 -07:00
|
|
|
typedef struct ALfilter
|
2007-12-17 15:43:35 -08:00
|
|
|
{
|
|
|
|
// Filter type (AL_FILTER_NULL, ...)
|
|
|
|
ALenum type;
|
|
|
|
|
2007-12-17 22:42:38 -08:00
|
|
|
ALfloat Gain;
|
|
|
|
ALfloat GainHF;
|
|
|
|
|
2007-12-17 15:43:35 -08:00
|
|
|
// Index to itself
|
|
|
|
ALuint filter;
|
|
|
|
} ALfilter;
|
|
|
|
|
|
|
|
|
2009-08-15 09:39:18 -07:00
|
|
|
ALvoid ReleaseALFilters(ALCdevice *device);
|
2007-12-17 17:08:44 -08:00
|
|
|
|
2007-12-17 15:43:35 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|