Use powf when available
[openal-soft.git] / OpenAL32 / Include / alFilter.h
blobd5ca965a7bf6eeb3086ddc0d46f01d555942d282
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;
81 #define AL_FILTER_TYPE 0x8001
83 #define AL_FILTER_NULL 0x0000
84 #define AL_FILTER_LOWPASS 0x0001
85 #define AL_FILTER_HIGHPASS 0x0002
86 #define AL_FILTER_BANDPASS 0x0003
88 #define AL_LOWPASS_GAIN 0x0001
89 #define AL_LOWPASS_GAINHF 0x0002
92 typedef struct ALfilter
94 // Filter type (AL_FILTER_NULL, ...)
95 ALenum type;
97 ALfloat Gain;
98 ALfloat GainHF;
100 // Index to itself
101 ALuint filter;
103 struct ALfilter *next;
104 } ALfilter;
106 ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters);
107 ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters);
108 ALboolean AL_APIENTRY alIsFilter(ALuint filter);
110 ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue);
111 ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, ALint *piValues);
112 ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat flValue);
113 ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, ALfloat *pflValues);
115 ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *piValue);
116 ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *piValues);
117 ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *pflValue);
118 ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pflValues);
120 ALvoid ReleaseALFilters(ALCdevice *device);
122 #ifdef __cplusplus
124 #endif
126 #endif