From 466020094825d002f63af2de750fd03700e50f6b Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Sun, 13 May 2018 16:24:35 +0200 Subject: [PATCH] Small fixes and tests. --- MicroDexed.ino | 97 ++++++++++++++++++++++++++++++++------------------ dexed.cpp | 4 +-- dexed.h | 16 +++++---- dx7note.cpp | 3 +- synth.h | 4 +++ 5 files changed, 80 insertions(+), 44 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 6b99be9..afdf8b2 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -6,7 +6,8 @@ #define RATE 128 #define TEENSY 1 #define TEST_MIDI 1 -#define TEST_NOTE 32 +#define TEST_NOTE1 59 +#define TEST_NOTE2 60 #ifdef TEENSY #include @@ -16,15 +17,28 @@ #include // GUItool: begin automatically generated code -AudioPlayQueue queue1; //xy=811,259 -AudioOutputI2S i2s1; //xy=1185,252 -AudioConnection patchCord1(queue1, 0, i2s1, 0); -AudioConnection patchCord2(queue1, 0, i2s1, 1); -AudioControlSGTL5000 sgtl5000_1; //xy=830,376 +AudioPlayQueue queue1; //xy=266,484 +AudioEffectReverb reverb1; //xy=486,545 +AudioOutputI2S i2s1; //xy=739,486 +AudioConnection patchCord1(queue1, reverb1); +AudioConnection patchCord2(reverb1, 0, i2s1, 0); +AudioConnection patchCord3(reverb1, 0, i2s1, 1); +AudioControlSGTL5000 sgtl5000_1; //xy=384,610 // GUItool: end automatically generated code + +/* + // GUItool: begin automatically generated code + AudioPlayQueue queue1; //xy=811,259 + AudioOutputI2S i2s1; //xy=1185,252 + AudioConnection patchCord1(queue1, 0, i2s1, 0); + AudioConnection patchCord2(queue1, 0, i2s1, 1); + AudioControlSGTL5000 sgtl5000_1; //xy=830,376 + // GUItool: end automatically generated code +*/ + #endif -MIDI_CREATE_DEFAULT_INSTANCE(); +MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI); Dexed* dexed = new Dexed(RATE); @@ -40,10 +54,10 @@ void setup() #ifdef TEENSY // Audio connections require memory to work. For more // detailed information, see the MemoryAndCpuUsage example - AudioMemory(8); + AudioMemory(16); sgtl5000_1.enable(); - sgtl5000_1.volume(0.3); + sgtl5000_1.volume(0.6); // Initialize processor and memory measurements //AudioProcessorUsageMaxReset(); @@ -52,18 +66,24 @@ void setup() // initial fill audio buffer while (queue1.available()) { - queue1.getBuffer(); - queue1.playBuffer(); + int16_t* audio_buffer = queue1.getBuffer(); + if (audio_buffer != NULL) + { + memset(audio_buffer,0,RATE); + queue1.playBuffer(); + } } #endif dexed->activate(); #ifdef TEST_MIDI - dexed->ProcessMidiMessage(0x90, TEST_NOTE, 100); - //dexed->ProcessMidiMessage(0x90, 66, 127); + dexed->ProcessMidiMessage(0x90, TEST_NOTE1, 100); + dexed->ProcessMidiMessage(0x90, TEST_NOTE2, 60); #endif + reverb1.reverbTime(5.0); + Serial.println("Go"); } @@ -73,7 +93,9 @@ void loop() #ifdef TEST_MIDI if (millis() > 3000 && millis() < 3050) - dexed->ProcessMidiMessage(0x80, TEST_NOTE, 0); + dexed->ProcessMidiMessage(0x80, TEST_NOTE1, 0); + if (millis() > 5000 && millis() < 5050) + dexed->ProcessMidiMessage(0x80, TEST_NOTE2, 0); #endif #ifdef TEENSY @@ -88,28 +110,35 @@ void loop() // process midi->audio if (MIDI.read()) { + Serial.print("Type: "); + Serial.print(MIDI.getType(), DEC); + Serial.print(" Data1: "); + Serial.print(MIDI.getData1(), DEC); + Serial.print(" Data2: "); + Serial.println(MIDI.getData2(), DEC); dexed->ProcessMidiMessage(MIDI.getType(), MIDI.getData1(), MIDI.getData2()); } - - dexed->GetSamples(RATE, audio_buffer); - - /* uint8_t i = 0; - for (i = 0; i < 128; i++) - { - if ((i % 16) == 0) - Serial.println(); - - if (i < 10) - Serial.print(" "); - if (i > 9 && i < 100) - Serial.print(" "); - Serial.print("["); - Serial.print(i, DEC); - Serial.print("]:"); - Serial.print(audio_buffer[i]); - Serial.print(" "); - } - Serial.println();*/ + else + + dexed->GetSamples(RATE, audio_buffer); + + /* uint8_t i = 0; + for (i = 0; i < 128; i++) + { + if ((i % 16) == 0) + Serial.println(); + + if (i < 10) + Serial.print(" "); + if (i > 9 && i < 100) + Serial.print(" "); + Serial.print("["); + Serial.print(i, DEC); + Serial.print("]:"); + Serial.print(audio_buffer[i]); + Serial.print(" "); + } + Serial.println();*/ #ifdef TEENSY queue1.playBuffer(); diff --git a/dexed.cpp b/dexed.cpp index 7335ebc..2273630 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -195,7 +195,7 @@ void Dexed::GetSamples(uint16_t n_samples, int16_t* buffer) { //buffer[i + j] = static_cast(sumbuf[j]*0x8000); buffer[i + j] = sumbuf[j]; - Serial.println(buffer[i + j], DEC); + //Serial.println(buffer[i + j], DEC); } else extra_buf_[j - jmax] = sumbuf[j]; @@ -350,7 +350,7 @@ void Dexed::keydown(uint8_t pitch, uint8_t velo) { voices[note].velocity = velo; voices[note].sustained = sustain; voices[note].keydown = true; - voices[note].dx7_note->init(data, pitch, velo); + voices[note].dx7_note->init(data, (int)pitch, (int)velo); if ( data[136] ) voices[note].dx7_note->oscSync(); break; diff --git a/dexed.h b/dexed.h index eda9d51..0b587c7 100644 --- a/dexed.h +++ b/dexed.h @@ -99,13 +99,14 @@ class Dexed uint16_t _rate; uint8_t _k_rate_counter; uint8_t _param_change_counter; + uint8_t data[173] = { - 95, 29, 20, 50, 99, 95, 00, 00, 41, 00, 19, 00, 00, 03, 00, 06, 79, 00, 01, 00, 14, - 95, 20, 20, 50, 99, 95, 00, 00, 00, 00, 00, 00, 00, 03, 00, 00, 99, 00, 01, 00, 00, - 95, 29, 20, 50, 99, 95, 00, 00, 00, 00, 00, 00, 00, 03, 00, 06, 89, 00, 01, 00, 07, - 95, 20, 20, 50, 99, 95, 00, 00, 00, 00, 00, 00, 00, 03, 00, 02, 99, 00, 01, 00, 07, - 95, 50, 35, 78, 99, 75, 00, 00, 00, 00, 00, 00, 00, 03, 00, 07, 58, 00, 14, 00, 07, - 96, 25, 25, 67, 99, 75, 00, 00, 00, 00, 00, 00, 00, 03, 00, 02, 99, 00, 01, 00, 10, + 95, 29, 20, 50, 99, 95, 00, 00, 41, 00, 19, 00, 00, 03, 00, 06, 79, 00, 01, 00, 14, // OP + 95, 20, 20, 50, 99, 95, 00, 00, 00, 00, 00, 00, 00, 03, 00, 00, 99, 00, 01, 00, 00, // OP + 95, 29, 20, 50, 99, 95, 00, 00, 00, 00, 00, 00, 00, 03, 00, 06, 89, 00, 01, 00, 07, // OP + 95, 20, 20, 50, 99, 95, 00, 00, 00, 00, 00, 00, 00, 03, 00, 02, 99, 00, 01, 00, 07, // OP + 95, 50, 35, 78, 99, 75, 00, 00, 00, 00, 00, 00, 00, 03, 00, 07, 58, 00, 14, 00, 07, // OP + 96, 25, 25, 67, 99, 75, 00, 00, 00, 00, 00, 00, 00, 03, 00, 02, 99, 00, 01, 00, 10, // OP 94, 67, 95, 60, 50, 50, 50, 50, 04, 06, 00, 34, 33, 00, 00, 00, 04, @@ -115,7 +116,8 @@ class Dexed 00, 01, 01, 01, 01, 01, 01, 16 - }; + }; // INIT + }; #endif // PLUGINPROCESSOR_H_INCLUDED diff --git a/dx7note.cpp b/dx7note.cpp index ce34341..0050aad 100644 --- a/dx7note.cpp +++ b/dx7note.cpp @@ -144,7 +144,8 @@ Dx7Note::Dx7Note() { } } -void Dx7Note::init(const uint8_t patch[156], int midinote, int velocity) { +//void Dx7Note::init(const uint8_t patch[156], int midinote, int velocity) { +void Dx7Note::init(const uint8_t patch[173], int midinote, int velocity) { int rates[4]; int levels[4]; for (int op = 0; op < 6; op++) { diff --git a/synth.h b/synth.h index 2dfda9f..838162d 100644 --- a/synth.h +++ b/synth.h @@ -17,6 +17,8 @@ #ifndef __SYNTH_H #define __SYNTH_H +#include + // This IS not be present on MSVC. // See http://stackoverflow.com/questions/126279/c99-stdint-h-header-and-ms-visual-studio #include @@ -47,6 +49,7 @@ typedef __int16 SInt16; #define SynthMemoryBarrier() #endif +/* template inline static T min(const T& a, const T& b) { return a < b ? a : b; @@ -56,6 +59,7 @@ template inline static T max(const T& a, const T& b) { return a > b ? a : b; } +*/ #define QER(n,b) ( ((float)n)/(1<