diff options
author | Chris Robinson <[email protected]> | 2014-06-11 09:57:48 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-06-11 09:57:48 -0700 |
commit | 4c706f59d9b21e1870c9fa4d7705b5bcebb834e6 (patch) | |
tree | db2229a2ffa670e69b234580b72c155d0dcd785a | |
parent | dfded9595cb878c350a8852066601a921a3c2c44 (diff) |
Use floats for the BS2B filter
-rw-r--r-- | Alc/bs2b.c | 68 | ||||
-rw-r--r-- | OpenAL32/Include/bs2b.h | 20 |
2 files changed, 44 insertions, 44 deletions
@@ -27,6 +27,7 @@ #include <string.h> #include "bs2b.h" +#include "alu.h" #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -35,57 +36,56 @@ /* Set up all data. */ static void init(struct bs2b *bs2b) { - double Fc_lo, Fc_hi; - double G_lo, G_hi; - double x; + float Fc_lo, Fc_hi; + float G_lo, G_hi; + float x; - if(bs2b->srate > 192000 || bs2b->srate < 2000) - bs2b->srate = BS2B_DEFAULT_SRATE; + bs2b->srate = clampi(bs2b->srate, 2000, 192000); switch(bs2b->level) { case BS2B_LOW_CLEVEL: /* Low crossfeed level */ - Fc_lo = 360.0; - Fc_hi = 501.0; - G_lo = 0.398107170553497; - G_hi = 0.205671765275719; + Fc_lo = 360.0f; + Fc_hi = 501.0f; + G_lo = 0.398107170553497f; + G_hi = 0.205671765275719f; break; case BS2B_MIDDLE_CLEVEL: /* Middle crossfeed level */ - Fc_lo = 500.0; - Fc_hi = 711.0; - G_lo = 0.459726988530872; - G_hi = 0.228208484414988; + Fc_lo = 500.0f; + Fc_hi = 711.0f; + G_lo = 0.459726988530872f; + G_hi = 0.228208484414988f; break; case BS2B_HIGH_CLEVEL: /* High crossfeed level (virtual speakers are closer to itself) */ - Fc_lo = 700.0; - Fc_hi = 1021.0; - G_lo = 0.530884444230988; - G_hi = 0.250105790667544; + Fc_lo = 700.0f; + Fc_hi = 1021.0f; + G_lo = 0.530884444230988f; + G_hi = 0.250105790667544f; break; case BS2B_LOW_ECLEVEL: /* Low easy crossfeed level */ - Fc_lo = 360.0; - Fc_hi = 494.0; - G_lo = 0.316227766016838; - G_hi = 0.168236228897329; + Fc_lo = 360.0f; + Fc_hi = 494.0f; + G_lo = 0.316227766016838f; + G_hi = 0.168236228897329f; break; case BS2B_MIDDLE_ECLEVEL: /* Middle easy crossfeed level */ - Fc_lo = 500.0; - Fc_hi = 689.0; - G_lo = 0.354813389233575; - G_hi = 0.187169483835901; + Fc_lo = 500.0f; + Fc_hi = 689.0f; + G_lo = 0.354813389233575f; + G_hi = 0.187169483835901f; break; default: /* High easy crossfeed level */ bs2b->level = BS2B_HIGH_ECLEVEL; - Fc_lo = 700.0; - Fc_hi = 975.0; - G_lo = 0.398107170553497; - G_hi = 0.205671765275719; + Fc_lo = 700.0f; + Fc_hi = 975.0f; + G_lo = 0.398107170553497f; + G_hi = 0.205671765275719f; break; } /* switch */ @@ -94,16 +94,16 @@ static void init(struct bs2b *bs2b) * $x = exp(-1 / $d); */ - x = exp(-2.0 * M_PI * Fc_lo / bs2b->srate); + x = expf(-2.0f * F_PI * Fc_lo / bs2b->srate); bs2b->b1_lo = x; - bs2b->a0_lo = G_lo * (1.0 - x); + bs2b->a0_lo = G_lo * (1.0f - x); - x = exp(-2.0 * M_PI * Fc_hi / bs2b->srate); + x = expf(-2.0f * F_PI * Fc_hi / bs2b->srate); bs2b->b1_hi = x; - bs2b->a0_hi = 1.0 - G_hi * (1.0 - x); + bs2b->a0_hi = 1.0f - G_hi * (1.0f - x); bs2b->a1_hi = -x; - bs2b->gain = 1.0f / (float)(1.0 - G_hi + G_lo); + bs2b->gain = 1.0f / (1.0f - G_hi + G_lo); } /* init */ /* Exported functions. diff --git a/OpenAL32/Include/bs2b.h b/OpenAL32/Include/bs2b.h index 2cc76931..47d9d674 100644 --- a/OpenAL32/Include/bs2b.h +++ b/OpenAL32/Include/bs2b.h @@ -51,13 +51,13 @@ struct bs2b { int srate; /* Sample rate (Hz) */ /* Lowpass IIR filter coefficients */ - double a0_lo; - double b1_lo; + float a0_lo; + float b1_lo; /* Highboost IIR filter coefficients */ - double a0_hi; - double a1_hi; - double b1_hi; + float a0_hi; + float a1_hi; + float b1_hi; /* Global gain against overloading */ float gain; @@ -66,9 +66,9 @@ struct bs2b { * [0] - first channel, [1] - second channel */ struct t_last_sample { - double asis[2]; - double lo[2]; - double hi[2]; + float asis[2]; + float lo[2]; + float hi[2]; } last_sample; }; @@ -120,8 +120,8 @@ inline void bs2b_cross_feed(struct bs2b *bs2b, float *restrict samples) bs2b->last_sample.asis[1] = samples[1]; /* Crossfeed */ - samples[0] = (float)(bs2b->last_sample.hi[0] + bs2b->last_sample.lo[1]); - samples[1] = (float)(bs2b->last_sample.hi[1] + bs2b->last_sample.lo[0]); + samples[0] = bs2b->last_sample.hi[0] + bs2b->last_sample.lo[1]; + samples[1] = bs2b->last_sample.hi[1] + bs2b->last_sample.lo[0]; /* Bass boost cause allpass attenuation */ samples[0] *= bs2b->gain; |