Adding function for checking, if sound is produced. If not, shut down the voice.

pull/4/head
Holger Wirtz 6 years ago
parent 587b954ac9
commit 1ac38718b7
  1. 14
      MicroDexed.ino
  2. 3
      config.h
  3. 47
      dexed.cpp
  4. 2
      dexed.h

@ -123,6 +123,7 @@ uint8_t effect_delay_feedback = 0;
uint8_t effect_delay_volume = 0; uint8_t effect_delay_volume = 0;
bool effect_delay_sync = 0; bool effect_delay_sync = 0;
elapsedMicros fill_audio_buffer; elapsedMicros fill_audio_buffer;
elapsedMillis control_rate;
#ifdef SHOW_CPU_LOAD_MSEC #ifdef SHOW_CPU_LOAD_MSEC
elapsedMillis cpu_mem_millis; elapsedMillis cpu_mem_millis;
@ -335,6 +336,13 @@ void loop()
// MIDI input handling // MIDI input handling
check_midi_devices(); check_midi_devices();
// Shutdown unused voices
if (control_rate > CONTROL_RATE_MS)
{
control_rate = 0;
uint8_t shutdown_voices = dexed->getNumNotesPlaying();
}
#ifdef I2C_DISPLAY #ifdef I2C_DISPLAY
// UI // UI
if (master_timer >= TIMER_UI_HANDLING_MS) if (master_timer >= TIMER_UI_HANDLING_MS)
@ -355,7 +363,7 @@ void loop()
} }
/****************************************************************************** /******************************************************************************
* MIDI MESSAGE HANDLER MIDI MESSAGE HANDLER
******************************************************************************/ ******************************************************************************/
void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity) void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity)
{ {
@ -654,9 +662,9 @@ void handleSystemReset(void)
} }
/****************************************************************************** /******************************************************************************
* END OF MIDI MESSAGE HANDLER END OF MIDI MESSAGE HANDLER
******************************************************************************/ ******************************************************************************/
bool checkMidiChannel(byte inChannel) bool checkMidiChannel(byte inChannel)
{ {
// check for MIDI channel // check for MIDI channel

@ -60,7 +60,8 @@
//* DEXED AND EFECTS SETTINGS //* DEXED AND EFECTS SETTINGS
//************************************************************************************************* //*************************************************************************************************
#define DEXED_ENGINE DEXED_ENGINE_MODERN // DEXED_ENGINE_MARKI // DEXED_ENGINE_OPL #define DEXED_ENGINE DEXED_ENGINE_MODERN // DEXED_ENGINE_MARKI // DEXED_ENGINE_OPL
#define CONTROL_RATE_MS 200
// EFFECTS // EFFECTS
#define FILTER_MAX_FREQ 10000 #define FILTER_MAX_FREQ 10000

@ -63,7 +63,7 @@ Dexed::Dexed(int rate)
voices[i].live = false; voices[i].live = false;
} }
max_notes = 16; max_notes = MAX_NOTES;
currentNote = 0; currentNote = 0;
resetControllers(); resetControllers();
controllers.masterTune = 0; controllers.masterTune = 0;
@ -391,6 +391,51 @@ uint8_t Dexed::getMaxNotes(void)
return max_notes; return max_notes;
} }
uint8_t Dexed::getNumNotesPlaying(void)
{
uint8_t op_carrier = controllers.core->get_carrier_operators(data[134]); // look for carriers
uint8_t i;
for (i = 0; i < max_notes; i++)
{
if (voices[i].live == true)
{
uint8_t op_amp = 0;
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++)
{
uint8_t op_bit = static_cast<uint8_t>(pow(2, op));
if ((op_carrier & op_bit) > 0)
{
{
// 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++;
}
}
if (op_amp == op_carrier_num)
{
// all carrier-operators are silent -> disable the voice
voices[i].live = false;
voices[i].sustained = false;
voices[i].keydown = false;
Serial.print("Voice shutdown [");
Serial.print(i,DEC);
Serial.println(F("]"));
}
}
}
}
}
bool Dexed::loadSysexVoice(uint8_t* new_data) bool Dexed::loadSysexVoice(uint8_t* new_data)
{ {
uint8_t* p_data = data; uint8_t* p_data = data;

@ -160,6 +160,7 @@ class Dexed
void keydown(uint8_t pitch, uint8_t velo); void keydown(uint8_t pitch, uint8_t velo);
void setSustain(bool sustain); void setSustain(bool sustain);
bool getSustain(void); bool getSustain(void);
uint8_t getNumNotesPlaying(void);
ProcessorVoice voices[MAX_NOTES]; ProcessorVoice voices[MAX_NOTES];
Controllers controllers; Controllers controllers;
@ -190,6 +191,7 @@ class Dexed
bool monoMode; bool monoMode;
bool refreshVoice; bool refreshVoice;
uint8_t engineType; uint8_t engineType;
VoiceStatus voiceStatus;
Lfo lfo; Lfo lfo;
FmCore* engineMsfa; FmCore* engineMsfa;
EngineMkI* engineMkI; EngineMkI* engineMkI;

Loading…
Cancel
Save