fix bw_src_int + use it in fx_satur

This commit is contained in:
Stefano D'Angelo 2023-03-14 16:46:13 +01:00
parent 02a964d453
commit d8ac7cadcc
4 changed files with 28 additions and 6 deletions

1
TODO
View File

@ -31,6 +31,7 @@ code:
* MEM_REQ_ROUGH() macro?
* use BW_SIZE_T, check constant types
* web examples: need to export memset?
* bw_satur gain compensation to divide by actual gain (derivative) rather than gain parameter?
* cite papers, thank authors
build system:

View File

@ -22,19 +22,30 @@
void bw_example_fx_satur_init(bw_example_fx_satur *instance) {
bw_satur_init(&instance->satur_coeffs);
bw_src_int_init(&instance->src_up_coeffs, 2);
bw_src_int_init(&instance->src_down_coeffs, -2);
}
void bw_example_fx_satur_set_sample_rate(bw_example_fx_satur *instance, float sample_rate) {
bw_satur_set_sample_rate(&instance->satur_coeffs, sample_rate);
bw_satur_set_sample_rate(&instance->satur_coeffs, 2.f * sample_rate);
}
void bw_example_fx_satur_reset(bw_example_fx_satur *instance) {
bw_satur_reset_coeffs(&instance->satur_coeffs);
bw_satur_reset_state(&instance->satur_coeffs, &instance->satur_state);
bw_src_int_reset_state(&instance->src_up_coeffs, &instance->src_up_state, 0.f);
bw_src_int_reset_state(&instance->src_down_coeffs, &instance->src_down_state, 0.f);
}
void bw_example_fx_satur_process(bw_example_fx_satur *instance, const float** x, float** y, int n_samples) {
bw_satur_process(&instance->satur_coeffs, &instance->satur_state, x[0], y[0], n_samples);
int i = 0;
while (i < n_samples) {
int n = bw_mini32(n_samples - i, BUF_SIZE >> 1);
bw_src_int_process(&instance->src_up_coeffs, &instance->src_up_state, x[0] + i, instance->buf, n);
bw_satur_process(&instance->satur_coeffs, &instance->satur_state, instance->buf, instance->buf, n << 1);
bw_src_int_process(&instance->src_down_coeffs, &instance->src_down_state, instance->buf, y[0] + i, n << 1);
i += n;
}
}
void bw_example_fx_satur_set_parameter(bw_example_fx_satur *instance, int index, float value) {

View File

@ -26,6 +26,7 @@ extern "C" {
#endif
#include <bw_satur.h>
#include <bw_src_int.h>
enum {
p_bias,
@ -33,13 +34,22 @@ enum {
p_n
};
#define BUF_SIZE 32
struct _bw_example_fx_satur {
// Sub-components
bw_satur_coeffs satur_coeffs;
bw_satur_state satur_state;
bw_satur_coeffs satur_coeffs;
bw_satur_state satur_state;
bw_src_int_coeffs src_up_coeffs;
bw_src_int_state src_up_state;
bw_src_int_coeffs src_down_coeffs;
bw_src_int_state src_down_state;
// Parameters
float params[p_n];
// Buffers
float buf[BUF_SIZE];
};
typedef struct _bw_example_fx_satur bw_example_fx_satur;

View File

@ -138,7 +138,7 @@ static inline void bw_src_int_reset_state(const bw_src_int_coeffs *BW_RESTRICT c
state->z2 = state->z1;
state->z3 = state->z2;
state->z4 = state->z3;
state->i = -coeffs->ratio;
state->i = 1;
} else {
// DF-I
state->z1 = x0;
@ -153,7 +153,7 @@ static inline void bw_src_int_reset_state(const bw_src_int_coeffs *BW_RESTRICT c
}
static inline int bw_src_int_process(const bw_src_int_coeffs *BW_RESTRICT coeffs, bw_src_int_state *BW_RESTRICT state, const float *x, float *y, int n_in_samples) {
n = 0;
int n = 0;
if (coeffs->ratio < 0) {
for (int i = 0; i < n_in_samples; i++) {
// DF-II