From 7c93f655a9242a6c430d2a03eb0f419003b75c22 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 16 Sep 2019 15:56:32 +0200 Subject: [PATCH] Fixed initial modulated delay offset when loading a sound. Removed modulated_delay internal feedback loop and added an "external" feedback lopp with a mixer. --- MicroMDAEPiano.ino | 32 +++++++++++++++++++++++--------- UI.hpp | 13 ++++++++++--- config.h | 4 ++++ effect_modulated_delay.cpp | 14 +------------- effect_modulated_delay.h | 3 --- 5 files changed, 38 insertions(+), 28 deletions(-) diff --git a/MicroMDAEPiano.ino b/MicroMDAEPiano.ino index 7b9ccef..dc3cdb4 100644 --- a/MicroMDAEPiano.ino +++ b/MicroMDAEPiano.ino @@ -54,6 +54,8 @@ AudioMixer4 mixer_l; AudioAmplifier volume_r; AudioAmplifier volume_l; AudioAmplifier inverter; +AudioMixer4 modchorus_fbk_mixer_r; +AudioMixer4 modchorus_fbk_mixer_l; AudioEffectModulatedDelay modchorus_r; AudioEffectModulatedDelay modchorus_l; AudioSynthWaveform modulator; @@ -61,13 +63,17 @@ AudioConnection patchCord0(queue_r, peak_r); AudioConnection patchCord1(queue_l, peak_l); AudioConnection patchCord2(queue_r, freeverb_r); AudioConnection patchCord3(queue_l, freeverb_l); -AudioConnection patchCord4(queue_r, 0, modchorus_r, 0); -AudioConnection patchCord5(queue_l, 0, modchorus_l, 0); -AudioConnection patchCord8(modulator, 0, modchorus_r, 1); -AudioConnection patchCord9(modulator, inverter); -AudioConnection patchCord10(inverter, 0, modchorus_l, 1); -AudioConnection patchCord11(queue_r, 0, mixer_r, 0); -AudioConnection patchCord12(queue_l, 0, mixer_l, 0); +AudioConnection patchCord4(queue_r, 0, modchorus_fbk_mixer_r, 0); +AudioConnection patchCord5(queue_l, 0, modchorus_fbk_mixer_l, 0); +AudioConnection patchCord6(modchorus_fbk_mixer_r, 0, modchorus_r, 0); +AudioConnection patchCord7(modchorus_fbk_mixer_l, 0, modchorus_l, 0); +AudioConnection patchCord8(modchorus_r, 0, modchorus_r, 1); +AudioConnection patchCord9(modchorus_l, 0, modchorus_l, 1); +AudioConnection patchCord10(modulator, 0, modchorus_r, 1); +AudioConnection patchCord11(modulator, inverter); +AudioConnection patchCord12(inverter, 0, modchorus_l, 1); +AudioConnection patchCord13(queue_r, 0, mixer_r, 0); +AudioConnection patchCord14(queue_l, 0, mixer_l, 0); AudioConnection patchCord15(modchorus_r, 0, mixer_r, 2); AudioConnection patchCord16(modchorus_l, 0, mixer_l, 2); AudioConnection patchCord17(freeverb_r, 0, mixer_r, 1); @@ -235,11 +241,19 @@ void setup() modulator.phase(0); modulator.amplitude(1.0); modulator.offset(0.0); +#ifdef MOD_STEREO inverter.gain(-1.0); // change phase for second modulated delay (faked stereo mode) +#else + inverter.gain(1.0); +#endif modchorus_r.offset(15.0); modchorus_l.offset(15.0); - modchorus_r.feedback(0.25); - modchorus_l.feedback(0.25); + //modchorus_r.feedback(0.25); + //modchorus_l.feedback(0.25); + modchorus_fbk_mixer_r.gain(0, 0.75); + modchorus_fbk_mixer_l.gain(0, 0.75); + modchorus_fbk_mixer_r.gain(1, 0.25); + modchorus_fbk_mixer_l.gain(1, 0.25); // internal mixing of original signal(0), reverb(1) and chorus(2) mixer_r.gain(VOL_MAIN, 0.5); diff --git a/UI.hpp b/UI.hpp index 15db4be..9128700 100644 --- a/UI.hpp +++ b/UI.hpp @@ -126,6 +126,8 @@ extern AudioEffectFreeverb freeverb_l; extern AudioSynthWaveform modulator; extern AudioEffectModulatedDelay modchorus_r; extern AudioEffectModulatedDelay modchorus_l; +extern AudioMixer4 modchorus_fbk_mixer_r; +extern AudioMixer4 modchorus_fbk_mixer_l; extern AudioMixer4 mixer_r; extern AudioMixer4 mixer_l; extern AudioAmplifier volume_r; @@ -2206,8 +2208,13 @@ void set_chorus_feedback(uint8_t value) Serial.print(F("Set CHORUS_FEEDBACK ")); Serial.println(value); #endif - modchorus_r.feedback(mapfloat(float(value), ENC_CHORUS_FEEDBACK_MIN, ENC_CHORUS_FEEDBACK_MAX, 0.0, 1.0)); - modchorus_l.feedback(mapfloat(float(value), ENC_CHORUS_FEEDBACK_MIN, ENC_CHORUS_FEEDBACK_MAX, 0.0, 1.0)); + //modchorus_r.feedback(mapfloat(float(value), ENC_CHORUS_FEEDBACK_MIN, ENC_CHORUS_FEEDBACK_MAX, 0.0, 1.0)); + //modchorus_l.feedback(mapfloat(float(value), ENC_CHORUS_FEEDBACK_MIN, ENC_CHORUS_FEEDBACK_MAX, 0.0, 1.0)); + float tmp = mapfloat(float(value), ENC_CHORUS_FEEDBACK_MIN, ENC_CHORUS_FEEDBACK_MAX, 0.0, 0.5); + modchorus_fbk_mixer_r.gain(0, 1.0 - tmp); + modchorus_fbk_mixer_l.gain(0, 1.0 - tmp); + modchorus_fbk_mixer_r.gain(1, tmp); + modchorus_fbk_mixer_l.gain(1, tmp); configuration.chorus_feedback = value; } @@ -2630,7 +2637,7 @@ void handle_ui(void) if (encoder_tmp != encoder_value[RIGHT_ENCODER]) { // value up/down - set_chorus_delay(encoder_tmp); + set_chorus_delay(encoder_tmp / 10); menu_system.update(); } } diff --git a/config.h b/config.h index c1ad9d0..258f9d2 100644 --- a/config.h +++ b/config.h @@ -30,6 +30,9 @@ // ATTENTION! For better latency you have to redefine AUDIO_BLOCK_SAMPLES from // 128 to 64 in /cores/teensy3/AudioStream.h +// arecord -f cd -Dhw:1,0 /tmp/bla.wav +// aplaymidi -p 20:0 test.mid + //************************************************************************************************* //* DEVICE SETTINGS //************************************************************************************************* @@ -57,6 +60,7 @@ // CHORUS parameters #define CHORUS_DELAY_LENGTH_SAMPLES (16*AUDIO_BLOCK_SAMPLES) // one AUDIO_BLOCK_SAMPLES = 2.902ms #define WAVEFORM_MOD WAVEFORM_TRIANGLE // WAVEFORM_SINE WAVEFORM_TRIANGLE WAVEFORM_SAWTOOTH WAVEFORM_SAWTOOTH_REVERSE +//#define MOD_STEREO 1 //************************************************************************************************* //* DEBUG OUTPUT SETTINGS //************************************************************************************************* diff --git a/effect_modulated_delay.cpp b/effect_modulated_delay.cpp index 7298a7b..a1abaaf 100644 --- a/effect_modulated_delay.cpp +++ b/effect_modulated_delay.cpp @@ -51,8 +51,6 @@ boolean AudioEffectModulatedDelay::begin(short *delayline, int d_length) _delay_length = 0; _delay_offset = 0.0; _cb_index = 0; - _feedback = 0.0; - _feedback_value = 0; if (delayline == NULL) { return (false); @@ -82,16 +80,6 @@ float AudioEffectModulatedDelay::offset(float offset_value) // in ms return (floor(offset_frames / AUDIO_SAMPLE_RATE * 1000)); } -void AudioEffectModulatedDelay::feedback(float feedback_level) -{ - if (feedback_level < 0.0) - feedback_level = 0.0; - else if (feedback_level > 1.0) - feedback_level = 1.0; - - _feedback = feedback_level / 2; -} - void AudioEffectModulatedDelay::update(void) { audio_block_t *block; @@ -122,7 +110,7 @@ void AudioEffectModulatedDelay::update(void) // write data into circular buffer (delayline) if (_cb_index >= _delay_length) _cb_index = 0; - _delayline[_cb_index] = (*bp * (1.0 - _feedback)) + (_feedback_value * _feedback); + _delayline[_cb_index] = *bp; // calculate the modulation-index as a floating point number for interpolation mod_index = *mp * MODULATION_MAX_FACTOR * _delay_length; diff --git a/effect_modulated_delay.h b/effect_modulated_delay.h index 33e431b..1a82d22 100644 --- a/effect_modulated_delay.h +++ b/effect_modulated_delay.h @@ -45,7 +45,6 @@ class AudioEffectModulatedDelay : boolean begin(short *delayline, int delay_length); virtual void update(void); virtual float offset(float offset_value); - virtual void feedback(float feedback_value); private: void set_modulator_filter_coeffs(void); @@ -54,8 +53,6 @@ class AudioEffectModulatedDelay : uint16_t _cb_index; // current write pointer of the circular buffer uint16_t _delay_offset; // number of samples for the read offset of the modulation inside the circular buffer uint16_t _delay_length; // calculated number of samples of the delay - float32_t _feedback; - int16_t _feedback_value; int16_t cb_mod_index; // current read pointer with modulation for the circular buffer };