aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32/Include
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2009-12-09 07:21:59 -0800
committerChris Robinson <[email protected]>2009-12-09 07:21:59 -0800
commit656a4063775b30fd3910181a049f9194432e5c16 (patch)
tree903384d2b634c1c8ebad44647d2e3ec66c75fda6 /OpenAL32/Include
parent5fcd6cc510212b3511084491da2feb2b0ea0110e (diff)
Use an inline function to calculate the low-pass filter coefficient
Diffstat (limited to 'OpenAL32/Include')
-rw-r--r--OpenAL32/Include/alFilter.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/OpenAL32/Include/alFilter.h b/OpenAL32/Include/alFilter.h
index 754b0b6f..d5ca965a 100644
--- a/OpenAL32/Include/alFilter.h
+++ b/OpenAL32/Include/alFilter.h
@@ -61,6 +61,22 @@ static __inline ALfloat lpFilter1P(FILTER *iir, ALuint offset, ALfloat input)
return output;
}
+/* 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) */
+static __inline ALfloat lpCoeffCalc(ALfloat g, ALfloat cw)
+{
+ ALfloat a = 0.0f;
+
+ /* Be careful with gains < 0.01, as that causes the coefficient
+ * head towards 1, which will flatten the signal */
+ g = __max(g, 0.01f);
+ if(g < 0.9999f) /* 1-epsilon */
+ a = (1 - g*cw - aluSqrt(2*g*(1-cw) - g*g*(1 - cw*cw))) /
+ (1 - g);
+
+ return a;
+}
#define AL_FILTER_TYPE 0x8001