Move extension function declarations to alext.h/efx.h
[openal-soft.git] / OpenAL32 / Include / alFilter.h
blob2b5d3e94d2e91d374afc758ae727da6429ad9e79
1 #ifndef _AL_FILTER_H_
2 #define _AL_FILTER_H_
4 #include "AL/al.h"
5 #include "alu.h"
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
11 typedef struct {
12 ALfloat coeff;
13 #ifndef _MSC_VER
14 ALfloat history[0];
15 #else
16 ALfloat history[1];
17 #endif
18 } FILTER;
20 static __inline ALfloat lpFilter4P(FILTER *iir, ALuint offset, ALfloat input)
22 ALfloat *history = &iir->history[offset];
23 ALfloat a = iir->coeff;
24 ALfloat output = input;
26 output = output + (history[0]-output)*a;
27 history[0] = output;
28 output = output + (history[1]-output)*a;
29 history[1] = output;
30 output = output + (history[2]-output)*a;
31 history[2] = output;
32 output = output + (history[3]-output)*a;
33 history[3] = output;
35 return output;
38 static __inline ALfloat lpFilter2P(FILTER *iir, ALuint offset, ALfloat input)
40 ALfloat *history = &iir->history[offset];
41 ALfloat a = iir->coeff;
42 ALfloat output = input;
44 output = output + (history[0]-output)*a;
45 history[0] = output;
46 output = output + (history[1]-output)*a;
47 history[1] = output;
49 return output;
52 static __inline ALfloat lpFilter1P(FILTER *iir, ALuint offset, ALfloat input)
54 ALfloat *history = &iir->history[offset];
55 ALfloat a = iir->coeff;
56 ALfloat output = input;
58 output = output + (history[0]-output)*a;
59 history[0] = output;
61 return output;
64 /* Calculates the low-pass filter coefficient given the pre-scaled gain and
65 * cos(w) value. Note that g should be pre-scaled (sqr(gain) for one-pole,
66 * sqrt(gain) for four-pole, etc) */
67 static __inline ALfloat lpCoeffCalc(ALfloat g, ALfloat cw)
69 ALfloat a = 0.0f;
71 /* Be careful with gains < 0.01, as that causes the coefficient
72 * head towards 1, which will flatten the signal */
73 g = __max(g, 0.01f);
74 if(g < 0.9999f) /* 1-epsilon */
75 a = (1 - g*cw - aluSqrt(2*g*(1-cw) - g*g*(1 - cw*cw))) /
76 (1 - g);
78 return a;
82 typedef struct ALfilter
84 // Filter type (AL_FILTER_NULL, ...)
85 ALenum type;
87 ALfloat Gain;
88 ALfloat GainHF;
90 // Index to itself
91 ALuint filter;
93 struct ALfilter *next;
94 } ALfilter;
97 ALvoid ReleaseALFilters(ALCdevice *device);
99 #ifdef __cplusplus
101 #endif
103 #endif