From d4a850f632e7094a85febf916b9724ff53f2e949 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Sat, 8 Feb 2014 06:39:55 +0100 Subject: [PATCH] Vocoder: more improvements --- gui/gui-vocoder.xml | 2 +- src/calf/metadata.h | 3 +-- src/calf/modules_filter.h | 3 --- src/metadata.cpp | 3 +-- src/modules_filter.cpp | 38 +++++++++++++++++++++++++------------- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/gui/gui-vocoder.xml b/gui/gui-vocoder.xml index c3bef08..8dc96d0 100644 --- a/gui/gui-vocoder.xml +++ b/gui/gui-vocoder.xml @@ -63,7 +63,7 @@ - + diff --git a/src/calf/metadata.h b/src/calf/metadata.h index 2848b5b..efe7926 100644 --- a/src/calf/metadata.h +++ b/src/calf/metadata.h @@ -424,8 +424,7 @@ struct vocoder_metadata: public plugin_metadata param_carrier_in, param_carrier_inL, param_carrier_inR, param_carrier_clip_inL, param_carrier_clip_inR, param_mod_in, param_mod_inL, param_mod_inR, param_mod_clip_inL, param_mod_clip_inR, param_out, param_outL, param_outR, param_clip_outL, param_clip_outR, - param_carrier, param_mod, param_proc, - param_bands_knob, param_bands_disp, + param_carrier, param_mod, param_proc, param_bands, param_attack, param_release, param_analyzer, param_volume0, param_pan0, param_noise0, param_active0, param_volume1, param_pan1, param_noise1, param_active1, diff --git a/src/calf/modules_filter.h b/src/calf/modules_filter.h index 3fa9d2b..40bb438 100644 --- a/src/calf/modules_filter.h +++ b/src/calf/modules_filter.h @@ -368,9 +368,6 @@ public: int clip[] = {param_carrier_clip_inL, param_carrier_clip_inR, param_mod_clip_inL, param_mod_clip_inR, param_clip_outL, param_clip_outR}; meters.init(params, meter, clip, 6, sr); } - virtual float freq_gain(int index, double freq) const { - return detector[0][index].freq_gain(freq, (float)srate); - } virtual bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const; virtual bool get_layers(int index, int generation, unsigned int &layers) const; uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask); diff --git a/src/metadata.cpp b/src/metadata.cpp index 4b34f3f..ce14701 100644 --- a/src/metadata.cpp +++ b/src/metadata.cpp @@ -836,8 +836,7 @@ CALF_PORT_PROPS(vocoder) = { { 0, 0.000015849, 16, 0, PF_FLOAT | PF_SCALE_GAIN | PF_CTL_KNOB | PF_UNIT_DB, NULL, "modulator", "Modulator" }, { 1, 0.000015849, 16, 0, PF_FLOAT | PF_SCALE_GAIN | PF_CTL_KNOB | PF_UNIT_DB, NULL, "processed", "Processed" }, - { 0, 0, 3, 0, PF_INT | PF_SCALE_LINEAR | PF_CTL_KNOB | PF_UNIT_COEF, NULL, "bands_knob", "Bands" }, - { 4, 4, 32, 0, PF_INT | PF_SCALE_LINEAR | PF_CTL_KNOB | PF_UNIT_COEF, NULL, "bands_disp", "Bands Amount" }, + { 16, 4, 32, 0, PF_INT | PF_SCALE_LINEAR | PF_CTL_KNOB | PF_UNIT_COEF, NULL, "bands", "Bands" }, { 6.f, 0.1f, 500.f, 0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_KNOB | PF_UNIT_MSEC, NULL, "attack", "Attack" }, { 20.f, 0.1f, 5000.f, 0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_KNOB | PF_UNIT_MSEC, NULL, "release", "Release" }, diff --git a/src/modules_filter.cpp b/src/modules_filter.cpp index c53aa03..0511e8d 100644 --- a/src/modules_filter.cpp +++ b/src/modules_filter.cpp @@ -885,7 +885,7 @@ void vocoder_audio_module::params_changed() attack = exp(log(0.01)/( *params[param_attack] * srate * 0.001)); release = exp(log(0.01)/( *params[param_release] * srate * 0.001)); - bands = 4 * (1 << (int)*params[param_bands_knob]); + bands = *params[param_bands]; if (bands != bands_old) { bands_old = bands; for (int i = 0; i < 32; i++) { @@ -893,16 +893,16 @@ void vocoder_audio_module::params_changed() *params[param_active0 + i * 4] = i < bands ? 1 : 0; if(i < bands) { // set all actually used filters - detector[0][i].set_bp_rbj(pow(10, fcoeff + (0.5f + (float)i) * 3.f / (float)bands), 1.0, (double)srate); + detector[0][i].set_bp_rbj(pow(10, fcoeff + (0.5f + (float)i) * 3.f / (float)bands), pow(0.707, 1.0 / (bands / 4)), (double)srate); detector[1][i].copy_coeffs(detector[0][i]); modulator[0][i].copy_coeffs(detector[0][i]); modulator[1][i].copy_coeffs(detector[0][i]); } } - redraw_graph = true; } //void analyzer::set_params(float resolution, float offset, int accuracy, int hold, int smoothing, int mode, int scale, int post, int speed, int windowing, int view, int freeze) _analyzer.set_params(256, 1, 6, 0, 1, 0, 0, 0, 15, 2, 0, 0); + redraw_graph = true; } uint32_t vocoder_audio_module::process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask) @@ -930,25 +930,33 @@ uint32_t vocoder_audio_module::process(uint32_t offset, uint32_t numsamples, uin // carrier with level double cL = ins[0][offset] * *params[param_carrier_in]; - double cR = ins[(!*params[param_mono] > 0.5f) ? 1 : 0][offset] * *params[param_carrier_in]; + double cR = ins[1][offset] * *params[param_carrier_in]; // modulator with level double mL = ins[2][offset] * *params[param_mod_in]; - double mR = ins[(!*params[param_mono] > 0.5f) ? 3 : 2][offset] * *params[param_mod_in]; + double mR = ins[3][offset] * *params[param_mod_in]; // noise generator double nL = (float)rand() / (float)RAND_MAX; - double nR = *params[param_mono] > 0.5f ? nL : (float)rand() / (float)RAND_MAX; + double nR = (float)rand() / (float)RAND_MAX; for (int i = 0; i < bands; i++) { + double mL_ = mL; + double mR_ = mR; + double cL_ = cL + nL * *params[param_noise0 + i * 4]; + double cR_ = cR + nR * *params[param_noise0 + i * 4]; // filter modulator - double mL_ = detector[0][i].process(mL); - double mR_ = detector[1][i].process(mR); - + if (*params[param_mono] > 0.5) { + mL_ = detector[0][i].process(std::max(mL_, mR_)); + mR_ = mL_; + } else { + mL_ = detector[0][i].process(mL); + mR_ = detector[1][i].process(mR); + } // filter carrier with noise - double cL_ = modulator[0][i].process(cL + nL * *params[param_noise0 + i * 4]); - double cR_ = modulator[1][i].process(cL + nR * *params[param_noise0 + i * 4]); + cL_ = modulator[0][i].process(cL_); + cR_ = modulator[1][i].process(cR_); // level by envelope cL_ *= envelope[0][i]; @@ -1026,10 +1034,14 @@ uint32_t vocoder_audio_module::process(uint32_t offset, uint32_t numsamples, uin bool vocoder_audio_module::get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const { if (phase and *params[param_analyzer]) { + if (subindex) { + redraw_graph = false; + return false; + } bool r = _analyzer.get_graph(subindex, phase, data, points, context, mode); context->set_source_rgba(0,0,0,0.1); return r; - } else if (phase and (!*params[param_analyzer] or subindex)) { + } else if (phase) { redraw_graph = false; return false; } else { @@ -1040,7 +1052,7 @@ bool vocoder_audio_module::get_graph(int index, int subindex, int phase, float * } else { for (int i = 0; i < points; i++) { double freq = 20.0 * pow (20000.0 / 20.0, i * 1.0 / points); - data[i] = dB_grid(detector[0][subindex].freq_gain(freq, srate), 256, 0.4); + data[i] = dB_grid(detector[0][subindex].freq_gain(freq, srate) * *params[param_volume0 + subindex * 4], 256, 0.4); } } } -- 2.11.4.GIT