diff --git a/TODO b/TODO index 43dcb64..1c7a3a2 100644 --- a/TODO +++ b/TODO @@ -35,7 +35,6 @@ code: * peak gain + Q ??? * merge c++ code into c headers * sr_reduce reset_coeffs? update_coeffs? process_multi? -* fix definitions leading to X ** -> const X ** error https://isocpp.org/wiki/faq/const-correctness#constptrptr-conversion, fix fx_balance, fx_pan, synth_poly * drywet -> dry_wet, ringmod -> ring_mod, etc? * allow nullptr in C++ wrappers where process_multi arg can be NULL * better src filter diff --git a/examples/synth_poly/src/bw_example_synth_poly.c b/examples/synth_poly/src/bw_example_synth_poly.c index 21daf28..4c078d0 100644 --- a/examples/synth_poly/src/bw_example_synth_poly.c +++ b/examples/synth_poly/src/bw_example_synth_poly.c @@ -237,7 +237,7 @@ void bw_example_synth_poly_process(bw_example_synth_poly *instance, const float* else 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_buf_scale_multi((const float **)b1, 5.f, b1, N_VOICES, n); + bw_buf_scale_multi((const float * const *)b1, 5.f, b1, N_VOICES, n); float vcf_mod[N_VOICES]; for (int j = 0; j < N_VOICES; j++) { @@ -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->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_buf_mix_multi((const float **)b0, (const float **)b2, b0, N_VOICES, n); - bw_buf_mix_multi((const float **)b0, (const float **)b3, b0, N_VOICES, n); + bw_buf_mix_multi((const float * const *)b0, (const float * const *)b2, b0, N_VOICES, n); + bw_buf_mix_multi((const float * const *)b0, (const float * const *)b3, 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 ? 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); - bw_buf_scale_multi((const float **)b1, k, b1, N_VOICES, n); - bw_buf_mix_multi((const float **)b0, (const float **)b1, b0, N_VOICES, n); + bw_buf_scale_multi((const float * const *)b1, k, b1, N_VOICES, n); + bw_buf_mix_multi((const float * const *)b0, (const float * const *)b1, b0, 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++) { @@ -309,7 +309,7 @@ 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_buf_mul_multi((const float **)b0, (const float **)b1, b0, N_VOICES, n); + bw_buf_mul_multi((const float * const *)b0, (const float * const *)b1, b0, N_VOICES, n); bw_buf_fill(0.f, out, n); for (int j = 0; j < N_VOICES; j++) diff --git a/examples/synthpp_poly/src/bw_example_synthpp_poly.cpp b/examples/synthpp_poly/src/bw_example_synthpp_poly.cpp index df6fd4a..e875611 100644 --- a/examples/synthpp_poly/src/bw_example_synthpp_poly.cpp +++ b/examples/synthpp_poly/src/bw_example_synthpp_poly.cpp @@ -167,10 +167,16 @@ void bw_example_synthpp_poly_process(bw_example_synthpp_poly *instance, const fl const float vcf_mod_k = 0.3f * instance->params[p_vcf_mod]; + float *xb0[N_VOICES], *xb1[N_VOICES], *xb2[N_VOICES], *xb3[N_VOICES], *xb4[N_VOICES]; std::array b0, b1, b2, b3, b4, na; std::array cb0, cb1, cb2, cb3, cb4; std::array gates; for (int j = 0; j < N_VOICES; j++) { + xb0[j] = instance->voices[j].buf[0]; + xb1[j] = instance->voices[j].buf[1]; + xb2[j] = instance->voices[j].buf[2]; + xb3[j] = instance->voices[j].buf[3]; + xb4[j] = instance->voices[j].buf[4]; b0.data()[j] = instance->voices[j].buf[0]; b1.data()[j] = instance->voices[j].buf[1]; b2.data()[j] = instance->voices[j].buf[2]; @@ -208,7 +214,7 @@ void bw_example_synthpp_poly_process(bw_example_synthpp_poly *instance, const fl instance->pinkFilt.process(cb1, b1, n); else instance->pinkFilt.reset(); // FIXME: calling this here is sloppy coding - bufScale(b1, cb1, 5.f, n); + bufScale(xb1, 5.f, xb1, n); float vcf_mod[N_VOICES]; for (int j = 0; j < N_VOICES; j++) { @@ -218,8 +224,8 @@ void bw_example_synthpp_poly_process(bw_example_synthpp_poly *instance, const fl } for (int j = 0; j < N_VOICES; j++) { - bufScale<1>({b3.data()[j]}, {b2.data()[j]}, instance->params[p_vco1_mod], n); - instance->voices[j].vco1PhaseGen.process({b3.data()[j]}, {b3.data()[j]}, {b4.data()[j]}, n); + bufScale<1>({xb2[j]}, instance->params[p_vco1_mod], {xb3[j]}, n); + instance->voices[j].vco1PhaseGen.process({b3.data()[j]}, {b4.data()[j]}, {b3.data()[j]}, n); } if (instance->params[p_vco1_waveform] >= (1.f / 4.f + 1.f / 2.f)) { instance->vco1OscTri.process(cb3, cb4, b3, n); @@ -234,7 +240,7 @@ void bw_example_synthpp_poly_process(bw_example_synthpp_poly *instance, const fl } for (int j = 0; j < N_VOICES; j++) { - bufScale<1>({b2.data()[j]}, {b2.data()[j]}, instance->params[p_vco2_mod], n); + bufScale<1>({xb2[j]}, instance->params[p_vco2_mod], {xb2[j]}, n); instance->voices[j].vco2PhaseGen.process({b2.data()[j]}, {b2.data()[j]}, {b4.data()[j]}, n); } if (instance->params[p_vco2_waveform] >= (1.f / 4.f + 1.f / 2.f)) { @@ -253,16 +259,16 @@ void bw_example_synthpp_poly_process(bw_example_synthpp_poly *instance, const fl instance->vco2Gain.process(cb2, b2, n); instance->vco3Gain.process(cb0, b0, n); instance->noiseGain.process(cb1, b1, n); - bufMix(b0, cb0, cb2, n); - bufMix(b0, cb0, cb3, n); + bufMix(xb0, xb2, xb0, n); + bufMix(xb0, xb3, xb0, n); instance->oscFilt.process(cb0, b0, n); const float k = instance->params[p_noise_color] >= 0.5f ? 6.f * instance->noiseGen.getScalingK() * instance->pinkFilt.getScalingK() : 0.1f * instance->noiseGen.getScalingK(); - bufScale(b1, cb1, k, n); - bufMix(b0, cb0, cb1, n); + bufScale(xb1, k, xb1, n); + bufMix(xb0, xb1, xb0, n); instance->vcfEnvGen.process(gates, na, n); for (int j = 0; j < N_VOICES; j++) { @@ -280,16 +286,16 @@ void bw_example_synthpp_poly_process(bw_example_synthpp_poly *instance, const fl } instance->vcaEnvGen.process(gates, b1, n); - bufMul(b0, cb0, cb1, n); + bufMul(xb0, xb1, xb0, n); - bufFill<1>({out}, 0.f, n); + bufFill<1>(0.f, {out}, n); for (int j = 0; j < N_VOICES; j++) - bufMix<1>({out}, {out}, {b0.data()[j]}, n); + bufMix<1>({out}, {xb0[j]}, {out}, n); instance->a440PhaseGen.process({nullptr}, {instance->buf}, {nullptr}, n); oscSinProcess<1>({instance->buf}, {instance->buf}, n); if (instance->params[p_a440] >= 0.5f) - bufMix<1>({out}, {out}, {instance->buf}, n); + bufMix<1>({out}, {instance->buf}, {out}, n); instance->gain.process({out}, {out}, n); instance->ppm.process({out}, {nullptr}, n); diff --git a/include/bw_buf.h b/include/bw_buf.h index ba5f418..7da174b 100644 --- a/include/bw_buf.h +++ b/include/bw_buf.h @@ -35,6 +35,8 @@ *
  • Added more const specifiers to input * arguments.
  • *
  • Moved C++ code to C header.
  • + *
  • Added overladed C++ functions taking C-style arrays as + * arguments.
  • *
  • Removed usage of reserved identifiers.
  • * * @@ -176,7 +178,13 @@ namespace Brickworks { * ##### Brickworks::bufFill * ```>>> */ template -void bufFill( +inline void bufFill( + float k, + float ** dest, + int nSamples); + +template +inline void bufFill( float k, std::array dest, int nSamples); @@ -185,7 +193,13 @@ void bufFill( * ##### Brickworks::bufNeg * ```>>> */ template -void bufNeg( +inline void bufNeg( + const float * const *src, + float **dest, + int nSamples); + +template +inline void bufNeg( std::array src, std::array dest, int nSamples); @@ -194,7 +208,14 @@ void bufNeg( * ##### Brickworks::bufAdd * ```>>> */ template -void bufAdd( +inline void bufAdd( + const float * const *src, + float **dest, + float k, + int nSamples); + +template +inline void bufAdd( std::array src, std::array dest, float k, @@ -204,7 +225,14 @@ void bufAdd( * ##### Brickworks::bufScale * ```>>> */ template -void bufScale( +inline void bufScale( + const float * const *src, + float k, + float **dest, + int nSamples); + +template +inline void bufScale( std::array src, std::array dest, float k, @@ -214,7 +242,14 @@ void bufScale( * ##### Brickworks::bufMix * ```>>> */ template -void bufMix( +inline void bufMix( + const float * const *src1, + const float * const *src2, + float **dest, + int nSamples); + +template +inline void bufMix( std::array src1, std::array src2, std::array dest, @@ -224,7 +259,14 @@ void bufMix( * ##### Brickworks::bufMul * ```>>> */ template -void bufMul( +inline void bufMul( + const float * const *src1, + const float * const *src2, + float **dest, + int nSamples); + +template +inline void bufMul( std::array src1, std::array src2, std::array dest, @@ -355,12 +397,28 @@ static inline void bw_buf_mul_multi(const float * const *src1, const float * con namespace Brickworks { +template +inline void bufFill( + float k, + float ** dest, + int nSamples) { + bw_buf_fill_multi(k, dest, N_CHANNELS, nSamples); +} + template inline void bufFill( float k, std::array dest, int nSamples) { - bw_buf_fill_multi(k, dest.data(), N_CHANNELS, nSamples); + bufFill(k, dest.data(), nSamples); +} + +template +inline void bufNeg( + const float * const *src, + float **dest, + int nSamples) { + bw_buf_neg_multi(src, dest, N_CHANNELS, nSamples); } template @@ -368,7 +426,16 @@ inline void bufNeg( std::array src, std::array dest, int nSamples) { - bw_buf_neg_multi(src.data(), dest.data(), N_CHANNELS, nSamples); + bufNeg(src, dest, nSamples); +} + +template +inline void bufAdd( + const float * const *src, + float **dest, + float k, + int nSamples) { + bw_buf_add_multi(src, k, dest, N_CHANNELS, nSamples); } template @@ -377,7 +444,16 @@ inline void bufAdd( float k, std::array dest, int nSamples) { - bw_buf_add_multi(src.data(), k, dest.data(), N_CHANNELS, nSamples); + bufAdd(src, k, dest, nSamples); +} + +template +inline void bufScale( + const float * const *src, + float k, + float **dest, + int nSamples) { + bw_buf_scale_multi(src, k, dest, N_CHANNELS, nSamples); } template @@ -386,7 +462,16 @@ inline void bufScale( float k, std::array dest, int nSamples) { - bw_buf_scale_multi(src.data(), k, dest.data(), N_CHANNELS, nSamples); + bufScale(src, k, dest, nSamples); +} + +template +inline void bufMix( + const float * const *src1, + const float * const *src2, + float **dest, + int nSamples) { + bw_buf_mix_multi(src1, src2, dest, N_CHANNELS, nSamples); } template @@ -395,7 +480,16 @@ inline void bufMix( std::array src2, std::array dest, int nSamples) { - bw_buf_mix_multi(src1.data(), src2.data(), dest.data(), N_CHANNELS, nSamples); + bufMix(src1, src2, dest, nSamples); +} + +template +inline void bufMul( + const float * const *src1, + const float * const *src2, + float **dest, + int nSamples) { + bw_buf_mul_multi(src1, src2, dest, N_CHANNELS, nSamples); } template @@ -404,7 +498,7 @@ inline void bufMul( std::array src2, std::array dest, int nSamples) { - bw_buf_mul_multi(src1.data(), src2.data(), dest.data(), N_CHANNELS, nSamples); + bufMul(src1, src2, dest, nSamples); } }