From 69ce71436e7a924b42b9c195971267143174719f Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Wed, 20 May 2020 12:48:22 +0200 Subject: [PATCH] Dropped old code pieces and small fixes. --- MicroDexed.ino | 89 ++++----------------------------------------- config.h | 22 +++++------ dexed.cpp | 73 ++++++++++++++++--------------------- dexed.h | 2 - dexed_sd.cpp | 9 +++++ source_microdexed.h | 8 ---- 6 files changed, 58 insertions(+), 145 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 4465dd8..eb5c38b 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -193,7 +193,6 @@ uint8_t midi_voices[NUM_DEXED]; elapsedMillis cpu_mem_millis; #endif uint32_t cpumax = 0; -elapsedMillis cpu_overload_throttle_timer; uint32_t peak_dexed = 0; float peak_dexed_value = 0.0; uint32_t peak_r = 0; @@ -208,12 +207,14 @@ char g_voice_name[NUM_DEXED][VOICE_NAME_LEN]; char g_bank_name[NUM_DEXED][BANK_NAME_LEN]; char receive_bank_filename[FILENAME_LEN]; uint8_t selected_instance_id = 0; +#ifdef TEENSY4 #if NUM_DEXED>1 int8_t midi_decay[NUM_DEXED] = { -1, -1}; #else int8_t midi_decay[NUM_DEXED] = { -1}; #endif elapsedMillis midi_decay_timer; +#endif #if defined(USE_FX) // Allocate the delay lines for chorus @@ -409,27 +410,6 @@ void setup() change_disp_sd(true); #endif - /* - for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) - { - // INIT PEAK MIXER - microdexed_peak_mixer.gain(instance_id, 1.0); - - // INIT DEXED VOLUME - dexed_level[instance_id]->gain(1.0); - - // INIT DEXED VOICE CONFIG - set_voiceconfig_params(instance_id); - - master_mixer_r.gain(instance_id, 1.0); - master_mixer_l.gain(instance_id, 1.0); - } - master_mixer_r.gain(3, pseudo_log_curve(configuration.fx.reverb_level / 100)); - master_mixer_l.gain(3, pseudo_log_curve(configuration.fx.reverb_level / 100)); - - set_sys_params(); - */ - // Initialize processor and memory measurements AudioProcessorUsageMaxReset(); AudioMemoryUsageMaxReset(); @@ -487,38 +467,12 @@ void loop() { control_rate = 0; - /* - // EEPROM update handling - if (autostore >= AUTOSTORE_MS && eeprom_update_flag == true) - { - // only store configuration data to EEPROM when AUTOSTORE_MS is reached and no voices are activated anymore - eeprom_update_sys(); - } - */ - // check for value changes, unused voices and CPU overload for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) { active_voices[instance_id] = MicroDexed[instance_id]->getNumNotesPlaying(); if (active_voices[instance_id] == 0) midi_voices[instance_id] = 0; - -#if defined(CPU_OVERLOAD_THROTTLE) - if (AudioProcessorUsageMax() > CPU_OVERLOAD_THROTTLE && cpu_overload_throttle_timer >= CPU_OVERLOAD_THROTTLE_TIMER) - { - cpu_overload_throttle_timer = 0; - AudioProcessorUsageMaxReset(); - MicroDexed[instance_id]->keyup(-1); // kills the oldest note and decreases max_notes -#ifdef DEBUG - Serial.print(F("!!!CPU overload!!! Automatic throttling polyphony down to ")); - Serial.print(MicroDexed[instance_id]->getMaxNotes(), DEC); - Serial.print(F(" for instance ")); - Serial.print(instance_id, DEC); - Serial.println(F(".")); -#endif - configuration.dexed[instance_id].polyphony = MicroDexed[instance_id]->getMaxNotes(); - } -#endif } if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_voice_select)) @@ -555,10 +509,12 @@ void loop() } #endif } +#ifdef TEENSY4 if (midi_decay_timer > 250) { midi_decay_timer = 0; } +#endif } } else @@ -600,11 +556,13 @@ void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity) MicroDexed[instance_id]->keydown(inNumber, uint8_t(float(configuration.dexed[instance_id].velocity_level / 127.0)*inVelocity + 0.5)); midi_voices[instance_id]++; +#ifdef TEENSY4 if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_voice_select)) { midi_decay_timer = 0; midi_decay[instance_id] = min(inVelocity / 5, 7); } +#endif #ifdef DEBUG char note_name[4]; getNoteName(note_name, inNumber); @@ -1437,37 +1395,6 @@ void initial_values_from_eeprom(bool init) for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) { set_voiceconfig_params(instance_id); - - /* - MicroDexed[instance_id]->setPBController(configuration.dexed[instance_id].pb_range, configuration.dexed[instance_id].pb_step); - MicroDexed[instance_id]->setMWController(configuration.dexed[instance_id].mw_range, configuration.dexed[instance_id].mw_assign, configuration.dexed[instance_id].mw_mode); - MicroDexed[instance_id]->setFCController(configuration.dexed[instance_id].fc_range, configuration.dexed[instance_id].fc_assign, configuration.dexed[instance_id].fc_mode); - MicroDexed[instance_id]->setBCController(configuration.dexed[instance_id].bc_range, configuration.dexed[instance_id].bc_assign, configuration.dexed[instance_id].bc_mode); - MicroDexed[instance_id]->setATController(configuration.dexed[instance_id].at_range, configuration.dexed[instance_id].at_assign, configuration.dexed[instance_id].at_mode); - MicroDexed[instance_id]->controllers.refresh(); - MicroDexed[instance_id]->setOPs(configuration.dexed[instance_id].op_enabled); - MicroDexed[instance_id]->doRefreshVoice(); - MicroDexed[instance_id]->setMaxNotes(configuration.dexed[instance_id].polyphony); - MicroDexed[instance_id]->setMonoMode(configuration.sys.mono); - */ - - /* - chorus_mixer[instance_id]->gain(1, 1.0 - mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 0.5)); - chorus_mixer[instance_id]->gain(1, mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 0.5)); - delay_mixer[instance_id]->gain(0, 1.0); - delay_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_level[instance_id], DELAY_LEVEL_MIN, DELAY_LEVEL_MAX, 0.0, 1.0))); - delay_fb_mixer[instance_id]->gain(0, 1.0); - delay_fb_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_feedback[instance_id], DELAY_FEEDBACK_MIN, DELAY_FEEDBACK_MAX, 0.0, 1.0))); - reverb_mixer_r.gain(instance_id, pseudo_log_curve(configuration.fx.reverb_send[instance_id] / 100.0)); - reverb_mixer_l.gain(instance_id, pseudo_log_curve(configuration.fx.reverb_send[instance_id] / 100.0)); - - // MicroDexed[instance_id]->fx.Gain = configuration.dexed[instance_id].sound_intensity / 100.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); - - dexed_level[instance_id]->gain(pseudo_log_curve(mapfloat(configuration.dexed[instance_id].sound_intensity, SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX))); - */ } set_fx_params(); set_sys_params(); @@ -1802,8 +1729,8 @@ void set_fx_params(void) delay_fx[instance_id]->delay(0, constrain(configuration.fx.delay_time[instance_id], DELAY_TIME_MIN, DELAY_TIME_MAX) * 10); // REVERB SEND - reverb_mixer_r.gain(instance_id, pseudo_log_curve(configuration.fx.reverb_send[instance_id] / 100.0)); - reverb_mixer_l.gain(instance_id, pseudo_log_curve(configuration.fx.reverb_send[instance_id] / 100.0)); + reverb_mixer_r.gain(instance_id, pseudo_log_curve(mapfloat(configuration.fx.reverb_send[instance_id], REVERB_SEND_MIN, REVERB_SEND_MAX, 0.0, 1.0))); + 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); diff --git a/config.h b/config.h index 101d209..3484a18 100644 --- a/config.h +++ b/config.h @@ -84,7 +84,7 @@ //************************************************************************************************* //* DEBUG OUTPUT SETTINGS //************************************************************************************************* -#define DEBUG 1 +//#define DEBUG 1 #define SERIAL_SPEED 230400 #define SHOW_XRUN 1 #define SHOW_CPU_LOAD_MSEC 5000 @@ -247,9 +247,7 @@ //************************************************************************************************* #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 CPU_OVERLOAD_THROTTLE 95.0 // Level (in percent) when throttling should start -#define CPU_OVERLOAD_THROTTLE_TIMER 100 // timer (in ms) when next throttling is possible -#define CONTROL_RATE_MS 100 +#define CONTROL_RATE_MS 50 #define EEPROM_MARKER 0x4242 @@ -404,9 +402,9 @@ #define TUNE_DEFAULT 100 #define SOUND_INTENSITY_MIN 0 -#define SOUND_INTENSITY_MAX 127 +#define SOUND_INTENSITY_MAX 200 #define SOUND_INTENSITY_DEFAULT 100 -#define SOUND_INTENSITY_AMP_MAX 1.27 +#define SOUND_INTENSITY_AMP_MAX 2.0 #define POLYPHONY_MIN 0 #define POLYPHONY_MAX MAX_NOTES @@ -518,15 +516,15 @@ #define PERFORMANCE_NUM_MIN 0 #define PERFORMANCE_NUM_MAX MAX_PERFORMANCE -#define PERFORMANCE_NUM_DEFAULT 0 +#define PERFORMANCE_NUM_DEFAULT -1 #define FX_NUM_MIN 0 #define FX_NUM_MAX MAX_FX -#define FX_NUM_DEFAULT 0 +#define FX_NUM_DEFAULT -1 #define VOICECONFIG_NUM_MIN 0 #define VOICECONFIG_NUM_MAX MAX_VOICECONFIG -#define VOICECONFIG_NUM_DEFAULT 0 +#define VOICECONFIG_NUM_DEFAULT -1 // typedef struct dexed_s { @@ -581,8 +579,8 @@ typedef struct fx_s { typedef struct performance_s { uint8_t bank[MAX_DEXED]; uint8_t voice[MAX_DEXED]; - uint8_t voiceconfig_number[MAX_DEXED]; - uint8_t fx_number; + int8_t voiceconfig_number[MAX_DEXED]; + int8_t fx_number; } performance_t; typedef struct sys_s { @@ -590,7 +588,7 @@ typedef struct sys_s { uint8_t vol; uint8_t mono; uint8_t soft_midi_thru; - uint8_t performance_number; + int8_t performance_number; } sys_t; typedef struct configuration_s { diff --git a/dexed.cpp b/dexed.cpp index a214982..792ff43 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -150,7 +150,7 @@ void Dexed::getSamples(uint16_t n_samples, int16_t* buffer) { //sumbuf[i + j] += static_cast(signed_saturate_rshift(audiobuf.get()[j] >> 4, 24, 9)) / 0x8000; //sumbuf[i + j] += static_cast(signed_saturate_rshift(audiobuf.get()[j] >> 5, 24, 9)) / 0x8000; - sumbuf[i + j] += static_cast(signed_saturate_rshift(audiobuf.get()[j], 32, 13)) / 0x8000; + sumbuf[i + j] += static_cast(signed_saturate_rshift(audiobuf.get()[j], 32, 14)) / 0x8000; //sumbuf[i + j] += static_cast(audiobuf.get()[j] / 0x8000); audiobuf.get()[j] = 0; } @@ -278,58 +278,47 @@ void Dexed::keydown(int16_t pitch, uint8_t velo) { } void Dexed::keyup(int16_t pitch) { - if (pitch < 0) // for disabling the oldest note when cpu overload is detected - { - voices[currentNote].keydown = false; - voices[currentNote].key_pressed_timer = 0; - - if (--max_notes == currentNote) - currentNote = 0; - } - else - { - uint8_t note; - - pitch += data[144] - TRANSPOSE_FIX; + uint8_t note; - for (note = 0; note < max_notes; note++) { - if ( voices[note].midi_note == pitch && voices[note].keydown ) { - voices[note].keydown = false; - voices[note].key_pressed_timer = 0; + pitch += data[144] - TRANSPOSE_FIX; - break; - } - } + for (note = 0; note < max_notes; note++) { + if ( voices[note].midi_note == pitch && voices[note].keydown ) { + voices[note].keydown = false; + voices[note].key_pressed_timer = 0; - // note not found ? - if ( note >= max_notes ) { - return; + break; } + } - if ( monoMode ) { - int16_t highNote = -1; - uint8_t target = 0; - for (int8_t i = 0; i < max_notes; i++) { - if ( voices[i].keydown && voices[i].midi_note > highNote ) { - target = i; - highNote = voices[i].midi_note; - } - } + // note not found ? + if ( note >= max_notes ) { + return; + } - if ( highNote != -1 && voices[note].live ) { - voices[note].live = false; - voices[note].key_pressed_timer = 0; - voices[target].live = true; - voices[target].dx7_note->transferState(*voices[note].dx7_note); + if ( monoMode ) { + int16_t highNote = -1; + uint8_t target = 0; + for (int8_t i = 0; i < max_notes; i++) { + if ( voices[i].keydown && voices[i].midi_note > highNote ) { + target = i; + highNote = voices[i].midi_note; } } - if ( sustain ) { - voices[note].sustained = true; - } else { - voices[note].dx7_note->keyup(); + if ( highNote != -1 && voices[note].live ) { + voices[note].live = false; + voices[note].key_pressed_timer = 0; + voices[target].live = true; + voices[target].dx7_note->transferState(*voices[note].dx7_note); } } + + if ( sustain ) { + voices[note].sustained = true; + } else { + voices[note].dx7_note->keyup(); + } } void Dexed::doRefreshVoice(void) diff --git a/dexed.h b/dexed.h index 7edef95..4bd4119 100644 --- a/dexed.h +++ b/dexed.h @@ -38,7 +38,6 @@ #include #include "config.h" -//extern uint32_t overload; extern bool load_sysex(uint8_t bank, uint8_t voice_number); extern AudioControlSGTL5000 sgtl5000_1; extern float vol; @@ -194,7 +193,6 @@ class Dexed 69, 68, 80, 56, 85, 76, 84, 00, 00, 00 // 10 * char for name ("DEFAULT ") }; // FM-Piano - uint32_t overload = 0; int lastKeyDown; protected: diff --git a/dexed_sd.cpp b/dexed_sd.cpp index ea14ead..9e39a06 100644 --- a/dexed_sd.cpp +++ b/dexed_sd.cpp @@ -346,6 +346,9 @@ bool save_sd_bank(const char* bank_filename, uint8_t* data) ******************************************************************************/ bool load_sd_voiceconfig(uint8_t vc, uint8_t instance_id) { + if (vc < 0) + return (false); + vc = constrain(vc, 0, MAX_VOICECONFIG); if (sd_card > 0) @@ -443,6 +446,9 @@ bool save_sd_voiceconfig(uint8_t vc, uint8_t instance_id) ******************************************************************************/ bool load_sd_fx(uint8_t fx) { + if (fx < 0) + return (false); + fx = constrain(fx, 0, MAX_FX); if (sd_card > 0) @@ -539,6 +545,9 @@ bool save_sd_fx(uint8_t fx) ******************************************************************************/ bool load_sd_performance(uint8_t p) { + if (p < 0) + return (false); + p = constrain(p, 0, MAX_PERFORMANCE); if (sd_card > 0) diff --git a/source_microdexed.h b/source_microdexed.h index 132e449..cf27991 100644 --- a/source_microdexed.h +++ b/source_microdexed.h @@ -37,14 +37,6 @@ class AudioSourceMicroDexed : public AudioStream, public Dexed { if (render_time > audio_block_time_us) // everything greater 2.9ms is a buffer underrun! xrun++; - /* if (render_time > audio_block_time_us - (audio_block_time_us / 10)) { - #ifdef DEBUG - Serial.println("At CPU Limit"); - #endif - uint8_t nnotes = getNumNotesPlaying(); - //setMaxNotes(nnotes); - max_notes = nnotes; - } */ if (render_time > render_time_max) render_time_max = render_time;