From 09037e4c735bbb01d7ebf8121933da67bf627d88 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Sun, 21 Apr 2019 18:21:56 +0200 Subject: [PATCH] Fixes for voice auto-shutdown. --- MicroDexed.ino | 14 ++++---------- dexed.cpp | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 49a284e..9ef338f 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -124,7 +124,7 @@ uint8_t effect_delay_volume = 0; bool effect_delay_sync = 0; elapsedMicros fill_audio_buffer; elapsedMillis control_rate; -uint8_t shutdown_voices = 0; +uint8_t active_voices = 0; #ifdef SHOW_CPU_LOAD_MSEC elapsedMillis cpu_mem_millis; @@ -340,16 +340,8 @@ void loop() // Shutdown unused voices if (control_rate > CONTROL_RATE_MS) { - uint8_t tmp = shutdown_voices; control_rate = 0; - dexed->getNumNotesPlaying(); - - if (tmp != shutdown_voices) - { - Serial.print(F("Active voices [")); - Serial.print(shutdown_voices); - Serial.println(F("]")); - } + active_voices = dexed->getNumNotesPlaying(); } #ifdef I2C_DISPLAY @@ -954,6 +946,8 @@ void show_cpu_and_mem_usage(void) Serial.print(peak, DEC); Serial.print(F(" BLOCKSIZE: ")); Serial.print(AUDIO_BLOCK_SAMPLES, DEC); + Serial.print(F(" ACTIVE_VOICES: ")); + Serial.print(active_voices, DEC); Serial.println(); AudioProcessorUsageMaxReset(); AudioMemoryUsageMaxReset(); diff --git a/dexed.cpp b/dexed.cpp index 1e09062..04965a2 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -395,7 +395,7 @@ uint8_t Dexed::getNumNotesPlaying(void) { uint8_t op_carrier = controllers.core->get_carrier_operators(data[134]); // look for carriers uint8_t i; - uint8_t count_playing_voices=0; + uint8_t count_playing_voices = 0; for (i = 0; i < max_notes; i++) { @@ -405,19 +405,18 @@ uint8_t Dexed::getNumNotesPlaying(void) uint8_t op_carrier_num = 0; memset(&voiceStatus, 0, sizeof(VoiceStatus)); - voices[i].dx7_note->peekVoiceStatus(voiceStatus); for (uint8_t op = 0; op < 6; op++) { - if ((op_carrier & (1 >> op)) == 1) + if ((op_carrier & (1 << op))) { + // this voice is a carrier! + op_carrier_num++; + if (voiceStatus.amp[op] <= 1069 && voiceStatus.ampStep[op] == 4) { - // this voice is a carrier! - op_carrier_num++; - - if (voiceStatus.amp[op] <= 1069 && voiceStatus.ampStep[op] == 4) // this voice produces no audio output - op_amp++; + // this voice produces no audio output + op_amp++; } } } @@ -428,14 +427,16 @@ uint8_t Dexed::getNumNotesPlaying(void) voices[i].live = false; voices[i].sustained = false; voices[i].keydown = false; - Serial.print(F("Voice shutdown: ")); +#ifdef DEBUG + Serial.print(F("Shutdown voice: ")); Serial.println(i, DEC); +#endif } else count_playing_voices++; } } - return(count_playing_voices); + return (count_playing_voices); } bool Dexed::loadSysexVoice(uint8_t* new_data)