From d2052dc28f91a4d9071df63bf61694a4b8d38d9c Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Fri, 20 Jul 2018 08:27:47 +0200 Subject: [PATCH] Removed freeverb and mixer due to latency problems. Replaced mixer with amp. Showing maximum timing for the last n secs when showing CPU usage. --- MicroDexed.ino | 50 +++++++++++++++++++++---------------------------- config.h | 9 +++------ dexed.cpp | 16 ++++++++-------- dexed_sysex.cpp | 4 ++++ 4 files changed, 36 insertions(+), 43 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index cd7733f..8c35187 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -51,27 +51,25 @@ Bounce but1 = Bounce(BUT1_PIN, 10); // 10 ms debounce #endif // GUItool: begin automatically generated code -AudioPlayQueue queue1; //xy=637,396 -AudioEffectFreeverbStereo freeverbs1; //xy=815,506 -AudioMixer4 mixer2; //xy=1014,461 -AudioMixer4 mixer1; //xy=1016,376 -AudioOutputI2S i2s1; //xy=1214,414 -AudioConnection patchCord1(queue1, freeverbs1); -AudioConnection patchCord2(queue1, 0, mixer1, 0); -AudioConnection patchCord3(queue1, 0, mixer2, 0); -AudioConnection patchCord4(freeverbs1, 0, mixer1, 1); -AudioConnection patchCord5(freeverbs1, 1, mixer2, 1); -AudioConnection patchCord6(mixer2, 0, i2s1, 1); -AudioConnection patchCord7(mixer1, 0, i2s1, 0); -AudioControlSGTL5000 sgtl5000_1; //xy=1214,469 +AudioPlayQueue queue1; //xy=708,349 +AudioAmplifier amp1; //xy=904,314 +AudioAmplifier amp2; //xy=909,373 +AudioOutputI2S i2s1; //xy=1055,343 +AudioConnection patchCord1(queue1, amp1); +AudioConnection patchCord2(queue1, amp2); +AudioConnection patchCord3(amp1, 0, i2s1, 0); +AudioConnection patchCord4(amp2, 0, i2s1, 1); +AudioControlSGTL5000 sgtl5000_1; //xy=1055,398 // GUItool: end automatically generated code + Dexed* dexed = new Dexed(SAMPLE_RATE); bool sd_card_available = false; uint8_t bank = EEPROM.read(EEPROM_BANK_ADDR); uint8_t midi_channel = DEFAULT_MIDI_CHANNEL; uint32_t xrun = 0; uint32_t overload = 0; +uint16_t render_time_max = 0; #ifdef MASTER_KEY_MIDI bool master_key_enabled = false; @@ -133,17 +131,9 @@ void setup() AudioMemory(AUDIO_MEM); sgtl5000_1.enable(); sgtl5000_1.volume(VOLUME); + amp1.gain(1.0); // normal audio + amp2.gain(1.0); // normal audio - // configure mixer - mixer1.gain(0,1.0); // normal audio - mixer2.gain(0,0.2); // reverb audio - mixer1.gain(0,1.0); // normal audio - mixer2.gain(0,0.2); // reverb audio - - // configure reverb - freeverbs1.roomsize(DEFAULT_REVERB_ROOMSIZE); - freeverbs1.damping(DEFAULT_REVERB_DAMPING); - // start SD card SPI.setMOSI(SDCARD_MOSI_PIN); SPI.setSCK(SDCARD_SCK_PIN); @@ -203,7 +193,7 @@ void setup() void loop() { int16_t* audio_buffer; // pointer to 128 * int16_t (=256 bytes!) - + while (42 == 42) // DON'T PANIC! { #if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC) @@ -221,18 +211,17 @@ void loop() { Serial.println(F("E: audio_buffer allocation problems!")); } - + if (!queue1.available()) continue; - + elapsedMicros t1; dexed->getSamples(AUDIO_BLOCK_SAMPLES, audio_buffer); uint32_t t2 = t1; if (t2 > 2900) // everything greater 2.9ms is a buffer underrun! xrun++; -#ifdef SHOW_DEXED_TIMING - Serial.println(t1, DEC); -#endif + if (t2 > render_time_max) + render_time_max = t2; queue1.playBuffer(); } } @@ -607,6 +596,8 @@ void show_cpu_and_mem_usage(void) Serial.print(AudioMemoryUsage(), DEC); Serial.print(F(" MEM MAX: ")); Serial.print(AudioMemoryUsageMax(), DEC); + Serial.print(F(" RENDER_TIME_MAX: ")); + Serial.print(render_time_max, DEC); Serial.print(F(" XRUN: ")); Serial.print(xrun, DEC); Serial.print(F(" OVERLOAD: ")); @@ -614,6 +605,7 @@ void show_cpu_and_mem_usage(void) Serial.println(); AudioProcessorUsageMaxReset(); AudioMemoryUsageMaxReset(); + render_time_max=0; } #endif diff --git a/config.h b/config.h index 1d88804..ae33304 100644 --- a/config.h +++ b/config.h @@ -28,14 +28,12 @@ #define MIDI_DEVICE Serial1 #define USE_ONBOARD_USB_HOST 1 #define VOLUME 0.8 -#define SAMPLE_RATE 44100 #define DEFAULT_MIDI_CHANNEL MIDI_CHANNEL_OMNI #define DEFAULT_SYSEXBANK 0 #define DEFAULT_SYSEXSOUND 0 -#define DEFAULT_REVERB_ROOMSIZE 0.5 -#define DEFAULT_REVERB_DAMPING 0.5 //#define DEXED_ENGINE DEXED_ENGINE_MODERN -#define AUDIO_MEM 32 +#define AUDIO_MEM 2 +#define SAMPLE_RATE 44100 #if !defined(__MK66FX1M0__) // check for Teensy-3.6 #define MAX_NOTES 11 // No? @@ -49,13 +47,12 @@ // Debug output #define SERIAL_SPEED 38400 -//#define SHOW_DEXED_TIMING 1 #define DEBUG 1 #define SHOW_MIDI_EVENT 1 #define SHOW_XRUN 1 #define SHOW_CPU_LOAD_MSEC 5000 -// Some optimizations in the code +// Some optimizations #define USE_TEENSY_DSP 1 #define SUM_UP_AS_INT 1 #define REDUCE_LOUDNESS 2 diff --git a/dexed.cpp b/dexed.cpp index b3b3a3f..e611e49 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -45,8 +45,8 @@ extern AudioControlSGTL5000 sgtl5000_1; extern AudioAmplifier amp1; extern AudioAmplifier amp2; extern AudioEffectFreeverbStereo freeverbs1; -extern AudioMixer4 mixer2; -extern AudioMixer4 mixer1; +extern AudioAmplifier amp1; +extern AudioAmplifier amp2; Dexed::Dexed(int rate) { @@ -240,18 +240,18 @@ bool Dexed::processMidiMessage(uint8_t type, uint8_t data1, uint8_t data2) case 10: // Pan if (value < 64) { - mixer1.gain(0, 1.0); - mixer2.gain(0, float(value) / 0x40); + amp1.gain(1.0); + amp2.gain(float(value) / 0x40); } else if (value > 64) { - mixer1.gain(0, float(0x7f - value) / 0x40); - mixer2.gain(0, 1.0); + amp1.gain(float(0x7f - value) / 0x40); + amp2.gain(1.0); } else { - mixer1.gain(0, 1.0); - mixer2.gain(0, 1.0); + amp1.gain(1.0); + amp2.gain(1.0); } break; case 32: // BankSelect LSB diff --git a/dexed_sysex.cpp b/dexed_sysex.cpp index f758e96..32e1564 100644 --- a/dexed_sysex.cpp +++ b/dexed_sysex.cpp @@ -30,6 +30,8 @@ #include "dexed_sysex.h" #include "config.h" +extern uint16_t render_time_max; + bool load_sysex(uint8_t bank, uint8_t voice_number) { File root; @@ -194,5 +196,7 @@ bool get_sysex_voice(char* dir, File sysex, uint8_t voice_number, uint8_t* data) } #endif + render_time_max=0; + return (true); }