From de2a893fb715a2c14560ff79b41c1280b36a73cd Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Sat, 7 Jan 2023 18:11:02 +0100 Subject: [PATCH] Several bug fixes: - drums volume - ep tune - drums exclude for HH and HC - filter Dexed enabled again. --- MicroDexed.ino | 40 ++++++++++--------- UI.hpp | 5 ++- addon/SD/PERFORMANCE/0/epiano.json | 2 +- dexed_sd.cpp | 2 +- third-party/Synth_Dexed/src/PluginFx.cpp | 2 - third-party/Synth_Dexed/src/compressor.h | 18 +++------ third-party/Synth_Dexed/src/dexed.cpp | 8 ++-- third-party/Synth_Dexed/tools/gen_includes.sh | 26 ++++++++++++ third-party/Synth_Dexed/tools/includes.txt | 17 ++++++++ 9 files changed, 79 insertions(+), 41 deletions(-) create mode 100755 third-party/Synth_Dexed/tools/gen_includes.sh create mode 100644 third-party/Synth_Dexed/tools/includes.txt diff --git a/MicroDexed.ino b/MicroDexed.ino index 9978924..6f8502f 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -2287,9 +2287,9 @@ void set_epiano_params(void) { ep.setStereo(mapfloat(configuration.epiano.stereo, EP_STEREO_MIN, EP_STEREO_MAX, 0.0, 1.0)); ep.setPolyphony(configuration.epiano.polyphony); ep.setTune(mapfloat(configuration.epiano.tune, EP_TUNE_MIN, EP_TUNE_MAX, 0.0, 1.0)); - ep.setDetune(mapfloat(configuration.epiano.detune, EP_DETUNE_MIN, EP_DETUNE_MAX, 0, 1.0)); - ep.setOverdrive(mapfloat(configuration.epiano.overdrive, EP_OVERDRIVE_MIN, EP_OVERDRIVE_MAX, 0, 1.0)); - ep.setVolume(mapfloat(configuration.epiano.sound_intensity, EP_SOUND_INTENSITY_MIN, EP_SOUND_INTENSITY_MAX, 0, 1.0)); + ep.setDetune(mapfloat(configuration.epiano.detune, EP_DETUNE_MIN, EP_DETUNE_MAX, 0.0, 1.0)); + ep.setOverdrive(mapfloat(configuration.epiano.overdrive, EP_OVERDRIVE_MIN, EP_OVERDRIVE_MAX, 0.0, 1.0)); + ep.setVolume(mapfloat(configuration.epiano.sound_intensity, EP_SOUND_INTENSITY_MIN, EP_SOUND_INTENSITY_MAX, 0.0, 1.0)); #ifdef DEBUG Serial.println(F("done.")); #endif @@ -2324,29 +2324,31 @@ void _softRestart(void) { #if NUM_DRUMS > 0 uint8_t drum_get_slot(uint8_t dt) { + // Cleanup not playing drums for (uint8_t i = 0; i < NUM_DRUMS; i++) { - if (!Drum[i]->isPlaying()) { + if ((dt == DRUM_HIHAT || dt == DRUM_HANDCLAP) && drum_type[i] == dt) { + Drum[i]->stop(); drum_type[i] = DRUM_NONE; Drum[i]->enableInterpolation(false); Drum[i]->setPlaybackRate(1.0); - } else { - if (dt == DRUM_HIHAT || dt == DRUM_HANDCLAP) { - Drum[i]->stop(); - drum_type[i] = DRUM_NONE; - Drum[i]->enableInterpolation(false); - Drum[i]->setPlaybackRate(1.0); -#ifdef DEBUG - Serial.print(F("Stopping Drum ")); - Serial.print(i); - Serial.print(F(" type ")); - Serial.println(dt); -#endif - return (i); - } +#ifdef DEBUG + Serial.print(F("Stopping Drum ")); + Serial.print(i); + Serial.print(F(" type ")); + Serial.println(dt); +#endif + drum_counter = i + 1; + return (i); + } else if (!Drum[i]->isPlaying()) { + drum_type[i] = DRUM_NONE; + Drum[i]->enableInterpolation(false); + Drum[i]->setPlaybackRate(1.0); + drum_counter=i+1; + return (i); } } #ifdef DEBUG - Serial.print(F("Using next free Drum slot ")); + Serial.print(F("Using next drum slot ")); Serial.println(drum_counter % NUM_DRUMS); #endif drum_type[drum_counter % NUM_DRUMS] = dt; diff --git a/UI.hpp b/UI.hpp index f04abf5..f50746c 100644 --- a/UI.hpp +++ b/UI.hpp @@ -4135,8 +4135,9 @@ void UI_func_drums_main_volume(uint8_t param) { configuration.drums.main_vol = constrain(configuration.drums.main_vol - ENCODER[ENC_L].speed(), DRUMS_MAIN_VOL_MIN, DRUMS_MAIN_VOL_MAX); } display_bar_int("DRM Main Vol", configuration.drums.main_vol, 1.0, DRUMS_MAIN_VOL_MIN, DRUMS_MAIN_VOL_MAX, 3, false, false, false); - master_mixer_r.gain(MASTER_MIX_CH_DRUMS, configuration.drums.main_vol); - master_mixer_l.gain(MASTER_MIX_CH_DRUMS, configuration.drums.main_vol); + float tmp_vol=configuration.drums.main_vol/100.0; + master_mixer_r.gain(MASTER_MIX_CH_DRUMS, tmp_vol); + master_mixer_l.gain(MASTER_MIX_CH_DRUMS, tmp_vol); } } #endif diff --git a/addon/SD/PERFORMANCE/0/epiano.json b/addon/SD/PERFORMANCE/0/epiano.json index ed4bd83..e87ba35 100644 --- a/addon/SD/PERFORMANCE/0/epiano.json +++ b/addon/SD/PERFORMANCE/0/epiano.json @@ -8,7 +8,7 @@ "velocity_sense": 0, "stereo": 50, "polyphony": 16, - "tune": 50, + "tune": 100, "detune": 15, "overdrive": 0, "lowest_note": 21, diff --git a/dexed_sd.cpp b/dexed_sd.cpp index e8dea36..f3c601a 100644 --- a/dexed_sd.cpp +++ b/dexed_sd.cpp @@ -944,7 +944,7 @@ bool load_sd_epiano_json(uint8_t number) { configuration.epiano.midi_channel = data_json["midi_channel"]; check_configuration_epiano(); - set_epiano_params(); + set_epiano_params(); return (true); } diff --git a/third-party/Synth_Dexed/src/PluginFx.cpp b/third-party/Synth_Dexed/src/PluginFx.cpp index 4e40731..e4d6fb9 100644 --- a/third-party/Synth_Dexed/src/PluginFx.cpp +++ b/third-party/Synth_Dexed/src/PluginFx.cpp @@ -131,7 +131,6 @@ void PluginFx::process(float *work, int sampleSize) { work[i] *= Gain; } -#ifdef USE_FX // don't apply the LPF if the cutoff is to maximum if ( Cutoff == 1.0 ) return; @@ -193,7 +192,6 @@ void PluginFx::process(float *work, int sampleSize) { //half volume comp work[i] = mc * (1 + R24 * 0.45); } -#endif } /* diff --git a/third-party/Synth_Dexed/src/compressor.h b/third-party/Synth_Dexed/src/compressor.h index 396d416..22331eb 100644 --- a/third-party/Synth_Dexed/src/compressor.h +++ b/third-party/Synth_Dexed/src/compressor.h @@ -87,8 +87,7 @@ class Compressor arm_scale_f32(audio_block, pre_gain, audio_block, len); //use ARM DSP for speed! //calculate the level of the audio (ie, calculate a smoothed version of the signal power) - //float32_t* audio_level_dB_block = (float32_t*)malloc(sizeof(float32_t)*len); - float32_t* audio_level_dB_block = new float32_t[len]; + float32_t* audio_level_dB_block = (float32_t*)malloc(sizeof(float32_t)*len); if(!audio_level_dB_block) { printf("Cannot allocate memory for \"audio_level_dB_block\" - stopping\n"); @@ -101,8 +100,7 @@ class Compressor calcAudioLevel_dB(audio_block, audio_level_dB_block, len); //returns through audio_level_dB_block //compute the desired gain based on the observed audio level - //float32_t* gain_block=(float32_t*)malloc(sizeof(float32_t)*len); - float32_t* gain_block=new float32_t[len]; + float32_t* gain_block=(float32_t*)malloc(sizeof(float32_t)*len); if(!gain_block) { printf("Cannot allocate memory for \"gain_block\" - stopping\n"); @@ -132,8 +130,7 @@ class Compressor void calcAudioLevel_dB(float32_t *wav_block, float32_t *level_dB_block, uint16_t len) { // calculate the instantaneous signal power (square the signal) - //float32_t* wav_pow_block=(float32_t*)malloc(sizeof(float32_t)*len); - float32_t* wav_pow_block=new float32_t[len]; + float32_t* wav_pow_block=(float32_t*)malloc(sizeof(float32_t)*len); if(!wav_pow_block) { printf("Cannot allocate memory for \"wav_pow_block\" - stopping\n"); @@ -175,8 +172,7 @@ class Compressor void calcGain(float32_t *audio_level_dB_block, float32_t *gain_block,uint16_t len) { //first, calculate the instantaneous target gain based on the compression ratio - //float32_t* inst_targ_gain_dB_block=(float32_t*)malloc(sizeof(float32_t)*len); - float32_t* inst_targ_gain_dB_block=new float32_t[len]; + float32_t* inst_targ_gain_dB_block=(float32_t*)malloc(sizeof(float32_t)*len); if(!inst_targ_gain_dB_block) { printf("Cannot allocate memory for \"inst_targ_gain_dB_block\" - stopping\n"); @@ -187,8 +183,7 @@ class Compressor calcInstantaneousTargetGain(audio_level_dB_block, inst_targ_gain_dB_block,len); //second, smooth in time (attack and release) by stepping through each sample - //float32_t *gain_dB_block = (float32_t*)malloc(sizeof(float32_t)*len); - float32_t *gain_dB_block = new float32_t[len]; + float32_t *gain_dB_block = (float32_t*)malloc(sizeof(float32_t)*len); if(!gain_dB_block) { printf("Cannot allocate memory for \"gain_dB_block\" - stopping\n"); @@ -217,8 +212,7 @@ class Compressor void calcInstantaneousTargetGain(float32_t *audio_level_dB_block, float32_t *inst_targ_gain_dB_block, uint16_t len) { // how much are we above the compression threshold? - //float32_t* above_thresh_dB_block=(float32_t*)malloc(sizeof(float32_t)*len); - float32_t* above_thresh_dB_block=new float32_t[len]; + float32_t* above_thresh_dB_block=(float32_t*)malloc(sizeof(float32_t)*len); if(!above_thresh_dB_block) { printf("Cannot allocate memory for \"above_thresh_dB_block\" - stopping\n"); diff --git a/third-party/Synth_Dexed/src/dexed.cpp b/third-party/Synth_Dexed/src/dexed.cpp index 17a755d..f611dcd 100644 --- a/third-party/Synth_Dexed/src/dexed.cpp +++ b/third-party/Synth_Dexed/src/dexed.cpp @@ -573,7 +573,7 @@ bool Dexed::decodeVoice(uint8_t* new_data, uint8_t* encoded_data) panic(); doRefreshVoice(); - strlcpy(dexed_voice_name, (char *)&encoded_data[118], sizeof(dexed_voice_name) - 1); + strncpy(dexed_voice_name, (char *)&encoded_data[118], sizeof(dexed_voice_name) - 1); dexed_voice_name[10] = '\0'; #if defined(MICRODEXED_VERSION) && defined(DEBUG) Serial.print(F("Voice [")); @@ -663,7 +663,7 @@ void Dexed::loadVoiceParameters(uint8_t* new_data) memcpy(&data, new_data, 155); doRefreshVoice(); #if defined(MICRODEXED_VERSION) && defined(DEBUG) - strlcpy(dexed_voice_name, (char *)&new_data[145], sizeof(dexed_voice_name) - 1); + strncpy(dexed_voice_name, (char *)&new_data[145], sizeof(dexed_voice_name) - 1); dexed_voice_name[10] = '\0'; Serial.print(F("Voice [")); @@ -1656,12 +1656,12 @@ uint8_t Dexed::getTranspose(void) void Dexed::setName(char* name) { - strlcpy(name, (char*)&data[DEXED_VOICE_OFFSET + DEXED_NAME], 10); + strncpy(name, (char*)&data[DEXED_VOICE_OFFSET + DEXED_NAME], 10); } void Dexed::getName(char* buffer) { - strlcpy((char*)&data[DEXED_VOICE_OFFSET + DEXED_NAME], buffer, 10); + strncpy((char*)&data[DEXED_VOICE_OFFSET + DEXED_NAME], buffer, 10); buffer[10] = '\0'; } diff --git a/third-party/Synth_Dexed/tools/gen_includes.sh b/third-party/Synth_Dexed/tools/gen_includes.sh new file mode 100755 index 0000000..07a1efb --- /dev/null +++ b/third-party/Synth_Dexed/tools/gen_includes.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +echo "#include " > synth_dexed.h +echo "#include " >> synth_dexed.h +echo "#include \"config.h\"" >> synth_dexed.h +for i in `cat includes.txt` +do + echo "/*****************************************************" >> synth_dexed.h + echo " * CODE; ${i}" >> synth_dexed.h + echo " *****************************************************/" >> synth_dexed.h + + cat $i >> synth_dexed.h + echo "" >> synth_dexed.h + echo "//=====================================================" >> synth_dexed.h +done + +echo "#include \"synth_dexed.h\"" > synth_dexed.cpp +for i in `ls orig_code/*.cpp` +do + echo "/*****************************************************" >> synth_dexed.cpp + echo " * CODE; ${i}" >> synth_dexed.cpp + echo " *****************************************************/" >> synth_dexed.cpp + cat $i >> synth_dexed.cpp + echo "" >> synth_dexed.cpp + echo "//=====================================================" >> synth_dexed.cpp +done diff --git a/third-party/Synth_Dexed/tools/includes.txt b/third-party/Synth_Dexed/tools/includes.txt new file mode 100644 index 0000000..2835504 --- /dev/null +++ b/third-party/Synth_Dexed/tools/includes.txt @@ -0,0 +1,17 @@ +orig_code/synth.h +orig_code/aligned_buf.h +orig_code/sin.h +orig_code/exp2.h +orig_code/fast_log.h +orig_code/freqlut.h +orig_code/lfo.h +orig_code/env.h +orig_code/pitchenv.h +orig_code/controllers.h +orig_code/PluginFx.h +orig_code/fm_op_kernel.h +orig_code/fm_core.h +orig_code/dx7note.h +orig_code/dexed.h +orig_code/porta.h +orig_code/source_microdexed.h