comparison OpenAL32/Include/alFilter.h @ 0:f9476ff7637e

initial forking of open-al to create multiple listeners
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 13:02:31 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f9476ff7637e
1 #ifndef _AL_FILTER_H_
2 #define _AL_FILTER_H_
3
4 #include "AL/al.h"
5 #include "alu.h"
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10
11 typedef struct {
12 ALfloat coeff;
13 #ifndef _MSC_VER
14 ALfloat history[0];
15 #else
16 ALfloat history[1];
17 #endif
18 } FILTER;
19
20 static __inline ALfloat lpFilter2P(FILTER *iir, ALuint offset, ALfloat input)
21 {
22 ALfloat *history = &iir->history[offset*2];
23 ALfloat a = iir->coeff;
24 ALfloat output = input;
25
26 output = output + (history[0]-output)*a;
27 history[0] = output;
28 output = output + (history[1]-output)*a;
29 history[1] = output;
30
31 return output;
32 }
33 static __inline ALfloat lpFilter1P(FILTER *iir, ALuint offset, ALfloat input)
34 {
35 ALfloat *history = &iir->history[offset];
36 ALfloat a = iir->coeff;
37 ALfloat output = input;
38
39 output = output + (history[0]-output)*a;
40 history[0] = output;
41
42 return output;
43 }
44
45 static __inline ALfloat lpFilter2PC(const FILTER *iir, ALuint offset, ALfloat input)
46 {
47 const ALfloat *history = &iir->history[offset*2];
48 ALfloat a = iir->coeff;
49 ALfloat output = input;
50
51 output = output + (history[0]-output)*a;
52 output = output + (history[1]-output)*a;
53
54 return output;
55 }
56 static __inline ALfloat lpFilter1PC(FILTER *iir, ALuint offset, ALfloat input)
57 {
58 const ALfloat *history = &iir->history[offset];
59 ALfloat a = iir->coeff;
60 ALfloat output = input;
61
62 output = output + (history[0]-output)*a;
63
64 return output;
65 }
66
67 /* Calculates the low-pass filter coefficient given the pre-scaled gain and
68 * cos(w) value. Note that g should be pre-scaled (sqr(gain) for one-pole,
69 * sqrt(gain) for four-pole, etc) */
70 ALfloat lpCoeffCalc(ALfloat g, ALfloat cw);
71
72
73 typedef struct ALfilter
74 {
75 // Filter type (AL_FILTER_NULL, ...)
76 ALenum type;
77
78 ALfloat Gain;
79 ALfloat GainHF;
80
81 // Index to itself
82 ALuint filter;
83 } ALfilter;
84
85
86 ALvoid ReleaseALFilters(ALCdevice *device);
87
88 #ifdef __cplusplus
89 }
90 #endif
91
92 #endif