From 3f0279987dae8e00c0a456c1f884404d01d3c0b4 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 22 Jul 2021 16:35:50 +0200 Subject: [PATCH] Fixed problems with input block handling in modulated_delay and mono_stereo. --- MicroDexed.ino | 47 +++++++++++++++++++------------ config.h | 4 +++ effect_modulated_delay.cpp | 35 ++++++++++++++++++++--- effect_mono_stereo.cpp | 57 ++++++++++++++++++++++++++++---------- 4 files changed, 106 insertions(+), 37 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index a208ed3..fa8152c 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -82,7 +82,7 @@ AudioMixer4 audio_thru_mixer_l; #endif // Drumset -#ifdef NUM_DRUMS +#if NUM_DRUMS > 0 AudioPlaySdRaw* Drum[NUM_DRUMS]; AudioEffectMonoStereo* drum_mono2stereo[NUM_DRUMS]; AudioMixer4 drum_mixer_r; @@ -158,7 +158,7 @@ AudioConnection patchCord19(audio_thru_mixer_r, 0, i2s1, 0); AudioConnection patchCord20(audio_thru_mixer_l, 0, i2s1, 1); #endif -#ifdef NUM_DRUMS +#if NUM_DRUMS > 0 #ifdef USE_FX AudioConnection patchCord21(drum_mixer_r, 0, reverb_mixer_r, 2); AudioConnection patchCord22(drum_mixer_l, 0, reverb_mixer_l, 2); @@ -173,13 +173,13 @@ AudioConnection patchCord22(drum_mixer_l, 0, master_mixer_l, 2); // // Dynamic patching of MicroDexed objects // -uint16_t nDynamic = 0; +uint8_t nDynamic = 0; #if defined(USE_FX) && MOD_FILTER_OUTPUT != MOD_NO_FILTER_OUTPUT -AudioConnection * dynamicConnections[NUM_DEXED * 17]; +AudioConnection* dynamicConnections[NUM_DEXED * 16 + NUM_DRUMS * 3 ]; #elif defined(USE_FX) && MOD_FILTER_OUTPUT == MOD_NO_FILTER_OUTPUT -AudioConnection * dynamicConnections[NUM_DEXED * 16]; +AudioConnection* dynamicConnections[NUM_DEXED * 15 + NUM_DRUMS * 3]; #else -AudioConnection * dynamicConnections[NUM_DEXED * 5]; +AudioConnection* dynamicConnections[NUM_DEXED * 4 + NUM_DRUMS * 3]; #endif void create_audio_dexed_chain(uint8_t instance_id) { @@ -198,10 +198,9 @@ void create_audio_dexed_chain(uint8_t instance_id) #endif dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, microdexed_peak_mixer, instance_id); - #if defined(USE_FX) dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *chorus_mixer[instance_id], 0); - dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *modchorus[instance_id], 0); + dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *modchorus[instance_id], 0); ////////////////////// #if MOD_FILTER_OUTPUT != MOD_NO_FILTER_OUTPUT dynamicConnections[nDynamic++] = new AudioConnection(*chorus_modulator[instance_id], 0, *modchorus_filter[instance_id], 0); dynamicConnections[nDynamic++] = new AudioConnection(*modchorus_filter[instance_id], 0, *modchorus[instance_id], 1); @@ -222,22 +221,34 @@ void create_audio_dexed_chain(uint8_t instance_id) #endif dynamicConnections[nDynamic++] = new AudioConnection(*mono2stereo[instance_id], 0, master_mixer_r, instance_id); dynamicConnections[nDynamic++] = new AudioConnection(*mono2stereo[instance_id], 1, master_mixer_l, instance_id); + +#ifdef DEBUG + Serial.print(F("Dexed-Instance: ")); + Serial.println(instance_id); + Serial.print(F("Dynamic-Connection-Counter=")); + Serial.println(nDynamic); +#endif } // // Dynamic patching of Drum objects // -#ifdef NUM_DRUMS -uint16_t nDrumDynamic = 0; -AudioConnection* dynamicDrumConnections[NUM_DRUMS * 3]; +#if NUM_DRUMS > 0 void create_audio_drum_chain(uint8_t instance_id) { Drum[instance_id] = new AudioPlaySdRaw(); drum_mono2stereo[instance_id] = new AudioEffectMonoStereo(); - dynamicDrumConnections[nDrumDynamic++] = new AudioConnection(*Drum[instance_id], 0, *drum_mono2stereo[instance_id], 0); - dynamicDrumConnections[nDrumDynamic++] = new AudioConnection(*drum_mono2stereo[instance_id], 0, drum_mixer_r, instance_id); - dynamicDrumConnections[nDrumDynamic++] = new AudioConnection(*drum_mono2stereo[instance_id], 1, drum_mixer_l, instance_id); + dynamicConnections[nDynamic++] = new AudioConnection(*Drum[instance_id], 0, *drum_mono2stereo[instance_id], 0); + dynamicConnections[nDynamic++] = new AudioConnection(*drum_mono2stereo[instance_id], 0, drum_mixer_r, instance_id); + dynamicConnections[nDynamic++] = new AudioConnection(*drum_mono2stereo[instance_id], 1, drum_mixer_l, instance_id); + +#ifdef DEBUG + Serial.print(F("Drum-Instance: ")); + Serial.println(instance_id); + Serial.print(F("Dynamic-Connection-Counter=")); + Serial.println(nDynamic); +#endif } #endif @@ -423,7 +434,7 @@ void setup() } #endif -#ifdef NUM_DRUMS +#if NUM_DRUMS > 0 // create dynamic Drum instances for (uint8_t instance_id = 0; instance_id < NUM_DRUMS; instance_id++) { @@ -534,7 +545,7 @@ void setup() master_mixer_r.gain(1, 0.0); master_mixer_l.gain(1, 0.0); #endif -#ifdef NUM_DRUMS +#if NUM_DRUMS > 0 master_mixer_r.gain(2, 1.0); master_mixer_l.gain(2, 1.0); #else @@ -697,7 +708,7 @@ void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity) } } -#ifdef NUM_DRUMS +#if NUM_DRUMS > 0 static uint8_t drum_counter; // Check for Drum @@ -2040,7 +2051,7 @@ void set_fx_params(void) freeverb.damping(mapfloat(configuration.fx.reverb_damping, REVERB_DAMPING_MIN, REVERB_DAMPING_MAX, 0.0, 1.0)); #endif -#ifdef NUM_DRUMS +#if NUM_DRUMS > 0 #ifdef USE_FX reverb_mixer_r.gain(2, 1.0); // Drums-Send reverb_mixer_l.gain(2, 1.0); // Drums-Send diff --git a/config.h b/config.h index 7871f87..703ec18 100644 --- a/config.h +++ b/config.h @@ -301,6 +301,10 @@ #define EEPROM_MARKER 0x4242 +#ifndef NUM_DRUMS +#define NUM_DRUMS 0 +#endif + // MAX_NOTES SETTINGS // Teensy-4.x settings #ifdef TEENSY4 diff --git a/effect_modulated_delay.cpp b/effect_modulated_delay.cpp index 22d5af9..4cb0c58 100644 --- a/effect_modulated_delay.cpp +++ b/effect_modulated_delay.cpp @@ -37,6 +37,33 @@ extern config_t configuration; // 140219 - correct storage class (not static) // 190527 - added modulation input (by Holger Wirtz) +static const audio_block_t zeroblock = { + 0, 0, 0, { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#if AUDIO_BLOCK_SAMPLES > 16 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#endif +#if AUDIO_BLOCK_SAMPLES > 32 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#endif +#if AUDIO_BLOCK_SAMPLES > 48 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#endif +#if AUDIO_BLOCK_SAMPLES > 64 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#endif +#if AUDIO_BLOCK_SAMPLES > 80 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#endif +#if AUDIO_BLOCK_SAMPLES > 96 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#endif +#if AUDIO_BLOCK_SAMPLES > 112 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#endif + } +}; + boolean AudioEffectModulatedDelay::begin(short *delayline, uint16_t d_length) { #if 0 @@ -78,11 +105,11 @@ void AudioEffectModulatedDelay::update(void) block = receiveWritable(0); if (!block) - return; + block = (audio_block_t*)&zeroblock; modulation = receiveReadOnly(1); if (!modulation) - return; + modulation = (audio_block_t*)&zeroblock; if (block && modulation) { @@ -128,10 +155,10 @@ void AudioEffectModulatedDelay::update(void) } } - if (modulation) + if (modulation != (audio_block_t*)&zeroblock) release(modulation); - if (block) + if (block != (audio_block_t*)&zeroblock) { transmit(block, 0); release(block); diff --git a/effect_mono_stereo.cpp b/effect_mono_stereo.cpp index efd3ae9..54f6ef5 100644 --- a/effect_mono_stereo.cpp +++ b/effect_mono_stereo.cpp @@ -30,6 +30,33 @@ // Written by Holger Wirtz // 20191122 - initial version +static const audio_block_t zeroblock = { + 0, 0, 0, { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#if AUDIO_BLOCK_SAMPLES > 16 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#endif +#if AUDIO_BLOCK_SAMPLES > 32 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#endif +#if AUDIO_BLOCK_SAMPLES > 48 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#endif +#if AUDIO_BLOCK_SAMPLES > 64 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#endif +#if AUDIO_BLOCK_SAMPLES > 80 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#endif +#if AUDIO_BLOCK_SAMPLES > 96 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#endif +#if AUDIO_BLOCK_SAMPLES > 112 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#endif + } +}; + #if !defined(_MAPFLOAT) #define _MAPFLOAT inline float mapfloat(float val, float in_min, float in_max, float out_min, float out_max) @@ -50,7 +77,7 @@ void AudioEffectMonoStereo::update(void) in = receiveReadOnly(0); if (!in) - return; + in = (audio_block_t*)&zeroblock; out[0] = allocate(); out[1] = allocate(); @@ -67,20 +94,20 @@ void AudioEffectMonoStereo::update(void) *out_p[0]++ = int16_t(in_f[n] * _pseudo_log * fsin * SHRT_MAX); *out_p[1]++ = int16_t(in_f[n] * _pseudo_log * fcos * SHRT_MAX); } + } - if (in) - { - release(in); - } - if (out[0]) - { - transmit(out[0], 0); - release(out[0]); - } - if (out[1]) - { - transmit(out[1], 1); - release(out[1]); - } + if (in != (audio_block_t*)&zeroblock) + { + release(in); + } + if (out[0]) + { + transmit(out[0], 0); + release(out[0]); + } + if (out[1]) + { + transmit(out[1], 1); + release(out[1]); } }