From 4244fe6727d556b6f8889a4839cf6686ea550c92 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Tue, 24 Sep 2019 13:33:25 +0200 Subject: [PATCH] Several small fixes for modulated delay offset and amplitude calculation. --- MicroMDAEPiano.ino | 18 ++++++++++++------ UI.hpp | 2 +- config.h | 10 +++++----- effect_modulated_delay.cpp | 13 ++++++++----- effect_modulated_delay.h | 8 +++----- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/MicroMDAEPiano.ino b/MicroMDAEPiano.ino index 6b7f6b3..6e986df 100644 --- a/MicroMDAEPiano.ino +++ b/MicroMDAEPiano.ino @@ -248,17 +248,23 @@ void setup() modulator.offset(0.0); #ifdef DEBUG Serial.print(F("Modulated delay buffer: ")); + Serial.print(SAMPLES2TIME_MS(MOD_DELAY_SAMPLE_BUFFER), 2); + Serial.print(F(" ms / ")); Serial.print(MOD_DELAY_SAMPLE_BUFFER, DEC); Serial.println(F(" samples")); - Serial.print(F("Default delay time: ")); - Serial.print(float(ENC_CHORUS_DELAY_DEFAULT) / 10, 2); - Serial.println(" ms"); Serial.print(F("Max delay time: ")); Serial.print(float(ENC_CHORUS_DELAY_MAX) / 10, 2); - Serial.println(F(" ms")); + Serial.print(F(" ms / ")); + Serial.print(uint16_t(TIME_MS2SAMPLES(float(ENC_CHORUS_DELAY_MAX) / 10)), DEC); + Serial.println(F(" samples")); + Serial.print(F("Default delay time: ")); + Serial.print(float(ENC_CHORUS_DELAY_DEFAULT) / 10, 2); + Serial.print(F(" ms / ")); + Serial.print(uint16_t(TIME_MS2SAMPLES(float(ENC_CHORUS_DELAY_DEFAULT) / 10)), DEC); + Serial.println(F(" samples")); #endif - modchorus_r.offset(TIME_MS2SAMPLES(float(ENC_CHORUS_DELAY_DEFAULT) / 10)); - modchorus_l.offset(TIME_MS2SAMPLES(float(ENC_CHORUS_DELAY_DEFAULT) / 10)); + modchorus_r.offset(TIME_MS2SAMPLES(float(ENC_CHORUS_DELAY_MAX) / 10)); + modchorus_l.offset(TIME_MS2SAMPLES(float(ENC_CHORUS_DELAY_MAX) / 10)); // Butterworth filter, 12 db/octave modchorus_filter_r.setLowpass(0, 6000, 0.707); modchorus_filter_l.setLowpass(0, 6000, 0.707); diff --git a/UI.hpp b/UI.hpp index a912005..e1d08af 100644 --- a/UI.hpp +++ b/UI.hpp @@ -243,7 +243,7 @@ char* get_chorus_frequency_value_text(void) char chorus_delay_value_text1[] = " "; char* get_chorus_delay_value_text(void) { - sprintf(chorus_delay_value_text1, "%02.1f ms", float(configuration.chorus_delay + ENC_CHORUS_DELAY_MAX) / 10); + sprintf(chorus_delay_value_text1, "%02.1f ms", float(configuration.chorus_delay) / 10); return (chorus_delay_value_text1); } diff --git a/config.h b/config.h index e5c5e76..f1efbab 100644 --- a/config.h +++ b/config.h @@ -59,8 +59,8 @@ #define USE_XFADE_DATA 1 /* HELPER MACROS */ -#define TIME_MS2SAMPLES(x) floor(x * AUDIO_SAMPLE_RATE / 1000) -#define SAMPLES2TIME_MS(x) float(x * 1000 / AUDIO_SAMPLE_RATE) +#define TIME_MS2SAMPLES(x) floor(uint32_t(x) * AUDIO_SAMPLE_RATE / 1000) +#define SAMPLES2TIME_MS(x) float(uint32_t(x) * 1000 / AUDIO_SAMPLE_RATE) // CHORUS parameters #define MOD_DELAY_SAMPLE_BUFFER int32_t(TIME_MS2SAMPLES(10.0)) #define MOD_WAVEFORM WAVEFORM_TRIANGLE // WAVEFORM_SINE WAVEFORM_TRIANGLE WAVEFORM_SAWTOOTH WAVEFORM_SAWTOOTH_REVERSE @@ -238,9 +238,9 @@ #define ENC_CHORUS_FREQUENCY_MAX 200 #define ENC_CHORUS_FREQUENCY_DEFAULT 30 // -#define ENC_CHORUS_DELAY_MIN 0 -#define ENC_CHORUS_DELAY_MAX uint8_t(SAMPLES2TIME_MS(float(MOD_DELAY_SAMPLE_BUFFER/2)*10)) -#define ENC_CHORUS_DELAY_DEFAULT uint8_t(float(ENC_CHORUS_DELAY_MAX/2)) +#define ENC_CHORUS_DELAY_MIN uint8_t(SAMPLES2TIME_MS(MOD_DELAY_SAMPLE_BUFFER>>2)*10+0.5) +#define ENC_CHORUS_DELAY_MAX uint8_t(SAMPLES2TIME_MS(MOD_DELAY_SAMPLE_BUFFER>>2)*30+0.5) +#define ENC_CHORUS_DELAY_DEFAULT uint8_t(SAMPLES2TIME_MS(MOD_DELAY_SAMPLE_BUFFER>>2)*20+0.5) // #define ENC_CHORUS_INTENSITY_MIN 0 #define ENC_CHORUS_INTENSITY_MAX 100 diff --git a/effect_modulated_delay.cpp b/effect_modulated_delay.cpp index 0b0d897..1925fc8 100644 --- a/effect_modulated_delay.cpp +++ b/effect_modulated_delay.cpp @@ -29,8 +29,6 @@ extern config_t configuration; -#define MODULATION_MAX_FACTOR 0.5 // Not sure to put this into a var? - /******************************************************************/ // Based on; A u d i o E f f e c t D e l a y @@ -39,7 +37,7 @@ extern config_t configuration; // 140219 - correct storage class (not static) // 190527 - added modulation input (by Holger Wirtz) -boolean AudioEffectModulatedDelay::begin(short *delayline, int d_length) +boolean AudioEffectModulatedDelay::begin(short *delayline, uint16_t d_length) { #if 0 Serial.print(F("AudioEffectModulatedDelay.begin(modulated-delay line length = ")); @@ -66,13 +64,18 @@ boolean AudioEffectModulatedDelay::begin(short *delayline, int d_length) return (true); } -void AudioEffectModulatedDelay::offset(uint8_t offset_value) // in % +void AudioEffectModulatedDelay::offset(uint16_t offset_value) // in % { if (offset_value > 100) offset_value = 100; _delay_offset = floor(offset_value / 200.0 * _delay_length); } +uint16_t AudioEffectModulatedDelay::get_delay_length(void) +{ + return (_delay_length); +} + void AudioEffectModulatedDelay::update(void) { audio_block_t *block; @@ -106,7 +109,7 @@ void AudioEffectModulatedDelay::update(void) _delayline[_cb_index] = *bp; // calculate the modulation-index as a floating point number for interpolation - mod_index = *mp * MODULATION_MAX_FACTOR * _delay_length; + mod_index = *mp * (_delay_length >> 2); mod_fraction = modff(mod_index, &mod_number); // split float of mod_index into integer (= mod_number) and fraction part // calculate modulation index into circular buffer diff --git a/effect_modulated_delay.h b/effect_modulated_delay.h index 9c38aec..826b5c3 100644 --- a/effect_modulated_delay.h +++ b/effect_modulated_delay.h @@ -34,9 +34,6 @@ // 140219 - correct storage class (not static) // 190527 - added modulation input handling (Aug 2019 by Holger Wirtz) -#define TIME_MS2SAMPLES(x) floor(x * AUDIO_SAMPLE_RATE / 1000) -#define SAMPLES2TIME_MS(x) float(x * 1000 / AUDIO_SAMPLE_RATE) - class AudioEffectModulatedDelay : public AudioStream { @@ -45,9 +42,10 @@ class AudioEffectModulatedDelay : AudioStream(2, inputQueueArray) { } - boolean begin(short *delayline, int delay_length); + boolean begin(short *delayline, uint16_t delay_length); virtual void update(void); - virtual void offset(uint8_t offset_value); + virtual void offset(uint16_t offset_value); + virtual uint16_t get_delay_length(void); private: void set_modulator_filter_coeffs(void);