2022-11-15 23:49:51 +00:00
|
|
|
/*
|
|
|
|
* Brickworks
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 Orastron Srl unipersonale
|
|
|
|
*
|
|
|
|
* Brickworks is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3 of the License.
|
|
|
|
*
|
|
|
|
* Brickworks is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
*
|
|
|
|
* File author: Stefano D'Angelo
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* module_type {{{ dsp }}}
|
2022-11-19 01:25:38 +00:00
|
|
|
* version {{{ 0.2.0 }}}
|
2022-11-15 23:49:51 +00:00
|
|
|
* requires {{{ bw_config bw_common }}}
|
|
|
|
* description {{{
|
|
|
|
* Post-filter to decolorate oscillator waveshapers when antialiasing is on.
|
|
|
|
*
|
|
|
|
* This filter can be added in series of oscillator waveshapers that use
|
|
|
|
* PolyBLEP antialiasing (i.e., [bw_osc_saw](bw_osc_saw),
|
|
|
|
* [bw_osc_pulse](bw_osc_pulse), [bw_osc_tri](bw_osc_tri)) to compensate for
|
|
|
|
* high-frequency attenuation.
|
|
|
|
* }}}
|
|
|
|
* changelog {{{
|
|
|
|
* <ul>
|
2022-11-19 01:25:38 +00:00
|
|
|
* <li>Version <strong>0.2.0</strong>:
|
|
|
|
* <ul>
|
2022-11-28 17:31:52 +00:00
|
|
|
* <li>Refactored API.</li>
|
2022-11-19 01:25:38 +00:00
|
|
|
* </ul>
|
|
|
|
* </li>
|
2022-11-15 23:49:51 +00:00
|
|
|
* <li>Version <strong>0.1.0</strong>:
|
|
|
|
* <ul>
|
|
|
|
* <li>First release.</li>
|
|
|
|
* </ul>
|
|
|
|
* </li>
|
|
|
|
* </ul>
|
|
|
|
* }}}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BW_OSC_FILT_H
|
|
|
|
#define _BW_OSC_FILT_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-11-28 17:31:52 +00:00
|
|
|
#include <bw_common.h>
|
2022-11-15 23:49:51 +00:00
|
|
|
|
2022-11-28 17:31:52 +00:00
|
|
|
/*! api {{{
|
|
|
|
* #### bw_osc_filt_state
|
2022-11-15 23:49:51 +00:00
|
|
|
* ```>>> */
|
2022-11-28 17:31:52 +00:00
|
|
|
typedef struct _bw_osc_filt_state bw_osc_filt_state;
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
2022-11-28 17:31:52 +00:00
|
|
|
* State
|
2022-11-15 23:49:51 +00:00
|
|
|
* >>> */
|
|
|
|
|
|
|
|
/*! ...
|
|
|
|
* #### bw_osc_filt_reset()
|
|
|
|
* ```>>> */
|
2022-11-28 17:31:52 +00:00
|
|
|
static inline void bw_osc_filt_reset_state(bw_osc_filt_state *BW_RESTRICT state);
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Resets the given `instance` to its initial state.
|
|
|
|
* >>> */
|
|
|
|
|
2022-11-28 17:31:52 +00:00
|
|
|
static inline float bw_osc_filt_process1(bw_osc_filt_state *BW_RESTRICT state, float x);
|
|
|
|
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! ...
|
|
|
|
* #### bw_osc_filt_process()
|
|
|
|
* ```>>> */
|
2022-11-28 17:31:52 +00:00
|
|
|
static inline void bw_osc_filt_process(bw_osc_filt_state *BW_RESTRICT state, const float *x, float* y, int n_samples);
|
2022-11-15 23:49:51 +00:00
|
|
|
/*! <<<```
|
|
|
|
* Lets the given `instance` process `n_samples` samples from the input
|
|
|
|
* buffer `x` and fills the corresponding `n_samples` samples in the output
|
|
|
|
* buffer `y`.
|
|
|
|
* }}} */
|
|
|
|
|
2022-11-28 17:31:52 +00:00
|
|
|
/*** Implementation ***/
|
|
|
|
|
|
|
|
/* WARNING: This part of the file is not part of the public API. Its content may
|
|
|
|
* change at any time in future versions. Please, do not use it directly. */
|
2022-11-19 01:25:38 +00:00
|
|
|
|
2022-11-28 17:31:52 +00:00
|
|
|
struct _bw_osc_filt_state {
|
2022-11-19 01:25:38 +00:00
|
|
|
float x_z1;
|
|
|
|
float y_z1;
|
|
|
|
};
|
|
|
|
|
2022-11-28 17:31:52 +00:00
|
|
|
static inline void bw_osc_filt_reset_state(bw_osc_filt_state *BW_RESTRICT state) {
|
|
|
|
state->x_z1 = 0.f;
|
|
|
|
state->y_z1 = 0.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline float bw_osc_filt_process1(bw_osc_filt_state *BW_RESTRICT state, float x) {
|
|
|
|
const float y = 1.371308261611209f * x + 0.08785458027104826f * state->x_z1 - 4.591628418822578e-1f * state->y_z1;
|
|
|
|
state->x_z1 = x;
|
|
|
|
state->y_z1 = y;
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void bw_osc_filt_process(bw_osc_filt_state *BW_RESTRICT state, const float *x, float* y, int n_samples) {
|
|
|
|
for (int i = 0; i < n_samples; i++)
|
|
|
|
y[i] = bw_osc_filt_process1(state, x[i]);
|
|
|
|
}
|
2022-11-19 01:25:38 +00:00
|
|
|
|
2022-11-15 23:49:51 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|