Add SSE2 and SSE4.1 linear resamplers
[openal-soft.git] / OpenAL32 / Include / alFilter.h
blob62b5fda8db09cb4bb4908601a902f70fc4a858c8
1 #ifndef _AL_FILTER_H_
2 #define _AL_FILTER_H_
4 #include "alMain.h"
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
10 #define LOWPASSFREQREF (5000.0f)
11 #define HIGHPASSFREQREF (250.0f)
14 /* Filters implementation is based on the "Cookbook formulae for audio *
15 * EQ biquad filter coefficients" by Robert Bristow-Johnson *
16 * http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt */
18 typedef enum ALfilterType {
19 /** EFX-style low-pass filter, specifying a gain and reference frequency. */
20 ALfilterType_HighShelf,
21 /** EFX-style high-pass filter, specifying a gain and reference frequency. */
22 ALfilterType_LowShelf,
23 /** Peaking filter, specifying a gain, reference frequency, and bandwidth. */
24 ALfilterType_Peaking,
26 /** Low-pass cut-off filter, specifying a cut-off frequency and bandwidth. */
27 ALfilterType_LowPass,
28 /** High-pass cut-off filter, specifying a cut-off frequency and bandwidth. */
29 ALfilterType_HighPass,
30 /** Band-pass filter, specifying a center frequency and bandwidth. */
31 ALfilterType_BandPass,
32 } ALfilterType;
34 typedef struct ALfilterState {
35 ALfloat x[2]; /* History of two last input samples */
36 ALfloat y[2]; /* History of two last output samples */
37 ALfloat a[3]; /* Transfer function coefficients "a" */
38 ALfloat b[3]; /* Transfer function coefficients "b" */
40 void (*process)(struct ALfilterState *self, ALfloat *restrict dst, const ALfloat *src, ALuint numsamples);
41 } ALfilterState;
42 #define ALfilterState_process(a, ...) ((a)->process((a), __VA_ARGS__))
44 void ALfilterState_clear(ALfilterState *filter);
45 void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat gain, ALfloat freq_mult, ALfloat bandwidth);
47 inline ALfloat ALfilterState_processSingle(ALfilterState *filter, ALfloat sample)
49 ALfloat outsmp;
51 outsmp = filter->b[0] * sample +
52 filter->b[1] * filter->x[0] +
53 filter->b[2] * filter->x[1] -
54 filter->a[1] * filter->y[0] -
55 filter->a[2] * filter->y[1];
56 filter->x[1] = filter->x[0];
57 filter->x[0] = sample;
58 filter->y[1] = filter->y[0];
59 filter->y[0] = outsmp;
61 return outsmp;
64 void ALfilterState_processC(ALfilterState *filter, ALfloat *restrict dst, const ALfloat *src, ALuint numsamples);
67 typedef struct ALfilter {
68 // Filter type (AL_FILTER_NULL, ...)
69 ALenum type;
71 ALfloat Gain;
72 ALfloat GainHF;
73 ALfloat HFReference;
74 ALfloat GainLF;
75 ALfloat LFReference;
77 void (*SetParami)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALint val);
78 void (*SetParamiv)(struct ALfilter *filter, ALCcontext *context, ALenum param, const ALint *vals);
79 void (*SetParamf)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val);
80 void (*SetParamfv)(struct ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals);
82 void (*GetParami)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALint *val);
83 void (*GetParamiv)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALint *vals);
84 void (*GetParamf)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val);
85 void (*GetParamfv)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals);
87 /* Self ID */
88 ALuint id;
89 } ALfilter;
91 #define ALfilter_SetParami(x, c, p, v) ((x)->SetParami((x),(c),(p),(v)))
92 #define ALfilter_SetParamiv(x, c, p, v) ((x)->SetParamiv((x),(c),(p),(v)))
93 #define ALfilter_SetParamf(x, c, p, v) ((x)->SetParamf((x),(c),(p),(v)))
94 #define ALfilter_SetParamfv(x, c, p, v) ((x)->SetParamfv((x),(c),(p),(v)))
96 #define ALfilter_GetParami(x, c, p, v) ((x)->GetParami((x),(c),(p),(v)))
97 #define ALfilter_GetParamiv(x, c, p, v) ((x)->GetParamiv((x),(c),(p),(v)))
98 #define ALfilter_GetParamf(x, c, p, v) ((x)->GetParamf((x),(c),(p),(v)))
99 #define ALfilter_GetParamfv(x, c, p, v) ((x)->GetParamfv((x),(c),(p),(v)))
101 inline struct ALfilter *LookupFilter(ALCdevice *device, ALuint id)
102 { return (struct ALfilter*)LookupUIntMapKey(&device->FilterMap, id); }
103 inline struct ALfilter *RemoveFilter(ALCdevice *device, ALuint id)
104 { return (struct ALfilter*)RemoveUIntMapKey(&device->FilterMap, id); }
106 ALvoid ReleaseALFilters(ALCdevice *device);
108 #ifdef __cplusplus
110 #endif
112 #endif