From cc6c78896e82c84e28c7d337a007cb9080fefce0 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Fri, 22 May 2020 14:46:24 +0200 Subject: [PATCH] Fixes for voice loudness. --- MicroDexed.ino | 93 +++++++++++++++++++++++++----------------- config.h | 7 ++-- effect_mono_stereo.cpp | 9 ++-- 3 files changed, 64 insertions(+), 45 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 65fffc6..2663c95 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -136,18 +136,18 @@ AudioConnection patchCord13(stereo2mono, 1, dacOut, 1); // // Dynamic patching of MicroDexed objects // -uint8_t nDynamic = 0; +uint16_t nDynamic = 0; #if defined(USE_FX) && MOD_FILTER_OUTPUT != MOD_NO_FILTER_OUTPUT -AudioConnection * dynamicConnections[NUM_DEXED * 17]; +AudioConnection * dynamicConnections[NUM_DEXED * 18]; #elif defined(USE_FX) && MOD_FILTER_OUTPUT == MOD_NO_FILTER_OUTPUT -AudioConnection * dynamicConnections[NUM_DEXED * 16]; +AudioConnection * dynamicConnections[NUM_DEXED * 17]; #else -AudioConnection * dynamicConnections[NUM_DEXED * 5]; +AudioConnection * dynamicConnections[NUM_DEXED * 6]; #endif void create_audio_engine_chain(uint8_t instance_id) { MicroDexed[instance_id] = new AudioSourceMicroDexed(SAMPLE_RATE); - dexed_dynamic[instance_id] = new AudioEffectDynamics; + dexed_dynamic[instance_id] = new AudioEffectDynamics(); dexed_level[instance_id] = new AudioAmplifier(); mono2stereo[instance_id] = new AudioEffectMonoStereo(); #if defined(USE_FX) @@ -183,13 +183,11 @@ void create_audio_engine_chain(uint8_t instance_id) dynamicConnections[nDynamic++] = new AudioConnection(*delay_mixer[instance_id], 0, *mono2stereo[instance_id], 0); dynamicConnections[nDynamic++] = new AudioConnection(*mono2stereo[instance_id], 0, reverb_mixer_r, instance_id); dynamicConnections[nDynamic++] = new AudioConnection(*mono2stereo[instance_id], 1, reverb_mixer_l, instance_id); - 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); #else dynamicConnections[nDynamic++] = new AudioConnection(*dexed_level[instance_id], 0, *mono2stereo[instance_id], 0); +#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); -#endif } uint8_t sd_card = 0; @@ -286,28 +284,6 @@ void setup() setup_midi_devices(); - for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) - { - if (instance_id < MAX_DEXED) - { -#ifdef DEBUG - Serial.print(F("Creating MicroDexed instance ")); - Serial.println(instance_id, DEC); -#endif - create_audio_engine_chain(instance_id); - } - else - { -#ifdef DEBUG - Serial.print(F("Ignoring instance ")); - Serial.print(instance_id, DEC); - Serial.print(F(" (maximum allowed: ")); - Serial.print(MAX_DEXED, DEC); - Serial.println(F(")")); -#endif - } - } - #if defined(TEENSY_AUDIO_BOARD) sgtl5000_1.enable(); sgtl5000_1.lineOutLevel(SGTL5000_LINEOUT_LEVEL); @@ -370,6 +346,16 @@ void setup() #endif #endif + // create dynamic Dexed instances + for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) + { +#ifdef DEBUG + Serial.print(F("Creating MicroDexed instance ")); + Serial.println(instance_id, DEC); +#endif + create_audio_engine_chain(instance_id); + } + #if defined(USE_FX) // Init effects for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) @@ -391,7 +377,7 @@ void setup() #endif #endif -#if defined(REVERB_ANTIALIAS_FRQ) +#if defined(USE_FX) && defined(REVERB_ANTIALIAS_FRQ) freeverb_antialias_r.setLowpass(0, REVERB_ANTIALIAS_FRQ, 0.54); freeverb_antialias_r.setLowpass(1, REVERB_ANTIALIAS_FRQ, 1.3); freeverb_antialias_r.setLowpass(2, REVERB_ANTIALIAS_FRQ, 0.54); @@ -451,8 +437,6 @@ void setup() Serial.println(F("]")); Serial.print(F("Polyphony: ")); Serial.println(configuration.dexed[instance_id].polyphony, DEC); - - dexed_dynamic[instance_id]->limit(); } Serial.print(F("AUDIO_BLOCK_SAMPLES=")); @@ -466,6 +450,32 @@ void setup() show_cpu_and_mem_usage(); #endif + for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) + { + MicroDexed[instance_id]->fx.Gain = 1.0; + + // init dynamics for dexed + dexed_dynamic[instance_id]->limit(); + //dexed_dynamic[instance_id]->autoMakeupGain(); + //dexed_dynamic[instance_id]->compression(); + } + + // init master_mixer +#if NUM_DEXED > 1 + for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) + { + //master_mixer_r.gain(instance_id, pseudo_log_curve(0.5)); + //master_mixer_l.gain(instance_id, pseudo_log_curve(0.5)); + master_mixer_r.gain(instance_id, 1.0); + master_mixer_l.gain(instance_id, 1.0); + } +#else + master_mixer_r.gain(0, 1.0); + master_mixer_l.gain(0, 1.0); +#endif + master_mixer_r.gain(3, 0.0); + master_mixer_l.gain(3, 0.0); + AudioInterrupts(); #ifdef DEBUG @@ -699,7 +709,9 @@ void handleControlChange(byte inChannel, byte inCtrl, byte inValue) MicroDexed[instance_id]->fx.Gain = mapfloat(configuration.dexed[instance_id].sound_intensity, SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX); #else*/ - dexed_level[instance_id]->gain(pseudo_log_curve(mapfloat(map(inValue, 0, 0x7f, 0, configuration.dexed[instance_id].sound_intensity), SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX))); + // dexed_level[instance_id]->gain(pseudo_log_curve(mapfloat(map(inValue, 0, 0x7f, 0, configuration.dexed[instance_id].sound_intensity), SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX))); // That's not right... have to fix this! + dexed_level[instance_id]->gain(mapfloat(map(inValue, 0, 0x7f, 0, configuration.dexed[instance_id].sound_intensity), SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX)); + //#endif if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_sound_intensity)) { @@ -1762,8 +1774,7 @@ void set_fx_params(void) reverb_mixer_l.gain(instance_id, pseudo_log_curve(mapfloat(configuration.fx.reverb_send[instance_id], REVERB_SEND_MIN, REVERB_SEND_MAX, 0.0, 1.0))); // DEXED FILTER - //MicroDexed[instance_id]->fx.Gain = mapfloat(configuration.dexed[instance_id].sound_intensity, SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX); - MicroDexed[instance_id]->fx.Gain = 1.0; + //MicroDexed[instance_id]->fx.Gain = 1.0; MicroDexed[instance_id]->fx.Reso = mapfloat(configuration.dexed[instance_id].filter_resonance, FILTER_RESONANCE_MIN, FILTER_RESONANCE_MAX, 1.0, 0.0); MicroDexed[instance_id]->fx.Cutoff = mapfloat(configuration.dexed[instance_id].filter_cutoff, FILTER_CUTOFF_MIN, FILTER_CUTOFF_MAX, 1.0, 0.0); MicroDexed[instance_id]->doRefreshVoice(); @@ -1824,7 +1835,6 @@ void _softRestart(void) float pseudo_log_curve(float value) { const float _pseudo_log = 1048575 / (float)(1 << 20); - /* #ifdef DEBUG Serial.print(F("value in: ")); @@ -1834,7 +1844,14 @@ float pseudo_log_curve(float value) #endif */ - return (mapfloat(_pseudo_log * arm_sin_f32(value), 0.0, _pseudo_log * arm_sin_f32(1.0), 0.0, 1.0)); + // return (mapfloat(_pseudo_log * arm_sin_f32(value), 0.0, _pseudo_log * arm_sin_f32(1.0), 0.0, 1.0)); + + float g = mapfloat(_pseudo_log * arm_sin_f32(value), 0.0, _pseudo_log * arm_sin_f32(1.0), 0.0, 1.0); + + if (g == 0.0) + return (0.001); + else + return (g); } uint32_t crc32(byte * calc_start, uint16_t calc_bytes) // base code from https://www.arduino.cc/en/Tutorial/EEPROMCrc diff --git a/config.h b/config.h index ec7a5e3..47d779e 100644 --- a/config.h +++ b/config.h @@ -47,7 +47,7 @@ // amidi -p hw:2,0,0 -d -r /tmp/bkup1.syx // -#define VERSION "0.9.9h" +#define VERSION "0.9.9i" //************************************************************************************************* //* DEVICE SETTINGS @@ -94,6 +94,8 @@ //************************************************************************************************* #define DEXED_ENGINE DEXED_ENGINE_MODERN // DEXED_ENGINE_MARKI // DEXED_ENGINE_OPL +// Number of Dexed instances +#define NUM_DEXED 1 // 1 or 2 - nothing else! // FX-CHAIN ENABLE/DISABLE #define USE_FX 1 // CHORUS parameters @@ -104,7 +106,7 @@ // REVERB parameters #define REVERB_ANTIALIAS_FRQ 7500 // SGTL5000 -#define SGTL5000_AUDIO_ENHANCE 1 +//#define SGTL5000_AUDIO_ENHANCE 1 //************************************************************************************************* //* AUDIO SOFTWARE SETTINGS @@ -248,7 +250,6 @@ //************************************************************************************************* //* DO NO CHANGE ANYTHING BEYOND IF YOU DON'T KNOW WHAT YOU ARE DOING !!! //************************************************************************************************* -#define NUM_DEXED 1 // 1 or 2 - nothing else! #define MAX_DEXED 2 // No! - even don't think about increasing this number! IT WILL PRODUCE MASSIVE PROBLEMS! #define CONTROL_RATE_MS 50 diff --git a/effect_mono_stereo.cpp b/effect_mono_stereo.cpp index af410d9..bfe2c10 100644 --- a/effect_mono_stereo.cpp +++ b/effect_mono_stereo.cpp @@ -57,12 +57,13 @@ void AudioEffectMonoStereo::update(void) { arm_q15_to_float(in->data, in_f, AUDIO_BLOCK_SAMPLES); - float f = pan * PI / 2.0; - int16_t* out_p[2] = {out[0]->data, out[1]->data}; + float fsin = arm_sin_f32(pan * PI / 2.0); + float fcos = arm_cos_f32(pan * PI / 2.0); + int16_t* out_p[2] = {&out[0]->data[0], &out[1]->data[0]}; for (uint8_t n = 0; n < AUDIO_BLOCK_SAMPLES; n++) { - *out_p[0]++ = int16_t(in_f[n] * _pseudo_log * arm_sin_f32(f) * SHRT_MAX); - *out_p[1]++ = int16_t(in_f[n] * _pseudo_log * arm_cos_f32(f) * SHRT_MAX); + *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)