diff options
author | Chris Robinson <[email protected]> | 2018-04-21 23:23:46 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-04-21 23:23:46 -0700 |
commit | 9575eebac43c4401a1e82215e10700a01dd8be55 (patch) | |
tree | efb6c9261b41eb191fb48fab4e7a39e01c54d472 | |
parent | ace8e648509a1afa587a4e6c778e37a2e854e496 (diff) |
Move the bnad-splitter filters to a separate source
-rw-r--r-- | Alc/ALu.c | 1 | ||||
-rw-r--r-- | Alc/bformatdec.c | 102 | ||||
-rw-r--r-- | Alc/bformatdec.h | 34 | ||||
-rw-r--r-- | Alc/filters/splitter.c | 107 | ||||
-rw-r--r-- | Alc/filters/splitter.h | 40 | ||||
-rw-r--r-- | Alc/hrtf.c | 2 | ||||
-rw-r--r-- | Alc/panning.c | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 1 |
8 files changed, 152 insertions, 136 deletions
@@ -39,6 +39,7 @@ #include "bformatdec.h" #include "static_assert.h" #include "ringbuffer.h" +#include "filters/splitter.h" #include "mixer/defs.h" #include "fpu_modes.h" diff --git a/Alc/bformatdec.c b/Alc/bformatdec.c index 7ab315c3..dcde7d70 100644 --- a/Alc/bformatdec.c +++ b/Alc/bformatdec.c @@ -3,6 +3,7 @@ #include "bformatdec.h" #include "ambdec.h" +#include "filters/splitter.h" #include "alu.h" #include "bool.h" @@ -10,107 +11,6 @@ #include "almalloc.h" -void bandsplit_init(BandSplitter *splitter, ALfloat f0norm) -{ - ALfloat w = f0norm * F_TAU; - ALfloat cw = cosf(w); - if(cw > FLT_EPSILON) - splitter->coeff = (sinf(w) - 1.0f) / cw; - else - splitter->coeff = cw * -0.5f; - - splitter->lp_z1 = 0.0f; - splitter->lp_z2 = 0.0f; - splitter->hp_z1 = 0.0f; -} - -void bandsplit_clear(BandSplitter *splitter) -{ - splitter->lp_z1 = 0.0f; - splitter->lp_z2 = 0.0f; - splitter->hp_z1 = 0.0f; -} - -void bandsplit_process(BandSplitter *splitter, ALfloat *restrict hpout, ALfloat *restrict lpout, - const ALfloat *input, ALsizei count) -{ - ALfloat lp_coeff, hp_coeff, lp_y, hp_y, d; - ALfloat lp_z1, lp_z2, hp_z1; - ALsizei i; - - hp_coeff = splitter->coeff; - lp_coeff = splitter->coeff*0.5f + 0.5f; - lp_z1 = splitter->lp_z1; - lp_z2 = splitter->lp_z2; - hp_z1 = splitter->hp_z1; - for(i = 0;i < count;i++) - { - ALfloat in = input[i]; - - /* Low-pass sample processing. */ - d = (in - lp_z1) * lp_coeff; - lp_y = lp_z1 + d; - lp_z1 = lp_y + d; - - d = (lp_y - lp_z2) * lp_coeff; - lp_y = lp_z2 + d; - lp_z2 = lp_y + d; - - lpout[i] = lp_y; - - /* All-pass sample processing. */ - d = in - hp_coeff*hp_z1; - hp_y = hp_z1 + hp_coeff*d; - hp_z1 = d; - - /* High-pass generated from removing low-passed output. */ - hpout[i] = hp_y - lp_y; - } - splitter->lp_z1 = lp_z1; - splitter->lp_z2 = lp_z2; - splitter->hp_z1 = hp_z1; -} - - -void splitterap_init(SplitterAllpass *splitter, ALfloat f0norm) -{ - ALfloat w = f0norm * F_TAU; - ALfloat cw = cosf(w); - if(cw > FLT_EPSILON) - splitter->coeff = (sinf(w) - 1.0f) / cw; - else - splitter->coeff = cw * -0.5f; - - splitter->z1 = 0.0f; -} - -void splitterap_clear(SplitterAllpass *splitter) -{ - splitter->z1 = 0.0f; -} - -void splitterap_process(SplitterAllpass *splitter, ALfloat *restrict samples, ALsizei count) -{ - ALfloat coeff, d, x; - ALfloat z1; - ALsizei i; - - coeff = splitter->coeff; - z1 = splitter->z1; - for(i = 0;i < count;i++) - { - x = samples[i]; - - d = x - coeff*z1; - x = z1 + coeff*d; - z1 = d; - - samples[i] = x; - } - splitter->z1 = z1; -} - - /* NOTE: These are scale factors as applied to Ambisonics content. Decoder * coefficients should be divided by these values to get proper N3D scalings. */ diff --git a/Alc/bformatdec.h b/Alc/bformatdec.h index a6ca2209..2d7d1d62 100644 --- a/Alc/bformatdec.h +++ b/Alc/bformatdec.h @@ -54,38 +54,4 @@ void ambiup_reset(struct AmbiUpsampler *ambiup, const ALCdevice *device, ALfloat void ambiup_process(struct AmbiUpsampler *ambiup, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo); - -/* Band splitter. Splits a signal into two phase-matching frequency bands. */ -typedef struct BandSplitter { - ALfloat coeff; - ALfloat lp_z1; - ALfloat lp_z2; - ALfloat hp_z1; -} BandSplitter; - -void bandsplit_init(BandSplitter *splitter, ALfloat f0norm); -void bandsplit_clear(BandSplitter *splitter); -void bandsplit_process(BandSplitter *splitter, ALfloat *restrict hpout, ALfloat *restrict lpout, - const ALfloat *input, ALsizei count); - -/* The all-pass portion of the band splitter. Applies the same phase shift - * without splitting the signal. - */ -typedef struct SplitterAllpass { - ALfloat coeff; - ALfloat z1; -} SplitterAllpass; - -void splitterap_init(SplitterAllpass *splitter, ALfloat f0norm); -void splitterap_clear(SplitterAllpass *splitter); -void splitterap_process(SplitterAllpass *splitter, ALfloat *restrict samples, ALsizei count); - - -typedef struct FrontStablizer { - SplitterAllpass APFilter[MAX_OUTPUT_CHANNELS]; - BandSplitter LFilter, RFilter; - alignas(16) ALfloat LSplit[2][BUFFERSIZE]; - alignas(16) ALfloat RSplit[2][BUFFERSIZE]; -} FrontStablizer; - #endif /* BFORMATDEC_H */ diff --git a/Alc/filters/splitter.c b/Alc/filters/splitter.c new file mode 100644 index 00000000..524bcc1d --- /dev/null +++ b/Alc/filters/splitter.c @@ -0,0 +1,107 @@ + +#include "config.h" + +#include "splitter.h" + +#include "math_defs.h" + + +void bandsplit_init(BandSplitter *splitter, ALfloat f0norm) +{ + ALfloat w = f0norm * F_TAU; + ALfloat cw = cosf(w); + if(cw > FLT_EPSILON) + splitter->coeff = (sinf(w) - 1.0f) / cw; + else + splitter->coeff = cw * -0.5f; + + splitter->lp_z1 = 0.0f; + splitter->lp_z2 = 0.0f; + splitter->hp_z1 = 0.0f; +} + +void bandsplit_clear(BandSplitter *splitter) +{ + splitter->lp_z1 = 0.0f; + splitter->lp_z2 = 0.0f; + splitter->hp_z1 = 0.0f; +} + +void bandsplit_process(BandSplitter *splitter, ALfloat *restrict hpout, ALfloat *restrict lpout, + const ALfloat *input, ALsizei count) +{ + ALfloat lp_coeff, hp_coeff, lp_y, hp_y, d; + ALfloat lp_z1, lp_z2, hp_z1; + ALsizei i; + + hp_coeff = splitter->coeff; + lp_coeff = splitter->coeff*0.5f + 0.5f; + lp_z1 = splitter->lp_z1; + lp_z2 = splitter->lp_z2; + hp_z1 = splitter->hp_z1; + for(i = 0;i < count;i++) + { + ALfloat in = input[i]; + + /* Low-pass sample processing. */ + d = (in - lp_z1) * lp_coeff; + lp_y = lp_z1 + d; + lp_z1 = lp_y + d; + + d = (lp_y - lp_z2) * lp_coeff; + lp_y = lp_z2 + d; + lp_z2 = lp_y + d; + + lpout[i] = lp_y; + + /* All-pass sample processing. */ + d = in - hp_coeff*hp_z1; + hp_y = hp_z1 + hp_coeff*d; + hp_z1 = d; + + /* High-pass generated from removing low-passed output. */ + hpout[i] = hp_y - lp_y; + } + splitter->lp_z1 = lp_z1; + splitter->lp_z2 = lp_z2; + splitter->hp_z1 = hp_z1; +} + + +void splitterap_init(SplitterAllpass *splitter, ALfloat f0norm) +{ + ALfloat w = f0norm * F_TAU; + ALfloat cw = cosf(w); + if(cw > FLT_EPSILON) + splitter->coeff = (sinf(w) - 1.0f) / cw; + else + splitter->coeff = cw * -0.5f; + + splitter->z1 = 0.0f; +} + +void splitterap_clear(SplitterAllpass *splitter) +{ + splitter->z1 = 0.0f; +} + +void splitterap_process(SplitterAllpass *splitter, ALfloat *restrict samples, ALsizei count) +{ + ALfloat coeff, d, x; + ALfloat z1; + ALsizei i; + + coeff = splitter->coeff; + z1 = splitter->z1; + for(i = 0;i < count;i++) + { + x = samples[i]; + + d = x - coeff*z1; + x = z1 + coeff*d; + z1 = d; + + samples[i] = x; + } + splitter->z1 = z1; +} diff --git a/Alc/filters/splitter.h b/Alc/filters/splitter.h new file mode 100644 index 00000000..a788bc3e --- /dev/null +++ b/Alc/filters/splitter.h @@ -0,0 +1,40 @@ +#ifndef FILTER_SPLITTER_H +#define FILTER_SPLITTER_H + +#include "alMain.h" + + +/* Band splitter. Splits a signal into two phase-matching frequency bands. */ +typedef struct BandSplitter { + ALfloat coeff; + ALfloat lp_z1; + ALfloat lp_z2; + ALfloat hp_z1; +} BandSplitter; + +void bandsplit_init(BandSplitter *splitter, ALfloat f0norm); +void bandsplit_clear(BandSplitter *splitter); +void bandsplit_process(BandSplitter *splitter, ALfloat *restrict hpout, ALfloat *restrict lpout, + const ALfloat *input, ALsizei count); + +/* The all-pass portion of the band splitter. Applies the same phase shift + * without splitting the signal. + */ +typedef struct SplitterAllpass { + ALfloat coeff; + ALfloat z1; +} SplitterAllpass; + +void splitterap_init(SplitterAllpass *splitter, ALfloat f0norm); +void splitterap_clear(SplitterAllpass *splitter); +void splitterap_process(SplitterAllpass *splitter, ALfloat *restrict samples, ALsizei count); + + +typedef struct FrontStablizer { + SplitterAllpass APFilter[MAX_OUTPUT_CHANNELS]; + BandSplitter LFilter, RFilter; + alignas(16) ALfloat LSplit[2][BUFFERSIZE]; + alignas(16) ALfloat RSplit[2][BUFFERSIZE]; +} FrontStablizer; + +#endif /* FILTER_SPLITTER_H */ @@ -28,9 +28,9 @@ #include "alMain.h" #include "alSource.h" #include "alu.h" -#include "bformatdec.h" #include "hrtf.h" #include "alconfig.h" +#include "filters/splitter.h" #include "compat.h" #include "almalloc.h" diff --git a/Alc/panning.c b/Alc/panning.c index 50e5b530..5ff37d0a 100644 --- a/Alc/panning.c +++ b/Alc/panning.c @@ -33,6 +33,7 @@ #include "bool.h" #include "ambdec.h" #include "bformatdec.h" +#include "filters/splitter.h" #include "uhjfilter.h" #include "bs2b.h" diff --git a/CMakeLists.txt b/CMakeLists.txt index 69e5528c..5087fc2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -736,6 +736,7 @@ SET(ALC_OBJS Alc/ALc.c Alc/effects/reverb.c Alc/filters/filter.c Alc/filters/nfc.c + Alc/filters/splitter.c Alc/helpers.c Alc/hrtf.c Alc/uhjfilter.c |