aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32/Include
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2015-11-01 04:43:55 -0800
committerChris Robinson <[email protected]>2015-11-01 05:41:06 -0800
commitc57f57192067e2d68cfe4ab0fc9479d2453bfbda (patch)
treefb9dabd6296c87ff72f4271774ae9951898d9227 /OpenAL32/Include
parentf094d94608e00b1b08bd8c607d16651072323bb5 (diff)
Pass in the Q parameter for setting the filter parameters
Also better handle the peaking filter gain.
Diffstat (limited to 'OpenAL32/Include')
-rw-r--r--OpenAL32/Include/alFilter.h43
-rw-r--r--OpenAL32/Include/alu.h13
2 files changed, 36 insertions, 20 deletions
diff --git a/OpenAL32/Include/alFilter.h b/OpenAL32/Include/alFilter.h
index 9772f432..3c65fd9f 100644
--- a/OpenAL32/Include/alFilter.h
+++ b/OpenAL32/Include/alFilter.h
@@ -3,6 +3,8 @@
#include "alMain.h"
+#include "math_defs.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -11,23 +13,29 @@ extern "C" {
#define HIGHPASSFREQREF (250.0f)
-/* Filters implementation is based on the "Cookbook formulae for audio *
- * EQ biquad filter coefficients" by Robert Bristow-Johnson *
- * http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt */
+/* Filters implementation is based on the "Cookbook formulae for audio
+ * EQ biquad filter coefficients" by Robert Bristow-Johnson
+ * http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
+ */
+/* Implementation note: For the shelf filters, the specified gain is for the
+ * reference frequency, which is the centerpoint of the transition band. This
+ * better matches EFX filter design. To set the gain for the shelf itself, use
+ * the square root of the desired linear gain (or halve the dB gain).
+ */
typedef enum ALfilterType {
/** EFX-style low-pass filter, specifying a gain and reference frequency. */
ALfilterType_HighShelf,
/** EFX-style high-pass filter, specifying a gain and reference frequency. */
ALfilterType_LowShelf,
- /** Peaking filter, specifying a gain, reference frequency, and bandwidth. */
+ /** Peaking filter, specifying a gain and reference frequency. */
ALfilterType_Peaking,
- /** Low-pass cut-off filter, specifying a cut-off frequency and bandwidth. */
+ /** Low-pass cut-off filter, specifying a cut-off frequency. */
ALfilterType_LowPass,
- /** High-pass cut-off filter, specifying a cut-off frequency and bandwidth. */
+ /** High-pass cut-off filter, specifying a cut-off frequency. */
ALfilterType_HighPass,
- /** Band-pass filter, specifying a center frequency and bandwidth. */
+ /** Band-pass filter, specifying a center frequency. */
ALfilterType_BandPass,
} ALfilterType;
@@ -41,8 +49,27 @@ typedef struct ALfilterState {
} ALfilterState;
#define ALfilterState_process(a, ...) ((a)->process((a), __VA_ARGS__))
+/* Calculates the rcpQ (i.e. 1/Q) coefficient for shelving filters, using the
+ * reference gain and shelf slope parameter.
+ * 0 < gain
+ * 0 < slope <= 1
+ */
+inline ALfloat calc_rcpQ_from_slope(ALfloat gain, ALfloat slope)
+{
+ return sqrtf((gain + 1.0f/gain)*(1.0f/slope - 1.0f) + 2.0f);
+}
+/* Calculates the rcpQ (i.e. 1/Q) coefficient for filters, using the frequency
+ * multiple (i.e. ref_freq / sampling_freq) and bandwidth.
+ * 0 < freq_mult < 0.5.
+ */
+inline ALfloat calc_rcpQ_from_bandwidth(ALfloat freq_mult, ALfloat bandwidth)
+{
+ ALfloat w0 = F_TAU * freq_mult;
+ return 2.0f*sinhf(logf(2.0f)/2.0f*bandwidth*w0/sinf(w0));
+}
+
void ALfilterState_clear(ALfilterState *filter);
-void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat gain, ALfloat freq_mult, ALfloat bandwidth);
+void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat gain, ALfloat freq_mult, ALfloat rcpQ);
inline ALfloat ALfilterState_processSingle(ALfilterState *filter, ALfloat sample)
{
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index 126fffb5..27cf6713 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -16,18 +16,7 @@
#include "hrtf.h"
#include "align.h"
-
-
-#define F_PI (3.14159265358979323846f)
-#define F_PI_2 (1.57079632679489661923f)
-#define F_TAU (6.28318530717958647692f)
-
-#ifndef FLT_EPSILON
-#define FLT_EPSILON (1.19209290e-07f)
-#endif
-
-#define DEG2RAD(x) ((ALfloat)(x) * (F_PI/180.0f))
-#define RAD2DEG(x) ((ALfloat)(x) * (180.0f/F_PI))
+#include "math_defs.h"
#define MAX_PITCH (255)