improve arguments in bw_buf + remove BW_SIZE_T and use C++ buf api in examples

This commit is contained in:
Stefano D'Angelo 2023-08-11 16:54:01 +02:00
parent 55a78a5ab4
commit 3a948b1c99
20 changed files with 95 additions and 93 deletions

1
TODO
View File

@ -41,7 +41,6 @@ code:
* better src filter * better src filter
* bw_env_gen process_multi gate const? * bw_env_gen process_multi gate const?
* c++ get coeffs/state? or public? src nIn/OutSamples case (array vs single value), delay read/write, process1? process single? * c++ get coeffs/state? or public? src nIn/OutSamples case (array vs single value), delay read/write, process1? process single?
* bw_buf invert src dest order?
* check unititialized warnings * check unititialized warnings
* clearly specify that state is tied to a particular set of coeffs (1:N) * clearly specify that state is tied to a particular set of coeffs (1:N)
* modulation vs process (multi) no update (post 1.0.0)??? * modulation vs process (multi) no update (post 1.0.0)???

View File

@ -32,7 +32,7 @@ void bw_example_fx_chorus_set_sample_rate(bw_example_fx_chorus *instance, float
bw_chorus_set_sample_rate(&instance->chorus_coeffs, sample_rate); bw_chorus_set_sample_rate(&instance->chorus_coeffs, sample_rate);
} }
BW_SIZE_T bw_example_fx_chorus_mem_req(bw_example_fx_chorus *instance) { size_t bw_example_fx_chorus_mem_req(bw_example_fx_chorus *instance) {
return bw_chorus_mem_req(&instance->chorus_coeffs); return bw_chorus_mem_req(&instance->chorus_coeffs);
} }

View File

@ -47,7 +47,7 @@ typedef struct _bw_example_fx_chorus bw_example_fx_chorus;
void bw_example_fx_chorus_init(bw_example_fx_chorus *instance); void bw_example_fx_chorus_init(bw_example_fx_chorus *instance);
void bw_example_fx_chorus_set_sample_rate(bw_example_fx_chorus *instance, float sample_rate); void bw_example_fx_chorus_set_sample_rate(bw_example_fx_chorus *instance, float sample_rate);
BW_SIZE_T bw_example_fx_chorus_mem_req(bw_example_fx_chorus *instance); size_t bw_example_fx_chorus_mem_req(bw_example_fx_chorus *instance);
void bw_example_fx_chorus_mem_set(bw_example_fx_chorus *instance, void *mem); void bw_example_fx_chorus_mem_set(bw_example_fx_chorus *instance, void *mem);
void bw_example_fx_chorus_reset(bw_example_fx_chorus *instance); void bw_example_fx_chorus_reset(bw_example_fx_chorus *instance);
void bw_example_fx_chorus_process(bw_example_fx_chorus *instance, const float** x, float** y, int n_samples); void bw_example_fx_chorus_process(bw_example_fx_chorus *instance, const float** x, float** y, int n_samples);

View File

@ -28,7 +28,7 @@ void bw_example_fx_comb_set_sample_rate(bw_example_fx_comb *instance, float samp
bw_comb_set_sample_rate(&instance->comb_coeffs, sample_rate); bw_comb_set_sample_rate(&instance->comb_coeffs, sample_rate);
} }
BW_SIZE_T bw_example_fx_comb_mem_req(bw_example_fx_comb *instance) { size_t bw_example_fx_comb_mem_req(bw_example_fx_comb *instance) {
return bw_comb_mem_req(&instance->comb_coeffs); return bw_comb_mem_req(&instance->comb_coeffs);
} }

View File

@ -50,7 +50,7 @@ typedef struct _bw_example_fx_comb bw_example_fx_comb;
void bw_example_fx_comb_init(bw_example_fx_comb *instance); void bw_example_fx_comb_init(bw_example_fx_comb *instance);
void bw_example_fx_comb_set_sample_rate(bw_example_fx_comb *instance, float sample_rate); void bw_example_fx_comb_set_sample_rate(bw_example_fx_comb *instance, float sample_rate);
BW_SIZE_T bw_example_fx_comb_mem_req(bw_example_fx_comb *instance); size_t bw_example_fx_comb_mem_req(bw_example_fx_comb *instance);
void bw_example_fx_comb_mem_set(bw_example_fx_comb *instance, void *mem); void bw_example_fx_comb_mem_set(bw_example_fx_comb *instance, void *mem);
void bw_example_fx_comb_reset(bw_example_fx_comb *instance); void bw_example_fx_comb_reset(bw_example_fx_comb *instance);
void bw_example_fx_comb_process(bw_example_fx_comb *instance, const float** x, float** y, int n_samples); void bw_example_fx_comb_process(bw_example_fx_comb *instance, const float** x, float** y, int n_samples);

View File

@ -28,7 +28,7 @@ void bw_example_fx_delay_set_sample_rate(bw_example_fx_delay *instance, float sa
bw_delay_set_sample_rate(&instance->delay_coeffs, sample_rate); bw_delay_set_sample_rate(&instance->delay_coeffs, sample_rate);
} }
BW_SIZE_T bw_example_fx_delay_mem_req(bw_example_fx_delay *instance) { size_t bw_example_fx_delay_mem_req(bw_example_fx_delay *instance) {
return bw_delay_mem_req(&instance->delay_coeffs); return bw_delay_mem_req(&instance->delay_coeffs);
} }

View File

@ -46,7 +46,7 @@ typedef struct _bw_example_fx_delay bw_example_fx_delay;
void bw_example_fx_delay_init(bw_example_fx_delay *instance); void bw_example_fx_delay_init(bw_example_fx_delay *instance);
void bw_example_fx_delay_set_sample_rate(bw_example_fx_delay *instance, float sample_rate); void bw_example_fx_delay_set_sample_rate(bw_example_fx_delay *instance, float sample_rate);
BW_SIZE_T bw_example_fx_delay_mem_req(bw_example_fx_delay *instance); size_t bw_example_fx_delay_mem_req(bw_example_fx_delay *instance);
void bw_example_fx_delay_mem_set(bw_example_fx_delay *instance, void *mem); void bw_example_fx_delay_mem_set(bw_example_fx_delay *instance, void *mem);
void bw_example_fx_delay_reset(bw_example_fx_delay *instance); void bw_example_fx_delay_reset(bw_example_fx_delay *instance);
void bw_example_fx_delay_process(bw_example_fx_delay *instance, const float** x, float** y, int n_samples); void bw_example_fx_delay_process(bw_example_fx_delay *instance, const float** x, float** y, int n_samples);

View File

@ -32,7 +32,7 @@ void bw_example_fx_flanger_set_sample_rate(bw_example_fx_flanger *instance, floa
bw_chorus_set_sample_rate(&instance->chorus_coeffs, sample_rate); bw_chorus_set_sample_rate(&instance->chorus_coeffs, sample_rate);
} }
BW_SIZE_T bw_example_fx_flanger_mem_req(bw_example_fx_flanger *instance) { size_t bw_example_fx_flanger_mem_req(bw_example_fx_flanger *instance) {
return bw_chorus_mem_req(&instance->chorus_coeffs); return bw_chorus_mem_req(&instance->chorus_coeffs);
} }

View File

@ -47,7 +47,7 @@ typedef struct _bw_example_fx_flanger bw_example_fx_flanger;
void bw_example_fx_flanger_init(bw_example_fx_flanger *instance); void bw_example_fx_flanger_init(bw_example_fx_flanger *instance);
void bw_example_fx_flanger_set_sample_rate(bw_example_fx_flanger *instance, float sample_rate); void bw_example_fx_flanger_set_sample_rate(bw_example_fx_flanger *instance, float sample_rate);
BW_SIZE_T bw_example_fx_flanger_mem_req(bw_example_fx_flanger *instance); size_t bw_example_fx_flanger_mem_req(bw_example_fx_flanger *instance);
void bw_example_fx_flanger_mem_set(bw_example_fx_flanger *instance, void *mem); void bw_example_fx_flanger_mem_set(bw_example_fx_flanger *instance, void *mem);
void bw_example_fx_flanger_reset(bw_example_fx_flanger *instance); void bw_example_fx_flanger_reset(bw_example_fx_flanger *instance);
void bw_example_fx_flanger_process(bw_example_fx_flanger *instance, const float** x, float** y, int n_samples); void bw_example_fx_flanger_process(bw_example_fx_flanger *instance, const float** x, float** y, int n_samples);

View File

@ -28,7 +28,7 @@ void bw_example_fx_reverb_set_sample_rate(bw_example_fx_reverb *instance, float
bw_reverb_set_sample_rate(&instance->reverb_coeffs, sample_rate); bw_reverb_set_sample_rate(&instance->reverb_coeffs, sample_rate);
} }
BW_SIZE_T bw_example_fx_reverb_mem_req(bw_example_fx_reverb *instance) { size_t bw_example_fx_reverb_mem_req(bw_example_fx_reverb *instance) {
return bw_reverb_mem_req(&instance->reverb_coeffs); return bw_reverb_mem_req(&instance->reverb_coeffs);
} }

View File

@ -48,7 +48,7 @@ typedef struct _bw_example_fx_reverb bw_example_fx_reverb;
void bw_example_fx_reverb_init(bw_example_fx_reverb *instance); void bw_example_fx_reverb_init(bw_example_fx_reverb *instance);
void bw_example_fx_reverb_set_sample_rate(bw_example_fx_reverb *instance, float sample_rate); void bw_example_fx_reverb_set_sample_rate(bw_example_fx_reverb *instance, float sample_rate);
BW_SIZE_T bw_example_fx_reverb_mem_req(bw_example_fx_reverb *instance); size_t bw_example_fx_reverb_mem_req(bw_example_fx_reverb *instance);
void bw_example_fx_reverb_mem_set(bw_example_fx_reverb *instance, void *mem); void bw_example_fx_reverb_mem_set(bw_example_fx_reverb *instance, void *mem);
void bw_example_fx_reverb_reset(bw_example_fx_reverb *instance); void bw_example_fx_reverb_reset(bw_example_fx_reverb *instance);
void bw_example_fx_reverb_process(bw_example_fx_reverb *instance, const float** x, float** y, int n_samples); void bw_example_fx_reverb_process(bw_example_fx_reverb *instance, const float** x, float** y, int n_samples);

View File

@ -31,7 +31,7 @@ void bw_example_fx_vibrato_set_sample_rate(bw_example_fx_vibrato *instance, floa
bw_chorus_set_sample_rate(&instance->chorus_coeffs, sample_rate); bw_chorus_set_sample_rate(&instance->chorus_coeffs, sample_rate);
} }
BW_SIZE_T bw_example_fx_vibrato_mem_req(bw_example_fx_vibrato *instance) { size_t bw_example_fx_vibrato_mem_req(bw_example_fx_vibrato *instance) {
return bw_chorus_mem_req(&instance->chorus_coeffs); return bw_chorus_mem_req(&instance->chorus_coeffs);
} }

View File

@ -45,7 +45,7 @@ typedef struct _bw_example_fx_vibrato bw_example_fx_vibrato;
void bw_example_fx_vibrato_init(bw_example_fx_vibrato *instance); void bw_example_fx_vibrato_init(bw_example_fx_vibrato *instance);
void bw_example_fx_vibrato_set_sample_rate(bw_example_fx_vibrato *instance, float sample_rate); void bw_example_fx_vibrato_set_sample_rate(bw_example_fx_vibrato *instance, float sample_rate);
BW_SIZE_T bw_example_fx_vibrato_mem_req(bw_example_fx_vibrato *instance); size_t bw_example_fx_vibrato_mem_req(bw_example_fx_vibrato *instance);
void bw_example_fx_vibrato_mem_set(bw_example_fx_vibrato *instance, void *mem); void bw_example_fx_vibrato_mem_set(bw_example_fx_vibrato *instance, void *mem);
void bw_example_fx_vibrato_reset(bw_example_fx_vibrato *instance); void bw_example_fx_vibrato_reset(bw_example_fx_vibrato *instance);
void bw_example_fx_vibrato_process(bw_example_fx_vibrato *instance, const float** x, float** y, int n_samples); void bw_example_fx_vibrato_process(bw_example_fx_vibrato *instance, const float** x, float** y, int n_samples);

View File

@ -167,13 +167,13 @@ void bw_example_synth_mono_process(bw_example_synth_mono *instance, const float*
bw_pink_filt_process(&instance->pink_filt_coeffs, &instance->pink_filt_state, instance->buf[0], instance->buf[0], n); bw_pink_filt_process(&instance->pink_filt_coeffs, &instance->pink_filt_state, instance->buf[0], instance->buf[0], n);
else else
bw_pink_filt_reset_state(&instance->pink_filt_coeffs, &instance->pink_filt_state); // FIXME: calling this here is sloppy coding bw_pink_filt_reset_state(&instance->pink_filt_coeffs, &instance->pink_filt_state); // FIXME: calling this here is sloppy coding
bw_buf_scale(instance->buf[0], instance->buf[0], 5.f, n); bw_buf_scale(instance->buf[0], 5.f, instance->buf[0], n);
for (int j = 0; j < n; j++) for (int j = 0; j < n; j++)
instance->buf[1][j] = instance->mod_wheel * (out[j] + instance->params[p_mod_mix] * (instance->buf[0][j] - out[j])); instance->buf[1][j] = instance->mod_wheel * (out[j] + instance->params[p_mod_mix] * (instance->buf[0][j] - out[j]));
const float vcf_mod = 0.3f * instance->params[p_vcf_mod] * instance->buf[1][0]; const float vcf_mod = 0.3f * instance->params[p_vcf_mod] * instance->buf[1][0];
bw_buf_scale(instance->buf[2], instance->buf[1], instance->params[p_vco1_mod], n); bw_buf_scale(instance->buf[1], instance->params[p_vco1_mod], instance->buf[2], n);
bw_phase_gen_process(&instance->vco1_phase_gen_coeffs, &instance->vco1_phase_gen_state, instance->buf[2], instance->buf[2], instance->buf[3], n); bw_phase_gen_process(&instance->vco1_phase_gen_coeffs, &instance->vco1_phase_gen_state, instance->buf[2], instance->buf[2], instance->buf[3], n);
if (instance->params[p_vco1_waveform] >= (1.f / 4.f + 1.f / 2.f)) { if (instance->params[p_vco1_waveform] >= (1.f / 4.f + 1.f / 2.f)) {
bw_osc_tri_process(&instance->vco1_tri_coeffs, instance->buf[2], instance->buf[3], instance->buf[2], n); bw_osc_tri_process(&instance->vco1_tri_coeffs, instance->buf[2], instance->buf[3], instance->buf[2], n);
@ -187,7 +187,7 @@ void bw_example_synth_mono_process(bw_example_synth_mono *instance, const float*
bw_osc_tri_reset_coeffs(&instance->vco1_tri_coeffs); bw_osc_tri_reset_coeffs(&instance->vco1_tri_coeffs);
} }
bw_buf_scale(instance->buf[1], instance->buf[1], instance->params[p_vco2_mod], n); bw_buf_scale(instance->buf[1], instance->params[p_vco2_mod], instance->buf[1], n);
bw_phase_gen_process(&instance->vco2_phase_gen_coeffs, &instance->vco2_phase_gen_state, instance->buf[1], instance->buf[1], instance->buf[3], n); bw_phase_gen_process(&instance->vco2_phase_gen_coeffs, &instance->vco2_phase_gen_state, instance->buf[1], instance->buf[1], instance->buf[3], n);
if (instance->params[p_vco2_waveform] >= (1.f / 4.f + 1.f / 2.f)) { if (instance->params[p_vco2_waveform] >= (1.f / 4.f + 1.f / 2.f)) {
bw_osc_tri_process(&instance->vco2_tri_coeffs, instance->buf[1], instance->buf[3], instance->buf[1], n); bw_osc_tri_process(&instance->vco2_tri_coeffs, instance->buf[1], instance->buf[3], instance->buf[1], n);
@ -205,16 +205,16 @@ void bw_example_synth_mono_process(bw_example_synth_mono *instance, const float*
bw_gain_process(&instance->vco2_gain_coeffs, instance->buf[1], instance->buf[1], n); bw_gain_process(&instance->vco2_gain_coeffs, instance->buf[1], instance->buf[1], n);
bw_gain_process(&instance->vco3_gain_coeffs, out, out, n); bw_gain_process(&instance->vco3_gain_coeffs, out, out, n);
bw_gain_process(&instance->noise_gain_coeffs, instance->buf[0], instance->buf[0], n); bw_gain_process(&instance->noise_gain_coeffs, instance->buf[0], instance->buf[0], n);
bw_buf_mix(out, out, instance->buf[1], n); bw_buf_mix(out, instance->buf[1], out, n);
bw_buf_mix(out, out, instance->buf[2], n); bw_buf_mix(out, instance->buf[2], out, n);
bw_osc_filt_process(&instance->osc_filt_state, out, out, n); bw_osc_filt_process(&instance->osc_filt_state, out, out, n);
const float k = instance->params[p_noise_color] >= 0.5f const float k = instance->params[p_noise_color] >= 0.5f
? 6.f * bw_noise_gen_get_scaling_k(&instance->noise_gen_coeffs) * bw_pink_filt_get_scaling_k(&instance->pink_filt_coeffs) ? 6.f * bw_noise_gen_get_scaling_k(&instance->noise_gen_coeffs) * bw_pink_filt_get_scaling_k(&instance->pink_filt_coeffs)
: 0.1f * bw_noise_gen_get_scaling_k(&instance->noise_gen_coeffs); : 0.1f * bw_noise_gen_get_scaling_k(&instance->noise_gen_coeffs);
bw_buf_scale(instance->buf[0], instance->buf[0], k, n); bw_buf_scale(instance->buf[0], k, instance->buf[0], n);
bw_buf_mix(out, out, instance->buf[0], n); bw_buf_mix(out, instance->buf[0], out, n);
bw_env_gen_process(&instance->vcf_env_gen_coeffs, &instance->vcf_env_gen_state, instance->gate, NULL, n); bw_env_gen_process(&instance->vcf_env_gen_coeffs, &instance->vcf_env_gen_state, instance->gate, NULL, n);
float v = instance->params[p_vcf_cutoff] + instance->params[p_vcf_contour] * bw_env_gen_get_y_z1(&instance->vcf_env_gen_state) + vcf_mod; float v = instance->params[p_vcf_cutoff] + instance->params[p_vcf_contour] * bw_env_gen_get_y_z1(&instance->vcf_env_gen_state) + vcf_mod;
@ -230,12 +230,12 @@ void bw_example_synth_mono_process(bw_example_synth_mono *instance, const float*
bw_svf_process(&instance->vcf_coeffs, &instance->vcf_state, out, out, NULL, NULL, n); bw_svf_process(&instance->vcf_coeffs, &instance->vcf_state, out, out, NULL, NULL, n);
bw_env_gen_process(&instance->vca_env_gen_coeffs, &instance->vca_env_gen_state, instance->gate, instance->buf[0], n); bw_env_gen_process(&instance->vca_env_gen_coeffs, &instance->vca_env_gen_state, instance->gate, instance->buf[0], n);
bw_buf_mul(out, out, instance->buf[0], n); bw_buf_mul(out, instance->buf[0], out, n);
bw_phase_gen_process(&instance->a440_phase_gen_coeffs, &instance->a440_phase_gen_state, NULL, instance->buf[0], NULL, n); bw_phase_gen_process(&instance->a440_phase_gen_coeffs, &instance->a440_phase_gen_state, NULL, instance->buf[0], NULL, n);
bw_osc_sin_process(instance->buf[0], instance->buf[0], n); bw_osc_sin_process(instance->buf[0], instance->buf[0], n);
if (instance->params[p_a440] >= 0.5f) if (instance->params[p_a440] >= 0.5f)
bw_buf_mix(out, out, instance->buf[0], n); bw_buf_mix(out, instance->buf[0], out, n);
bw_gain_process(&instance->gain_coeffs, out, out, n); bw_gain_process(&instance->gain_coeffs, out, out, n);
bw_ppm_process(&instance->ppm_coeffs, &instance->ppm_state, out, NULL, n); bw_ppm_process(&instance->ppm_coeffs, &instance->ppm_state, out, NULL, n);

View File

@ -237,7 +237,7 @@ void bw_example_synth_poly_process(bw_example_synth_poly *instance, const float*
else else
for (int j = 0; j < N_VOICES; j++) for (int j = 0; j < N_VOICES; j++)
bw_pink_filt_reset_state(&instance->pink_filt_coeffs, pink_filt_states[j]); // FIXME: calling this here is sloppy coding bw_pink_filt_reset_state(&instance->pink_filt_coeffs, pink_filt_states[j]); // FIXME: calling this here is sloppy coding
bw_buf_scale_multi(b1, (const float **)b1, 5.f, N_VOICES, n); bw_buf_scale_multi((const float **)b1, 5.f, b1, N_VOICES, n);
float vcf_mod[N_VOICES]; float vcf_mod[N_VOICES];
for (int j = 0; j < N_VOICES; j++) { for (int j = 0; j < N_VOICES; j++) {
@ -247,7 +247,7 @@ void bw_example_synth_poly_process(bw_example_synth_poly *instance, const float*
} }
for (int j = 0; j < N_VOICES; j++) { for (int j = 0; j < N_VOICES; j++) {
bw_buf_scale(b3[j], b2[j], instance->params[p_vco1_mod], n); bw_buf_scale(b2[j], instance->params[p_vco1_mod], b3[j], n);
bw_phase_gen_process(&instance->voices[j].vco1_phase_gen_coeffs, &instance->voices[j].vco1_phase_gen_state, b3[j], b3[j], b4[j], n); bw_phase_gen_process(&instance->voices[j].vco1_phase_gen_coeffs, &instance->voices[j].vco1_phase_gen_state, b3[j], b3[j], b4[j], n);
} }
if (instance->params[p_vco1_waveform] >= (1.f / 4.f + 1.f / 2.f)) { if (instance->params[p_vco1_waveform] >= (1.f / 4.f + 1.f / 2.f)) {
@ -263,7 +263,7 @@ void bw_example_synth_poly_process(bw_example_synth_poly *instance, const float*
} }
for (int j = 0; j < N_VOICES; j++) { for (int j = 0; j < N_VOICES; j++) {
bw_buf_scale(b2[j], b2[j], instance->params[p_vco2_mod], n); bw_buf_scale(b2[j], instance->params[p_vco2_mod], b2[j], n);
bw_phase_gen_process(&instance->voices[j].vco2_phase_gen_coeffs, &instance->voices[j].vco2_phase_gen_state, b2[j], b2[j], b4[j], n); bw_phase_gen_process(&instance->voices[j].vco2_phase_gen_coeffs, &instance->voices[j].vco2_phase_gen_state, b2[j], b2[j], b4[j], n);
} }
if (instance->params[p_vco2_waveform] >= (1.f / 4.f + 1.f / 2.f)) { if (instance->params[p_vco2_waveform] >= (1.f / 4.f + 1.f / 2.f)) {
@ -282,16 +282,16 @@ void bw_example_synth_poly_process(bw_example_synth_poly *instance, const float*
bw_gain_process_multi(&instance->vco2_gain_coeffs, (const float **)b2, b2, N_VOICES, n); bw_gain_process_multi(&instance->vco2_gain_coeffs, (const float **)b2, b2, N_VOICES, n);
bw_gain_process_multi(&instance->vco3_gain_coeffs, (const float **)b0, b0, N_VOICES, n); bw_gain_process_multi(&instance->vco3_gain_coeffs, (const float **)b0, b0, N_VOICES, n);
bw_gain_process_multi(&instance->noise_gain_coeffs, (const float **)b1, b1, N_VOICES, n); bw_gain_process_multi(&instance->noise_gain_coeffs, (const float **)b1, b1, N_VOICES, n);
bw_buf_mix_multi(b0, (const float **)b0, (const float **)b2, N_VOICES, n); bw_buf_mix_multi((const float **)b0, (const float **)b2, b0, N_VOICES, n);
bw_buf_mix_multi(b0, (const float **)b0, (const float **)b3, N_VOICES, n); bw_buf_mix_multi((const float **)b0, (const float **)b3, b0, N_VOICES, n);
bw_osc_filt_process_multi(osc_filt_states, (const float **)b0, b0, N_VOICES, n); bw_osc_filt_process_multi(osc_filt_states, (const float **)b0, b0, N_VOICES, n);
const float k = instance->params[p_noise_color] >= 0.5f const float k = instance->params[p_noise_color] >= 0.5f
? 6.f * bw_noise_gen_get_scaling_k(&instance->noise_gen_coeffs) * bw_pink_filt_get_scaling_k(&instance->pink_filt_coeffs) ? 6.f * bw_noise_gen_get_scaling_k(&instance->noise_gen_coeffs) * bw_pink_filt_get_scaling_k(&instance->pink_filt_coeffs)
: 0.1f * bw_noise_gen_get_scaling_k(&instance->noise_gen_coeffs); : 0.1f * bw_noise_gen_get_scaling_k(&instance->noise_gen_coeffs);
bw_buf_scale_multi(b1, (const float **)b1, k, N_VOICES, n); bw_buf_scale_multi((const float **)b1, k, b1, N_VOICES, n);
bw_buf_mix_multi(b0, (const float **)b0, (const float **)b1, N_VOICES, n); bw_buf_mix_multi((const float **)b0, (const float **)b1, b0, N_VOICES, n);
bw_env_gen_process_multi(&instance->vcf_env_gen_coeffs, vcf_env_gen_states, gates, NULL, N_VOICES, n); bw_env_gen_process_multi(&instance->vcf_env_gen_coeffs, vcf_env_gen_states, gates, NULL, N_VOICES, n);
for (int j = 0; j < N_VOICES; j++) { for (int j = 0; j < N_VOICES; j++) {
@ -309,16 +309,16 @@ void bw_example_synth_poly_process(bw_example_synth_poly *instance, const float*
} }
bw_env_gen_process_multi(&instance->vca_env_gen_coeffs, vca_env_gen_states, gates, b1, N_VOICES, n); bw_env_gen_process_multi(&instance->vca_env_gen_coeffs, vca_env_gen_states, gates, b1, N_VOICES, n);
bw_buf_mul_multi(b0, (const float **)b0, (const float **)b1, N_VOICES, n); bw_buf_mul_multi((const float **)b0, (const float **)b1, b0, N_VOICES, n);
bw_buf_fill(out, 0.f, n); bw_buf_fill(0.f, out, n);
for (int j = 0; j < N_VOICES; j++) for (int j = 0; j < N_VOICES; j++)
bw_buf_mix(out, out, b0[j], n); bw_buf_mix(out, b0[j], out, n);
bw_phase_gen_process(&instance->a440_phase_gen_coeffs, &instance->a440_phase_gen_state, NULL, instance->buf, NULL, n); bw_phase_gen_process(&instance->a440_phase_gen_coeffs, &instance->a440_phase_gen_state, NULL, instance->buf, NULL, n);
bw_osc_sin_process(instance->buf, instance->buf, n); bw_osc_sin_process(instance->buf, instance->buf, n);
if (instance->params[p_a440] >= 0.5f) if (instance->params[p_a440] >= 0.5f)
bw_buf_mix(out, out, instance->buf, n); bw_buf_mix(out, instance->buf, out, n);
bw_gain_process(&instance->gain_coeffs, out, out, n); bw_gain_process(&instance->gain_coeffs, out, out, n);
bw_ppm_process(&instance->ppm_coeffs, &instance->ppm_state, out, NULL, n); bw_ppm_process(&instance->ppm_coeffs, &instance->ppm_state, out, NULL, n);

View File

@ -73,7 +73,7 @@ void bw_example_synth_simple_process(bw_example_synth_simple *instance, const fl
bw_osc_filt_process(&instance->osc_filt_state, out, out, n); bw_osc_filt_process(&instance->osc_filt_state, out, out, n);
bw_svf_process(&instance->svf_coeffs, &instance->svf_state, out, out, NULL, NULL, n); bw_svf_process(&instance->svf_coeffs, &instance->svf_state, out, out, NULL, NULL, n);
bw_env_gen_process(&instance->env_gen_coeffs, &instance->env_gen_state, instance->note >= 0, instance->buf, n); bw_env_gen_process(&instance->env_gen_coeffs, &instance->env_gen_state, instance->note >= 0, instance->buf, n);
bw_buf_mul(out, out, instance->buf, n); bw_buf_mul(out, instance->buf, out, n);
bw_gain_process(&instance->gain_coeffs, out, out, n); bw_gain_process(&instance->gain_coeffs, out, out, n);
bw_ppm_process(&instance->ppm_coeffs, &instance->ppm_state, out, NULL, n); bw_ppm_process(&instance->ppm_coeffs, &instance->ppm_state, out, NULL, n);
} }

View File

@ -139,13 +139,13 @@ void bw_example_synthpp_mono_process(bw_example_synthpp_mono *instance, const fl
instance->pinkFilt.process({instance->buf[0]}, {instance->buf[0]}, n); instance->pinkFilt.process({instance->buf[0]}, {instance->buf[0]}, n);
else else
instance->pinkFilt.reset(); // FIXME: calling this here is sloppy coding instance->pinkFilt.reset(); // FIXME: calling this here is sloppy coding
bw_buf_scale(instance->buf[0], instance->buf[0], 5.f, n); bufScale<1>({instance->buf[0]}, 5.f, {instance->buf[0]}, n);
for (int j = 0; j < n; j++) for (int j = 0; j < n; j++)
instance->buf[1][j] = instance->mod_wheel * (out[j] + instance->params[p_mod_mix] * (instance->buf[0][j] - out[j])); instance->buf[1][j] = instance->mod_wheel * (out[j] + instance->params[p_mod_mix] * (instance->buf[0][j] - out[j]));
const float vcf_mod = 0.3f * instance->params[p_vcf_mod] * instance->buf[1][0]; const float vcf_mod = 0.3f * instance->params[p_vcf_mod] * instance->buf[1][0];
bw_buf_scale(instance->buf[2], instance->buf[1], instance->params[p_vco1_mod], n); bufScale<1>({instance->buf[1]}, instance->params[p_vco1_mod], {instance->buf[2]}, n);
instance->vco1PhaseGen.process({instance->buf[2]}, {instance->buf[2]}, {instance->buf[3]}, n); instance->vco1PhaseGen.process({instance->buf[2]}, {instance->buf[2]}, {instance->buf[3]}, n);
if (instance->params[p_vco1_waveform] >= (1.f / 4.f + 1.f / 2.f)) { if (instance->params[p_vco1_waveform] >= (1.f / 4.f + 1.f / 2.f)) {
instance->vco1OscTri.process({instance->buf[2]}, {instance->buf[3]}, {instance->buf[2]}, n); instance->vco1OscTri.process({instance->buf[2]}, {instance->buf[3]}, {instance->buf[2]}, n);
@ -159,7 +159,7 @@ void bw_example_synthpp_mono_process(bw_example_synthpp_mono *instance, const fl
instance->vco1OscTri.reset(); instance->vco1OscTri.reset();
} }
bw_buf_scale(instance->buf[1], instance->buf[1], instance->params[p_vco1_mod], n); bufScale<1>({instance->buf[1]}, instance->params[p_vco1_mod], {instance->buf[1]}, n);
instance->vco2PhaseGen.process({instance->buf[1]}, {instance->buf[1]}, {instance->buf[3]}, n); instance->vco2PhaseGen.process({instance->buf[1]}, {instance->buf[1]}, {instance->buf[3]}, n);
if (instance->params[p_vco2_waveform] >= (1.f / 4.f + 1.f / 2.f)) { if (instance->params[p_vco2_waveform] >= (1.f / 4.f + 1.f / 2.f)) {
instance->vco2OscTri.process({instance->buf[1]}, {instance->buf[3]}, {instance->buf[1]}, n); instance->vco2OscTri.process({instance->buf[1]}, {instance->buf[3]}, {instance->buf[1]}, n);
@ -177,16 +177,16 @@ void bw_example_synthpp_mono_process(bw_example_synthpp_mono *instance, const fl
instance->vco2Gain.process({instance->buf[1]}, {instance->buf[1]}, n); instance->vco2Gain.process({instance->buf[1]}, {instance->buf[1]}, n);
instance->vco3Gain.process({out}, {out}, n); instance->vco3Gain.process({out}, {out}, n);
instance->noiseGain.process({instance->buf[0]}, {instance->buf[0]}, n); instance->noiseGain.process({instance->buf[0]}, {instance->buf[0]}, n);
bw_buf_mix(out, out, instance->buf[1], n); bufMix<1>({out}, {instance->buf[1]}, {out}, n);
bw_buf_mix(out, out, instance->buf[2], n); bufMix<1>({out}, {instance->buf[2]}, {out}, n);
instance->oscFilt.process({out}, {out}, n); instance->oscFilt.process({out}, {out}, n);
const float k = instance->params[p_noise_color] >= 0.5f const float k = instance->params[p_noise_color] >= 0.5f
? 6.f * instance->noiseGen.getScalingK() * instance->pinkFilt.getScalingK() ? 6.f * instance->noiseGen.getScalingK() * instance->pinkFilt.getScalingK()
: 0.1f * instance->noiseGen.getScalingK(); : 0.1f * instance->noiseGen.getScalingK();
bw_buf_scale(instance->buf[0], instance->buf[0], k, n); bufScale<1>({instance->buf[0]}, k, {instance->buf[0]}, n);
bw_buf_mix(out, out, instance->buf[0], n); bufMix<1>({out}, {instance->buf[0]}, {out}, n);
instance->vcfEnvGen.process({instance->gate}, {nullptr}, n); instance->vcfEnvGen.process({instance->gate}, {nullptr}, n);
float v = instance->params[p_vcf_cutoff] + instance->params[p_vcf_contour] * instance->vcfEnvGen.getYZ1(0) + vcf_mod; float v = instance->params[p_vcf_cutoff] + instance->params[p_vcf_contour] * instance->vcfEnvGen.getYZ1(0) + vcf_mod;
@ -202,12 +202,12 @@ void bw_example_synthpp_mono_process(bw_example_synthpp_mono *instance, const fl
instance->vcf.process({out}, {out}, {nullptr}, {nullptr}, n); instance->vcf.process({out}, {out}, {nullptr}, {nullptr}, n);
instance->vcaEnvGen.process({instance->gate}, {instance->buf[0]}, n); instance->vcaEnvGen.process({instance->gate}, {instance->buf[0]}, n);
bw_buf_mul(out, out, instance->buf[0], n); bufMul<1>({out}, {instance->buf[0]}, {out}, n);
instance->a440PhaseGen.process({nullptr}, {instance->buf[0]}, {nullptr}, n); instance->a440PhaseGen.process({nullptr}, {instance->buf[0]}, {nullptr}, n);
oscSinProcess<1>({instance->buf[0]}, {instance->buf[0]}, n); oscSinProcess<1>({instance->buf[0]}, {instance->buf[0]}, n);
if (instance->params[p_a440] >= 0.5f) if (instance->params[p_a440] >= 0.5f)
bw_buf_mix(out, out, instance->buf[0], n); bufMix<1>({out}, {instance->buf[0]}, {out}, n);
instance->gain.process({out}, {out}, n); instance->gain.process({out}, {out}, n);
instance->ppm.process({out}, {nullptr}, n); instance->ppm.process({out}, {nullptr}, n);

View File

@ -62,7 +62,7 @@ void bw_example_synthpp_simple_process(bw_example_synthpp_simple *instance, cons
instance->oscFilt.process({out}, {out}, n); instance->oscFilt.process({out}, {out}, n);
instance->svf.process({out}, {out}, {nullptr}, {nullptr}, n); instance->svf.process({out}, {out}, {nullptr}, {nullptr}, n);
instance->envGen.process({instance->note >= 0}, {instance->buf}, n); instance->envGen.process({instance->note >= 0}, {instance->buf}, n);
bw_buf_mul(out, out, instance->buf, n); bufMul<1>({out}, {instance->buf}, {out}, n);
instance->gain.process({out}, {out}, n); instance->gain.process({out}, {out}, n);
instance->ppm.process({out}, {nullptr}, n); instance->ppm.process({out}, {nullptr}, n);
} }

View File

@ -31,6 +31,9 @@
* <ul> * <ul>
* <li>Now using <code>size_t</code> instead of * <li>Now using <code>size_t</code> instead of
* <code>BW_SIZE_T</code>.</li> * <code>BW_SIZE_T</code>.</li>
* <li>Changed order of arguments to improve consistency.</li>
* <li>Added more <code>const</code> specifiers to input
* arguments.</li>
* <li>Moved C++ code to C header.</li> * <li>Moved C++ code to C header.</li>
* <li>Removed usage of reserved identifiers.</li> * <li>Removed usage of reserved identifiers.</li>
* </ul> * </ul>
@ -75,55 +78,55 @@ extern "C" {
/*! api {{{ /*! api {{{
* #### bw_buf_fill() * #### bw_buf_fill()
* ```>>> */ * ```>>> */
static inline void bw_buf_fill(float *dest, float k, size_t n_elems); static inline void bw_buf_fill(float k, float *dest, size_t n_elems);
/*! <<<``` /*! <<<```
* Sets the first `n_elems` in `dest` to `k`. * Sets the first `n_elems` in `dest` to `k`.
* *
* #### bw_buf_neg() * #### bw_buf_neg()
* ```>>> */ * ```>>> */
static inline void bw_buf_neg(float *dest, const float *src, size_t n_elems); static inline void bw_buf_neg(const float *src, float *dest, size_t n_elems);
/*! <<<``` /*! <<<```
* Inverts the sign of the first `n_elems` in `src` and stores the results in * Inverts the sign of the first `n_elems` in `src` and stores the results in
* the first `n_elems` of `dest`. * the first `n_elems` of `dest`.
* *
* #### bw_buf_add() * #### bw_buf_add()
* ```>>> */ * ```>>> */
static inline void bw_buf_add(float *dest, const float *src, float k, size_t n_elems); static inline void bw_buf_add(const float *src, float k, float *dest, size_t n_elems);
/*! <<<``` /*! <<<```
* Adds `k` to the first `n_elems` in `src` and stores the results in the * Adds `k` to the first `n_elems` in `src` and stores the results in the
* first `n_elems` of `dest`. * first `n_elems` of `dest`.
* *
* #### bw_buf_scale() * #### bw_buf_scale()
* ```>>> */ * ```>>> */
static inline void bw_buf_scale(float *dest, const float *src, float k, size_t n_elems); static inline void bw_buf_scale(const float *src, float k, float *dest, size_t n_elems);
/*! <<<``` /*! <<<```
* Multiplies the first `n_elems` in `src` by `k` and stores the results in * Multiplies the first `n_elems` in `src` by `k` and stores the results in
* the first `n_elems` of `dest`. * the first `n_elems` of `dest`.
* *
* #### bw_buf_mix() * #### bw_buf_mix()
* ```>>> */ * ```>>> */
static inline void bw_buf_mix(float *dest, const float *src1, const float *src2, size_t n_elems); static inline void bw_buf_mix(const float *src1, const float *src2, float *dest, size_t n_elems);
/*! <<<``` /*! <<<```
* Adds the first `n_elems` of `src1` and `src2` and stores the results in * Adds the first `n_elems` of `src1` and `src2` and stores the results in
* the first `n_elems` of `dest`. * the first `n_elems` of `dest`.
* *
* #### bw_buf_mul() * #### bw_buf_mul()
* ```>>> */ * ```>>> */
static inline void bw_buf_mul(float *dest, const float *src1, const float *src2, size_t n_elems); static inline void bw_buf_mul(const float *src1, const float *src2, float *dest, size_t n_elems);
/*! <<<``` /*! <<<```
* Multiplies the first `n_elems` of `src1` and `src2` and stores the results * Multiplies the first `n_elems` of `src1` and `src2` and stores the results
* in the first `n_elems` of `dest`. * in the first `n_elems` of `dest`.
* *
* #### bw_buf_fill_multi() * #### bw_buf_fill_multi()
* ```>>> */ * ```>>> */
static inline void bw_buf_fill_multi(float **dest, float k, size_t n_channels, size_t n_elems); static inline void bw_buf_fill_multi(float k, float **dest, size_t n_channels, size_t n_elems);
/*! <<<``` /*! <<<```
* Sets the first `n_elems` in each of the `n_channels` buffers `dest` to * Sets the first `n_elems` in each of the `n_channels` buffers `dest` to
* `k`. * `k`.
* *
* #### bw_buf_neg_multi() * #### bw_buf_neg_multi()
* ```>>> */ * ```>>> */
static inline void bw_buf_neg_multi(float **dest, const float **src, size_t n_channels, size_t n_elems); static inline void bw_buf_neg_multi(const float * const *src, float **dest, size_t n_channels, size_t n_elems);
/*! <<<``` /*! <<<```
* Inverts the sign of the first `n_elems` in each of the `n_channels` * Inverts the sign of the first `n_elems` in each of the `n_channels`
* buffers `src` and stores the results in the first `n_elems` in each of the * buffers `src` and stores the results in the first `n_elems` in each of the
@ -131,7 +134,7 @@ static inline void bw_buf_neg_multi(float **dest, const float **src, size_t n_ch
* *
* #### bw_buf_add_multi() * #### bw_buf_add_multi()
* ```>>> */ * ```>>> */
static inline void bw_buf_add_multi(float **dest, const float **src, float k, size_t n_channels, size_t n_elems); static inline void bw_buf_add_multi(const float * const *src, float k, float **dest, size_t n_channels, size_t n_elems);
/*! <<<``` /*! <<<```
* Adds `k` to the first `n_elems` in each of the `n_channels` buffers `src` * Adds `k` to the first `n_elems` in each of the `n_channels` buffers `src`
* and stores the results in the first `n_elems` in each of the `n_channels` * and stores the results in the first `n_elems` in each of the `n_channels`
@ -139,7 +142,7 @@ static inline void bw_buf_add_multi(float **dest, const float **src, float k, si
* *
* #### bw_buf_scale_multi() * #### bw_buf_scale_multi()
* ```>>> */ * ```>>> */
static inline void bw_buf_scale_multi(float **dest, const float **src, float k, size_t n_channels, size_t n_elems); static inline void bw_buf_scale_multi(const float * const *src, float k, float **dest, size_t n_channels, size_t n_elems);
/*! <<<``` /*! <<<```
* Multiplies the first `n_elems` in each of the `n_channels` buffers `src` * Multiplies the first `n_elems` in each of the `n_channels` buffers `src`
* by `k` and stores the results in the first `n_elems` in each of the * by `k` and stores the results in the first `n_elems` in each of the
@ -147,7 +150,7 @@ static inline void bw_buf_scale_multi(float **dest, const float **src, float k,
* *
* #### bw_buf_mix_multi() * #### bw_buf_mix_multi()
* ```>>> */ * ```>>> */
static inline void bw_buf_mix_multi(float **dest, const float **src1, const float **src2, size_t n_channels, size_t n_elems); static inline void bw_buf_mix_multi(const float * const *src1, const float * const *src2, float **dest, size_t n_channels, size_t n_elems);
/*! <<<``` /*! <<<```
* Adds the first `n_elems` in each of the `n_channels` buffers `src1` and * Adds the first `n_elems` in each of the `n_channels` buffers `src1` and
* `src2` and stores the results in the first `n_elems` in each of the * `src2` and stores the results in the first `n_elems` in each of the
@ -155,7 +158,7 @@ static inline void bw_buf_mix_multi(float **dest, const float **src1, const floa
* *
* #### bw_buf_mul_multi() * #### bw_buf_mul_multi()
* ```>>> */ * ```>>> */
static inline void bw_buf_mul_multi(float **dest, const float **src1, const float **src2, size_t n_channels, size_t n_elems); static inline void bw_buf_mul_multi(const float * const *src1, const float * const *src2, float **dest, size_t n_channels, size_t n_elems);
/*! <<<``` /*! <<<```
* Multiplies the first `n_elems` in each of the `n_channels` buffers `src1` * Multiplies the first `n_elems` in each of the `n_channels` buffers `src1`
* and `src2` and stores the results in the first `n_elems` in each of the * and `src2` and stores the results in the first `n_elems` in each of the
@ -174,8 +177,8 @@ namespace Brickworks {
* ```>>> */ * ```>>> */
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
void bufFill( void bufFill(
std::array<float *, N_CHANNELS> dest,
float k, float k,
std::array<float *, N_CHANNELS> dest,
int nSamples); int nSamples);
/*! <<<``` /*! <<<```
* *
@ -183,8 +186,8 @@ void bufFill(
* ```>>> */ * ```>>> */
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
void bufNeg( void bufNeg(
std::array<float *, N_CHANNELS> dest,
std::array<const float *, N_CHANNELS> src, std::array<const float *, N_CHANNELS> src,
std::array<float *, N_CHANNELS> dest,
int nSamples); int nSamples);
/*! <<<``` /*! <<<```
* *
@ -192,8 +195,8 @@ void bufNeg(
* ```>>> */ * ```>>> */
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
void bufAdd( void bufAdd(
std::array<float *, N_CHANNELS> dest,
std::array<const float *, N_CHANNELS> src, std::array<const float *, N_CHANNELS> src,
std::array<float *, N_CHANNELS> dest,
float k, float k,
int nSamples); int nSamples);
/*! <<<``` /*! <<<```
@ -202,8 +205,8 @@ void bufAdd(
* ```>>> */ * ```>>> */
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
void bufScale( void bufScale(
std::array<float *, N_CHANNELS> dest,
std::array<const float *, N_CHANNELS> src, std::array<const float *, N_CHANNELS> src,
std::array<float *, N_CHANNELS> dest,
float k, float k,
int nSamples); int nSamples);
/*! <<<``` /*! <<<```
@ -212,9 +215,9 @@ void bufScale(
* ```>>> */ * ```>>> */
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
void bufMix( void bufMix(
std::array<float *, N_CHANNELS> dest,
std::array<const float *, N_CHANNELS> src1, std::array<const float *, N_CHANNELS> src1,
std::array<const float *, N_CHANNELS> src2, std::array<const float *, N_CHANNELS> src2,
std::array<float *, N_CHANNELS> dest,
int nSamples); int nSamples);
/*! <<<``` /*! <<<```
* *
@ -222,9 +225,9 @@ void bufMix(
* ```>>> */ * ```>>> */
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
void bufMul( void bufMul(
std::array<float *, N_CHANNELS> dest,
std::array<const float *, N_CHANNELS> src1, std::array<const float *, N_CHANNELS> src1,
std::array<const float *, N_CHANNELS> src2, std::array<const float *, N_CHANNELS> src2,
std::array<float *, N_CHANNELS> dest,
int nSamples); int nSamples);
/*! <<<``` /*! <<<```
* }}} */ * }}} */
@ -241,7 +244,7 @@ void bufMul(
extern "C" { extern "C" {
#endif #endif
static inline void bw_buf_fill(float *dest, float k, size_t n_elems) { static inline void bw_buf_fill(float k, float *dest, size_t n_elems) {
BW_ASSERT(!(dest == NULL && n_elems != 0)); BW_ASSERT(!(dest == NULL && n_elems != 0));
BW_ASSERT(!bw_is_nan(k)); BW_ASSERT(!bw_is_nan(k));
@ -251,7 +254,7 @@ static inline void bw_buf_fill(float *dest, float k, size_t n_elems) {
BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems)); BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems));
} }
static inline void bw_buf_neg(float *dest, const float *src, size_t n_elems) { static inline void bw_buf_neg(const float *src, float *dest, size_t n_elems) {
BW_ASSERT(!((dest == NULL || src == NULL) && n_elems != 0)); BW_ASSERT(!((dest == NULL || src == NULL) && n_elems != 0));
BW_ASSERT_DEEP(!bw_has_nan(src, n_elems)); BW_ASSERT_DEEP(!bw_has_nan(src, n_elems));
@ -261,7 +264,7 @@ static inline void bw_buf_neg(float *dest, const float *src, size_t n_elems) {
BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems)); BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems));
} }
static inline void bw_buf_add(float *dest, const float *src, float k, size_t n_elems) { static inline void bw_buf_add(const float *src, float k, float *dest, size_t n_elems) {
BW_ASSERT(!((dest == NULL || src == NULL) && n_elems != 0)); BW_ASSERT(!((dest == NULL || src == NULL) && n_elems != 0));
BW_ASSERT_DEEP(!bw_has_nan(src, n_elems)); BW_ASSERT_DEEP(!bw_has_nan(src, n_elems));
BW_ASSERT(!bw_is_nan(k)); BW_ASSERT(!bw_is_nan(k));
@ -272,7 +275,7 @@ static inline void bw_buf_add(float *dest, const float *src, float k, size_t n_e
BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems)); BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems));
} }
static inline void bw_buf_scale(float *dest, const float *src, float k, size_t n_elems) { static inline void bw_buf_scale(const float *src, float k, float *dest, size_t n_elems) {
BW_ASSERT(!((dest == NULL || src == NULL) && n_elems != 0)); BW_ASSERT(!((dest == NULL || src == NULL) && n_elems != 0));
BW_ASSERT_DEEP(!bw_has_nan(src, n_elems)); BW_ASSERT_DEEP(!bw_has_nan(src, n_elems));
BW_ASSERT(!bw_is_nan(k)); BW_ASSERT(!bw_is_nan(k));
@ -283,7 +286,7 @@ static inline void bw_buf_scale(float *dest, const float *src, float k, size_t n
BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems)); BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems));
} }
static inline void bw_buf_mix(float *dest, const float *src1, const float *src2, size_t n_elems) { static inline void bw_buf_mix(const float *src1, const float *src2, float *dest, size_t n_elems) {
BW_ASSERT(!((dest == NULL || src1 == NULL || src2 == NULL) && n_elems != 0)); BW_ASSERT(!((dest == NULL || src1 == NULL || src2 == NULL) && n_elems != 0));
BW_ASSERT_DEEP(!bw_has_nan(src1, n_elems)); BW_ASSERT_DEEP(!bw_has_nan(src1, n_elems));
BW_ASSERT_DEEP(!bw_has_nan(src2, n_elems)); BW_ASSERT_DEEP(!bw_has_nan(src2, n_elems));
@ -294,7 +297,7 @@ static inline void bw_buf_mix(float *dest, const float *src1, const float *src2,
BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems)); BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems));
} }
static inline void bw_buf_mul(float *dest, const float *src1, const float *src2, size_t n_elems) { static inline void bw_buf_mul(const float *src1, const float *src2, float *dest, size_t n_elems) {
BW_ASSERT(!((dest == NULL || src1 == NULL || src2 == NULL) && n_elems != 0)); BW_ASSERT(!((dest == NULL || src1 == NULL || src2 == NULL) && n_elems != 0));
BW_ASSERT_DEEP(!bw_has_nan(src1, n_elems)); BW_ASSERT_DEEP(!bw_has_nan(src1, n_elems));
BW_ASSERT_DEEP(!bw_has_nan(src2, n_elems)); BW_ASSERT_DEEP(!bw_has_nan(src2, n_elems));
@ -305,46 +308,46 @@ static inline void bw_buf_mul(float *dest, const float *src1, const float *src2,
BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems)); BW_ASSERT_DEEP(!bw_has_nan(dest, n_elems));
} }
static inline void bw_buf_fill_multi(float **dest, float k, size_t n_channels, size_t n_elems) { static inline void bw_buf_fill_multi(float k, float **dest, size_t n_channels, size_t n_elems) {
BW_ASSERT(!(dest == NULL && n_channels != 0)); BW_ASSERT(!(dest == NULL && n_channels != 0));
for (size_t i = 0; i < n_channels; i++) for (size_t i = 0; i < n_channels; i++)
bw_buf_fill(dest[i], k, n_elems); bw_buf_fill(k, dest[i], n_elems);
} }
static inline void bw_buf_neg_multi(float **dest, const float **src, size_t n_channels, size_t n_elems) { static inline void bw_buf_neg_multi(const float * const *src, float **dest, size_t n_channels, size_t n_elems) {
BW_ASSERT(!((dest == NULL || src == NULL) && n_channels != 0)); BW_ASSERT(!((dest == NULL || src == NULL) && n_channels != 0));
for (size_t i = 0; i < n_channels; i++) for (size_t i = 0; i < n_channels; i++)
bw_buf_neg(dest[i], src[i], n_elems); bw_buf_neg(src[i], dest[i], n_elems);
} }
static inline void bw_buf_add_multi(float **dest, const float **src, float k, size_t n_channels, size_t n_elems) { static inline void bw_buf_add_multi(const float * const *src, float k, float **dest, size_t n_channels, size_t n_elems) {
BW_ASSERT(!((dest == NULL || src == NULL) && n_channels != 0)); BW_ASSERT(!((dest == NULL || src == NULL) && n_channels != 0));
for (size_t i = 0; i < n_channels; i++) for (size_t i = 0; i < n_channels; i++)
bw_buf_add(dest[i], src[i], k, n_elems); bw_buf_add(src[i], k, dest[i], n_elems);
} }
static inline void bw_buf_scale_multi(float **dest, const float **src, float k, size_t n_channels, size_t n_elems) { static inline void bw_buf_scale_multi(const float * const *src, float k, float **dest, size_t n_channels, size_t n_elems) {
BW_ASSERT(!((dest == NULL || src == NULL) && n_channels != 0)); BW_ASSERT(!((dest == NULL || src == NULL) && n_channels != 0));
for (size_t i = 0; i < n_channels; i++) for (size_t i = 0; i < n_channels; i++)
bw_buf_scale(dest[i], src[i], k, n_elems); bw_buf_scale(src[i], k, dest[i], n_elems);
} }
static inline void bw_buf_mix_multi(float **dest, const float **src1, const float **src2, size_t n_channels, size_t n_elems) { static inline void bw_buf_mix_multi(const float * const *src1, const float * const *src2, float **dest, size_t n_channels, size_t n_elems) {
BW_ASSERT(!((dest == NULL || src1 == NULL || src2 == NULL) && n_channels != 0)); BW_ASSERT(!((dest == NULL || src1 == NULL || src2 == NULL) && n_channels != 0));
for (size_t i = 0; i < n_channels; i++) for (size_t i = 0; i < n_channels; i++)
bw_buf_mix(dest[i], src1[i], src2[i], n_elems); bw_buf_mix(src1[i], src2[i], dest[i], n_elems);
} }
static inline void bw_buf_mul_multi(float **dest, const float **src1, const float **src2, size_t n_channels, size_t n_elems) { static inline void bw_buf_mul_multi(const float * const *src1, const float * const *src2, float **dest, size_t n_channels, size_t n_elems) {
BW_ASSERT(!((dest == NULL || src1 == NULL || src2 == NULL) && n_channels != 0)); BW_ASSERT(!((dest == NULL || src1 == NULL || src2 == NULL) && n_channels != 0));
for (size_t i = 0; i < n_channels; i++) for (size_t i = 0; i < n_channels; i++)
bw_buf_mul(dest[i], src1[i], src2[i], n_elems); bw_buf_mul(src1[i], src2[i], dest[i], n_elems);
} }
#ifdef __cplusplus #ifdef __cplusplus
@ -354,54 +357,54 @@ namespace Brickworks {
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
inline void bufFill( inline void bufFill(
std::array<float *, N_CHANNELS> dest,
float k, float k,
std::array<float *, N_CHANNELS> dest,
int nSamples) { int nSamples) {
bw_buf_fill_multi(dest.data(), k, N_CHANNELS, nSamples); bw_buf_fill_multi(k, dest.data(), N_CHANNELS, nSamples);
} }
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
inline void bufNeg( inline void bufNeg(
std::array<float *, N_CHANNELS> dest,
std::array<const float *, N_CHANNELS> src, std::array<const float *, N_CHANNELS> src,
std::array<float *, N_CHANNELS> dest,
int nSamples) { int nSamples) {
bw_buf_neg_multi(dest.data(), src.data(), N_CHANNELS, nSamples); bw_buf_neg_multi(src.data(), dest.data(), N_CHANNELS, nSamples);
} }
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
inline void bufAdd( inline void bufAdd(
std::array<float *, N_CHANNELS> dest,
std::array<const float *, N_CHANNELS> src, std::array<const float *, N_CHANNELS> src,
float k, float k,
std::array<float *, N_CHANNELS> dest,
int nSamples) { int nSamples) {
bw_buf_add_multi(dest.data(), src.data(), k, N_CHANNELS, nSamples); bw_buf_add_multi(src.data(), k, dest.data(), N_CHANNELS, nSamples);
} }
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
inline void bufScale( inline void bufScale(
std::array<float *, N_CHANNELS> dest,
std::array<const float *, N_CHANNELS> src, std::array<const float *, N_CHANNELS> src,
float k, float k,
std::array<float *, N_CHANNELS> dest,
int nSamples) { int nSamples) {
bw_buf_scale_multi(dest.data(), src.data(), k, N_CHANNELS, nSamples); bw_buf_scale_multi(src.data(), k, dest.data(), N_CHANNELS, nSamples);
} }
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
inline void bufMix( inline void bufMix(
std::array<float *, N_CHANNELS> dest,
std::array<const float *, N_CHANNELS> src1, std::array<const float *, N_CHANNELS> src1,
std::array<const float *, N_CHANNELS> src2, std::array<const float *, N_CHANNELS> src2,
std::array<float *, N_CHANNELS> dest,
int nSamples) { int nSamples) {
bw_buf_mix_multi(dest.data(), src1.data(), src2.data(), N_CHANNELS, nSamples); bw_buf_mix_multi(src1.data(), src2.data(), dest.data(), N_CHANNELS, nSamples);
} }
template<size_t N_CHANNELS> template<size_t N_CHANNELS>
inline void bufMul( inline void bufMul(
std::array<float *, N_CHANNELS> dest,
std::array<const float *, N_CHANNELS> src1, std::array<const float *, N_CHANNELS> src1,
std::array<const float *, N_CHANNELS> src2, std::array<const float *, N_CHANNELS> src2,
std::array<float *, N_CHANNELS> dest,
int nSamples) { int nSamples) {
bw_buf_mul_multi(dest.data(), src1.data(), src2.data(), N_CHANNELS, nSamples); bw_buf_mul_multi(src1.data(), src2.data(), dest.data(), N_CHANNELS, nSamples);
} }
} }

View File

@ -238,7 +238,7 @@ static inline void bw_delay_reset_coeffs(bw_delay_coeffs *BW_RESTRICT coeffs) {
} }
static inline void bw_delay_reset_state(const bw_delay_coeffs *BW_RESTRICT coeffs, bw_delay_state *BW_RESTRICT state) { static inline void bw_delay_reset_state(const bw_delay_coeffs *BW_RESTRICT coeffs, bw_delay_state *BW_RESTRICT state) {
bw_buf_fill(state->buf, 0.f, coeffs->len); bw_buf_fill(0.f, state->buf, coeffs->len);
state->idx = 0; state->idx = 0;
} }