From c7626929a9e66575ea7c9f087d2b3476fadf295e Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Tue, 15 May 2018 14:49:23 +0200 Subject: [PATCH] Fixes. --- MicroDexed.ino | 64 ++++++++++++++++++-------------------------------- dexed.cpp | 11 ++------- dexed.h | 5 +--- 3 files changed, 26 insertions(+), 54 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 4731a1b..c9fd27f 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include "dexed.h" @@ -18,20 +17,11 @@ #define AUDIO_MEM 32 #define AUDIO_BUFFER_SIZE 128 #define SAMPLEAUDIO_BUFFER_SIZE 44100 -#define MIDI_QUEUE_LOCK_TIMEOUT_MS 0 #define INIT_AUDIO_QUEUE 1 #define SHOW_DEXED_TIMING 1 - +#define SHOW_CPU_LOAD #define TEST_MIDI 1 -#define TEST_NOTE1 60 -#define TEST_NOTE2 68 - -typedef struct -{ - uint8_t cmd; - uint8_t data1; - uint8_t data2; -} midi_queue_t; +#define TEST_NOTE 60 // GUItool: begin automatically generated code AudioPlayQueue queue1; //xy=266,484 @@ -63,8 +53,10 @@ void setup() sgtl5000_1.volume(0.2); // Initialize processor and memory measurements +#ifdef SHOW_CPU_LOAD AudioProcessorUsageMaxReset(); AudioMemoryUsageMaxReset(); +#endif #ifdef INIT_AUDIO_QUEUE // initial fill audio buffer with empty data @@ -82,10 +74,19 @@ void setup() dexed->activate(); #ifdef TEST_MIDI - threads.addThread(midi_test_thread, 1); + queue_midi_event(0x90, TEST_NOTE, 100); + queue_midi_event(0x90, TEST_NOTE + 5, 100); + queue_midi_event(0x90, TEST_NOTE + 8, 100); + queue_midi_event(0x90, TEST_NOTE + 12, 100); + queue_midi_event(0x90, TEST_NOTE + 12, 100); + queue_midi_event(0x90, TEST_NOTE + 17, 100); + queue_midi_event(0x90, TEST_NOTE + 20, 100); + queue_midi_event(0x90, TEST_NOTE + 24, 100); #endif +#ifdef SHOW_CPU_LOAD sched.begin(cpu_and_mem_usage, 1000000); +#endif Serial.println(F("setup end")); } @@ -98,13 +99,13 @@ void loop() if (audio_buffer == NULL) { Serial.println(F("audio_buffer allocation problems!")); - return; } + while (MIDI.read()) { - break_for_calculation = dexed->ProcessMidiMessage(MIDI.getType(), MIDI.getData1(), MIDI.getData2()); - if (break_for_calculation == true) - break; + break_for_calculation = dexed->ProcessMidiMessage(MIDI.getType(), MIDI.getData1(), MIDI.getData2()); + if (break_for_calculation == true) + break; } #ifdef SHOW_DEXED_TIMING @@ -118,34 +119,12 @@ void loop() queue1.playBuffer(); } -void midi_test_thread(void) -{ - delay(100); - /*queue_midi_event(0x90, TEST_NOTE1, 100); - queue_midi_event(0x90, TEST_NOTE2, 100); - delay(1000); - queue_midi_event(0x80, TEST_NOTE1, 100); - delay(1000); - queue_midi_event(0x80, TEST_NOTE2, 100); - delay(500);*/ - for (uint8_t i = 0; i < 16; i++) - { - queue_midi_event(0x90, 55 + i, 100); - delay(1000); - } - delay(1000); - for (uint8_t i = 0; i < 16; i++) - { - queue_midi_event(0x80, 55 + i, 100); - } - threads.yield(); -} - bool queue_midi_event(uint8_t type, uint8_t data1, uint8_t data2) { - return dexed->ProcessMidiMessage(type, data1, data2); + return (dexed->ProcessMidiMessage(type, data1, data2)); } +#ifdef SHOW_CPU_LOAD void cpu_and_mem_usage(void) { Serial.print(F("CPU:")); @@ -157,5 +136,8 @@ void cpu_and_mem_usage(void) Serial.print(F(" MEM MAX:")); Serial.print(AudioMemoryUsageMax(), DEC); Serial.println(); + AudioProcessorUsageMaxReset(); + AudioMemoryUsageMaxReset(); } +#endif diff --git a/dexed.cpp b/dexed.cpp index 63ceb5c..e429b5d 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -89,10 +89,6 @@ Dexed::Dexed(int rate) controllers.opSwitch = 0x3f; // enable all operators //controllers.opSwitch=0x00; - bufsize_ = 256; - - outbuf_ = new float[bufsize_]; - lfo.reset(data + 137); setMonoMode(false); @@ -108,8 +104,6 @@ Dexed::Dexed(int rate) Dexed::~Dexed() { - delete [] outbuf_; - currentNote = -1; for (uint8_t note = 0; note < MAX_ACTIVE_NOTES; ++note) @@ -238,14 +232,13 @@ void Dexed::GetSamples(uint16_t n_samples, int16_t* buffer) TRACE("Shutted down Voice[%2d]", i); } } - // TRACE("Voice[%2d] live=%d keydown=%d",i,voices[i].live,voices[i].keydown); } } } -bool Dexed::ProcessMidiMessage(uint8_t cmd, uint8_t data1, uint8_t data2) +bool Dexed::ProcessMidiMessage(uint8_t type, uint8_t data1, uint8_t data2) { - switch (cmd & 0xf0) { + switch (type & 0xf0) { case 0x80 : //TRACE("MIDI keyup event: %d", data1); keyup(data1); diff --git a/dexed.h b/dexed.h index 392fc80..680f814 100644 --- a/dexed.h +++ b/dexed.h @@ -65,7 +65,7 @@ class Dexed void setMonoMode(bool mode); void set_params(void); void GetSamples(uint16_t n_samples, int16_t* buffer); - bool ProcessMidiMessage(uint8_t cmd, uint8_t data1, uint8_t data2); + bool ProcessMidiMessage(uint8_t type, uint8_t data1, uint8_t data2); Controllers controllers; VoiceStatus voiceStatus; @@ -85,13 +85,10 @@ class Dexed bool monoMode; bool refreshVoice; uint8_t engineType; - //PluginFx fx; Lfo lfo; FmCore* engineMsfa; EngineMkI* engineMkI; EngineOpl* engineOpl; - float* outbuf_; - uint32_t bufsize_; int16_t extra_buf_[_N_]; uint32_t extra_buf_size_;