From 06ffb961e9753300c20200860865e2d833e53ce9 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 11 Jun 2018 15:08:22 +0200 Subject: [PATCH] Small changes and fixes. --- MicroDexed.ino | 14 +++++++------- config.h | 29 +++++++++++++++++------------ dexed.cpp | 10 ++++------ dexed_sysex.cpp | 6 +++--- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 1f5414b..3f0bb01 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -62,7 +62,7 @@ USBHost usb_host; MIDIDevice midi_usb(usb_host); #endif -#ifdef TEST_MIDI +#ifdef TEST_NOTE IntervalTimer sched_note_on; IntervalTimer sched_note_off; uint8_t _voice_counter = 0; @@ -120,7 +120,7 @@ void setup() Serial.print(F("AUDIO_BLOCK_SAMPLES=")); Serial.println(AUDIO_BLOCK_SAMPLES); -#ifdef TEST_MIDI +#ifdef TEST_NOTE Serial.println(F("MIDI test enabled")); sched_note_on.begin(note_on, 2000000); sched_note_off.begin(note_off, 6333333); @@ -129,7 +129,7 @@ void setup() Serial.println(F("setup end")); show_cpu_and_mem_usage(); -#ifdef TEST_MIDI +#ifdef TEST_NOTE //dexed->data[DEXED_VOICE_OFFSET+DEXED_LFO_PITCH_MOD_DEP] = 99; // full pitch mod depth //dexed->data[DEXED_VOICE_OFFSET+DEXED_LFO_PITCH_MOD_SENS] = 99; // full pitch mod sense //dexed->data[DEXED_GLOBAL_PARAMETER_OFFSET+DEXED_MODWHEEL_ASSIGN] = 7; // mod wheel assign all @@ -202,7 +202,7 @@ void handle_midi_input(void) } } -#ifdef TEST_MIDI +#ifdef TEST_NOTE void note_on(void) { randomSeed(analogRead(A0)); @@ -254,13 +254,13 @@ void note_off(void) #ifdef SHOW_MIDI_EVENT void print_midi_event(uint8_t type, uint8_t data1, uint8_t data2) { - Serial.print("MIDI event type: 0x"); + Serial.print(F("MIDI event type: 0x")); if (type < 16) Serial.print(F("0")); Serial.print(type, HEX); - Serial.print(" data1: "); + Serial.print(F(" data1: ")); Serial.print(data1, DEC); - Serial.print(" data2: "); + Serial.print(F(" data2: ")); Serial.println(data2, DEC); } #endif diff --git a/config.h b/config.h index 31293cd..c7b9c88 100644 --- a/config.h +++ b/config.h @@ -21,36 +21,41 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "midinotes.h" -//#define TEST_MIDI 1 -#define TEST_NOTE MIDI_E2 -#define TEST_VEL_MIN 60 -#define TEST_VEL_MAX 110 +#include "midinotes.h" -//#define SHOW_DEXED_TIMING 1 -#define DEBUG 1 -#define SERIAL_SPEED 38400 +// Initial values #define VOLUME 0.1 #define SAMPLE_RATE 44100 //#define DEXED_ENGINE DEXED_ENGINE_MODERN #define USE_ONBOARD_USB_HOST 1 -#define SHOW_MIDI_EVENT 1 -#define SHOW_XRUN 1 -#define SHOW_CPU_LOAD_MSEC 5000 #define MAX_NOTES 16 #define AUDIO_MEM 2 - #define DEFAULT_SYSEXBANK 0 #define DEFAULT_SYSEXSOUND 0 +// Master key handling (comment out for disabling) #define MASTER_KEY_MIDI MIDI_C6 #define MASTER_NUM1 MIDI_C1 +// 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 #define USE_TEENSY_DSP 1 #define SUM_UP_AS_INT 1 #define REDUCE_LOUDNESS 2 +// Enable TEST_NOTE for adding code to drop some midi notes for testing without keyboard +//#define TEST_NOTE MIDI_E2 +#define TEST_VEL_MIN 60 +#define TEST_VEL_MAX 110 + // Use these with the Teensy Audio Shield #define SDCARD_CS_PIN 10 #define SDCARD_MOSI_PIN 7 diff --git a/dexed.cpp b/dexed.cpp index 0fa453b..9539320 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -158,20 +158,18 @@ void Dexed::getSamples(uint16_t n_samples, int16_t* buffer) #else int32_t clip_val = val < -(1 << 24) ? 0x8000 : val >= (1 << 24) ? 0x7fff : val >> 9; #endif - if (clip_val != (val>>9)) - overload++; #ifdef SUM_UP_AS_INT sum = buffer[i + j] + (clip_val >> REDUCE_LOUDNESS); -/* if (buffer[i + j] > 0 && clip_val > 0 && sum < 0) { - sum = 0x8000; + sum = INT_MAX; + overload++; } else if (buffer[i + j] < 0 && clip_val < 0 && sum > 0) { - sum = 0x7FFF; + sum = INT_MIN; + overload++; } - */ buffer[i + j] = sum; audiobuf.get()[j] = 0; #else diff --git a/dexed_sysex.cpp b/dexed_sysex.cpp index f43a26d..f88e526 100644 --- a/dexed_sysex.cpp +++ b/dexed_sysex.cpp @@ -70,11 +70,11 @@ bool load_sysex(uint8_t bank, uint8_t voice_number) { char n[11]; strncpy(n, (char*)&data[118], 10); - Serial.print("<"); + Serial.print(F("<")); Serial.print(entry.name()); - Serial.print("|'"); + Serial.print(F("|'")); Serial.print(n); - Serial.println("'>"); + Serial.println(F("'>")); return (dexed->loadSysexVoice(data)); } else