diff --git a/examples/BAExpansionCalibrate/BAExpansionCalibrate.ino b/examples/BAExpansionCalibrate/BAExpansionCalibrate.ino deleted file mode 100644 index 697eee0..0000000 --- a/examples/BAExpansionCalibrate/BAExpansionCalibrate.ino +++ /dev/null @@ -1,81 +0,0 @@ -/************************************************************************* - * This demo uses the BALibrary library to provide enhanced control of - * the TGA Pro board. - * - * The latest copy of the BA Guitar library can be obtained from - * https://github.com/Blackaddr/BALibrary - * - * This program can be used to find out the calibration values for each of your POTs - * on the Blackaddr Audio Expansion Control Board. - * - * USE THE ARDUINO SERIAL MONITOR TO PERFORM THE CALIBRATION - * - * When prompted turn the appropriate POT in the specified direction and - * enter any character on the terminal input line and press enter to send the character. - */ -#include "BALibrary.h" - -using namespace BALibrary; - -// Create physical controls for Expansion Board, 2 switches, 3 pots, 0 encoders, 2 LEDs -BAPhysicalControls controls(BA_EXPAND_NUM_SW, BA_EXPAND_NUM_POT, 0, BA_EXPAND_NUM_LED); - -void setup() { - delay(100); - Serial.begin(57600); - delay(500); // long delay to wait for Serial to init - - TGA_PRO_EXPAND_REV2(); // Set the expansion board revision - - // put your setup code here, to run once: - Serial.println("Calibrating POT1"); - Potentiometer::Calib pot1Calib = Potentiometer::calibrate(BA_EXPAND_POT1_PIN); - if (pot1Calib.min == pot1Calib.max) { Serial.println("\n!!! The knob didn't appear to move. Are you SURE you're turning the right knob? !!!"); } - - Serial.println("\nCalibrating POT2"); - Potentiometer::Calib pot2Calib = Potentiometer::calibrate(BA_EXPAND_POT2_PIN); - if (pot2Calib.min == pot2Calib.max) { Serial.println("\n!!! The knob didn't appear to move. Are you SURE you're turning the right knob? !!!"); } - - Serial.println("\nCalibrating POT3"); - Potentiometer::Calib pot3Calib = Potentiometer::calibrate(BA_EXPAND_POT3_PIN); - if (pot3Calib.min == pot3Calib.max) { Serial.println("\n!!! The knob didn't appear to move. Are you SURE you're turning the right knob? !!!"); } - - // Create the controls using the calib values - controls.addPot(BA_EXPAND_POT1_PIN, pot1Calib.min, pot1Calib.max, pot1Calib.swap); - controls.addPot(BA_EXPAND_POT2_PIN, pot2Calib.min, pot2Calib.max, pot2Calib.swap); - controls.addPot(BA_EXPAND_POT3_PIN, pot3Calib.min, pot3Calib.max, pot3Calib.swap); - - // Add the pushbuttons - controls.addSwitch(BA_EXPAND_SW1_PIN); - controls.addSwitch(BA_EXPAND_SW2_PIN); - - // Setup the LEDs - controls.addOutput(BA_EXPAND_LED1_PIN); - controls.setOutput(BA_EXPAND_LED1_PIN, 0); - controls.addOutput(BA_EXPAND_LED2_PIN); - controls.setOutput(BA_EXPAND_LED2_PIN, 0); - - Serial.println("DONE SETUP! Try turning knobs and pushing buttons!\n"); - -} - -void loop() { - // put your main code here, to run repeatedly: - float value; - for (unsigned i=0; i -#include -#include -#include "BALibrary.h" - -MIDI_CREATE_DEFAULT_INSTANCE(); -using namespace midi; -using namespace BALibrary; - -AudioInputI2S i2sIn; -AudioOutputI2S i2sOut; - -// Audio Thru Connection -AudioConnection patch0(i2sIn,0, i2sOut, 0); -AudioConnection patch1(i2sIn,1, i2sOut, 1); - -BAAudioControlWM8731 codecControl; -BAGpio gpio; // access to User LED - -unsigned long t=0; - -void setup() { - - MIDI.begin(MIDI_CHANNEL_OMNI); - Serial.begin(57600); - delay(5); - while (!Serial) { yield(); } - - // If the codec was already powered up (due to reboot) power itd own first - codecControl.disable(); - delay(100); - AudioMemory(24); - - Serial.println("Enabling codec...\n"); - codecControl.enable(); - delay(100); - -} - -void loop() { - - /////////////////////////////////////////////////////////////////////// - // MIDI TESTING - // Connect a loopback cable between the MIDI IN and MIDI OUT on the - // GTA Pro. This test code will periodically send MIDI events which - // will loop back and get printed in the Serial Monitor. - /////////////////////////////////////////////////////////////////////// - DataByte note, velocity, channel, d1, d2; - - // Send MIDI OUT - int cc, val=0xA, channelSend = 1; - for (cc=32; cc<40; cc++) { - MIDI.sendControlChange(cc, val, channelSend); val++; channelSend++; - delay(100); - MIDI.sendNoteOn(10, 100, channelSend); - delay(100); - } - - if (MIDI.read()) { // Is there a MIDI message incoming ? - MidiType type = MIDI.getType(); - Serial.println(String("MIDI IS WORKING!!!")); - switch (type) { - case NoteOn: - note = MIDI.getData1(); - velocity = MIDI.getData2(); - channel = MIDI.getChannel(); - if (velocity > 0) { - Serial.println(String("Note On: ch=") + channel + ", note=" + note + ", velocity=" + velocity); - } else { - Serial.println(String("Note Off: ch=") + channel + ", note=" + note); - } - break; - case NoteOff: - note = MIDI.getData1(); - velocity = MIDI.getData2(); - channel = MIDI.getChannel(); - Serial.println(String("Note Off: ch=") + channel + ", note=" + note + ", velocity=" + velocity); - break; - default: - d1 = MIDI.getData1(); - d2 = MIDI.getData2(); - Serial.println(String("Message, type=") + type + ", data = " + d1 + " " + d2); - } - t = millis(); - } - - if (millis() - t > 10000) { - t += 10000; - Serial.println("(no MIDI activity, check cables)"); - } - - // Toggle the USR LED state - gpio.toggleLed(); - -} diff --git a/examples/Basic/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino b/examples/Basic/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino deleted file mode 100644 index 09481d7..0000000 --- a/examples/Basic/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino +++ /dev/null @@ -1,209 +0,0 @@ -/************************************************************************* - * This demo uses the BALibrary library to provide enhanced control of - * the TGA Pro board. - * - * The latest copy of the BA Guitar library can be obtained from - * https://github.com/Blackaddr/BALibrary - * - * This demo will provide an audio passthrough, as well as exercise the - * MIDI interface. - * - * It will also peform a sweep of SPI MEM0. - * - * NOTE: SPI MEM0 can be used by a Teensy 3.1/3.2/3.5/3.6. - * pins. - * - */ -#include -#include -#include -#include "BALibrary.h" - -MIDI_CREATE_DEFAULT_INSTANCE(); -using namespace midi; - -using namespace BALibrary; - -AudioInputI2S i2sIn; -AudioOutputI2S i2sOut; - -// Audio Thru Connection -AudioConnection patch0(i2sIn,0, i2sOut, 0); -AudioConnection patch1(i2sIn,1, i2sOut, 1); - -BAAudioControlWM8731 codecControl; -BAGpio gpio; // access to User LED -BASpiMemory spiMem0(SpiDeviceId::SPI_DEVICE0); - -unsigned long t=0; - -// SPI stuff -unsigned spiAddress0 = 0; -uint16_t spiData0 = 0xABCD; -int spiErrorCount0 = 0; - -constexpr int mask0 = 0x5555; -constexpr int mask1 = 0xaaaa; - -int maskPhase = 0; -int loopPhase = 0; - -void setup() { - - MIDI.begin(MIDI_CHANNEL_OMNI); - Serial.begin(57600); - while (!Serial) { yield(); } - delay(5); - - SPI_MEM0_1M(); // Set the Spi memory size to 1Mbit - - // If the codec was already powered up (due to reboot) power itd own first - codecControl.disable(); - delay(100); - AudioMemory(24); - - Serial.println("Sketch: Enabling codec...\n"); - codecControl.enable(); - delay(100); - - Serial.println("Enabling SPI"); - spiMem0.begin(); - -} - -int calcData(int spiAddress, int loopPhase, int maskPhase) -{ - int data; - - int phase = ((loopPhase << 1) + maskPhase) & 0x3; - switch(phase) - { - case 0 : - data = spiAddress ^ mask0; - break; - case 1: - data = spiAddress ^ mask1; - break; - case 2: - data = ~spiAddress ^ mask0; - break; - case 3: - data = ~spiAddress ^ mask1; - - } - return (data & 0xffff); -} - -void loop() { - - ////////////////////////////////////////////////////////////////// - // Write test data to the SPI Memory 0 - ////////////////////////////////////////////////////////////////// - maskPhase = 0; - for (spiAddress0=0; spiAddress0 <= BAHardwareConfig.getSpiMemMaxAddr(0); spiAddress0=spiAddress0+2) { - if ((spiAddress0 % 32768) == 0) { - //Serial.print("Writing to "); - //Serial.println(spiAddress0, HEX); - } - - spiData0 = calcData(spiAddress0, loopPhase, maskPhase); - spiMem0.write16(spiAddress0, spiData0); - maskPhase = (maskPhase+1) % 2; - } - Serial.println("SPI0 writing DONE!"); - - /////////////////////////////////////////////////////////////////// - // Read back from the SPI Memory 0 - /////////////////////////////////////////////////////////////////// - spiErrorCount0 = 0; - spiAddress0 = 0; - maskPhase = 0; - - for (spiAddress0=0; spiAddress0 <= BAHardwareConfig.getSpiMemMaxAddr(0); spiAddress0=spiAddress0+2) { - if ((spiAddress0 % 32768) == 0) { -// Serial.print("Reading "); -// Serial.print(spiAddress0, HEX); - } - - spiData0 = calcData(spiAddress0, loopPhase, maskPhase); - int data = spiMem0.read16(spiAddress0); - if (data != spiData0) { - spiErrorCount0++; - Serial.println(""); - Serial.print("ERROR MEM0: (expected) (actual):"); - Serial.print(spiData0, HEX); Serial.print(":"); - Serial.print(data, HEX); - - delay(100); - } - maskPhase = (maskPhase+1) % 2; - - if ((spiAddress0 % 32768) == 0) { -// Serial.print(", data = "); -// Serial.println(data, HEX); -// Serial.println(String(" loopPhase: ") + loopPhase + String(" maskPhase: ") + maskPhase); - } - - // Break out of test once the error count reaches 10 - if (spiErrorCount0 > 10) { break; } - - } - - if (spiErrorCount0 == 0) { Serial.println("SPI0 TEST PASSED!!!"); } - - loopPhase = (loopPhase+1) % 2; - - /////////////////////////////////////////////////////////////////////// - // MIDI TESTING - // Connect a loopback cable between the MIDI IN and MIDI OUT on the - // GTA Pro. This test code will periodically send MIDI events which - // will loop back and get printed in the Serial Monitor. - /////////////////////////////////////////////////////////////////////// - DataByte note, velocity, channel, d1, d2; - - // Send MIDI OUT - int cc, val=0xA, channelSend = 1; - for (cc=32; cc<40; cc++) { - MIDI.sendControlChange(cc, val, channelSend); val++; channelSend++; - delay(100); - MIDI.sendNoteOn(10, 100, channelSend); - delay(100); - } - - if (MIDI.read()) { // Is there a MIDI message incoming ? - MidiType type = MIDI.getType(); - Serial.println(String("MIDI IS WORKING!!!")); - switch (type) { - case NoteOn: - note = MIDI.getData1(); - velocity = MIDI.getData2(); - channel = MIDI.getChannel(); - if (velocity > 0) { - Serial.println(String("Note On: ch=") + channel + ", note=" + note + ", velocity=" + velocity); - } else { - Serial.println(String("Note Off: ch=") + channel + ", note=" + note); - } - break; - case NoteOff: - note = MIDI.getData1(); - velocity = MIDI.getData2(); - channel = MIDI.getChannel(); - Serial.println(String("Note Off: ch=") + channel + ", note=" + note + ", velocity=" + velocity); - break; - default: - d1 = MIDI.getData1(); - d2 = MIDI.getData2(); - Serial.println(String("Message, type=") + type + ", data = " + d1 + " " + d2); - } - t = millis(); - } - - if (millis() - t > 10000) { - t += 10000; - Serial.println("(no MIDI activity, check cables)"); - } - - // Toggle the USR LED state - gpio.toggleLed(); - -} diff --git a/examples/Basic/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino b/examples/Basic/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino deleted file mode 100644 index 5f570a7..0000000 --- a/examples/Basic/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino +++ /dev/null @@ -1,271 +0,0 @@ -/************************************************************************* - * This demo uses the BALibrary library to provide enhanced control of - * the TGA Pro board. - * - * The latest copy of the BA Guitar library can be obtained from - * https://github.com/Blackaddr/BALibrary - * - * This demo will provide an audio passthrough, as well as exercise the - * MIDI interface. - * - * It will also peform a sweep of SPI MEM0 and MEM1. - * - * NOTE: SPI MEM0 can be used by a Teensy 3.1/3.2/3.5/3.6. SPI MEM1 - * can only be used by a Teensy 3.5/3.6 since it is mapped to the extended - * pins. - * - */ -#include -#include -#include -#include "BALibrary.h" - -MIDI_CREATE_DEFAULT_INSTANCE(); -using namespace midi; -using namespace BALibrary; - -AudioInputI2S i2sIn; -AudioOutputI2S i2sOut; - -// Audio Thru Connection -AudioConnection patch0(i2sIn,0, i2sOut, 0); -AudioConnection patch1(i2sIn,1, i2sOut, 1); - -BAAudioControlWM8731 codecControl; -BAGpio gpio; // access to User LED -BASpiMemory spiMem0(SpiDeviceId::SPI_DEVICE0); -BASpiMemory spiMem1(SpiDeviceId::SPI_DEVICE1); - -unsigned long t=0; - -// SPI stuff -int spiAddress0 = 0; -uint16_t spiData0 = 0xABCD; -int spiErrorCount0 = 0; - -int spiAddress1 = 0; -uint16_t spiData1 = 0xDCBA; -int spiErrorCount1 = 0; - -constexpr int mask0 = 0x5555; -constexpr int mask1 = 0xaaaa; - -int maskPhase = 0; -int loopPhase = 0; - -void setup() { - - MIDI.begin(MIDI_CHANNEL_OMNI); - Serial.begin(57600); - while (!Serial) { yield(); } - delay(5); - - // Set the SPI memory sizes - SPI_MEM0_1M(); - SPI_MEM1_1M(); - - // If the codec was already powered up (due to reboot) power itd own first - codecControl.disable(); - delay(100); - AudioMemory(24); - - Serial.println("Sketch: Enabling codec...\n"); - codecControl.enable(); - delay(100); - - Serial.println("Enabling SPI"); - spiMem0.begin(); - spiMem1.begin(); - -} - -int calcData(int spiAddress, int loopPhase, int maskPhase) -{ - int data; - - int phase = ((loopPhase << 1) + maskPhase) & 0x3; - switch(phase) - { - case 0 : - data = spiAddress ^ mask0; - break; - case 1: - data = spiAddress ^ mask1; - break; - case 2: - data = ~spiAddress ^ mask0; - break; - case 3: - data = ~spiAddress ^ mask1; - - } - return (data & 0xffff); -} - -void loop() { - - ////////////////////////////////////////////////////////////////// - // Write test data to the SPI Memory 0 - ////////////////////////////////////////////////////////////////// - maskPhase = 0; - for (spiAddress0=0; spiAddress0 <= BAHardwareConfig.getSpiMemMaxAddr(0); spiAddress0=spiAddress0+2) { - if ((spiAddress0 % 32768) == 0) { - //Serial.print("Writing to "); - //Serial.println(spiAddress0, HEX); - } - - spiData0 = calcData(spiAddress0, loopPhase, maskPhase); - spiMem0.write16(spiAddress0, spiData0); - maskPhase = (maskPhase+1) % 2; - } - Serial.println("SPI0 writing DONE!"); - - /////////////////////////////////////////////////////////////////// - // Read back from the SPI Memory 0 - /////////////////////////////////////////////////////////////////// - spiErrorCount0 = 0; - spiAddress0 = 0; - maskPhase = 0; - - for (spiAddress0=0; spiAddress0 <= BAHardwareConfig.getSpiMemMaxAddr(0); spiAddress0=spiAddress0+2) { - if ((spiAddress0 % 32768) == 0) { -// Serial.print("Reading "); -// Serial.print(spiAddress0, HEX); - } - - spiData0 = calcData(spiAddress0, loopPhase, maskPhase); - int data = spiMem0.read16(spiAddress0); - if (data != spiData0) { - spiErrorCount0++; - Serial.println(""); - Serial.print("ERROR MEM0: (expected) (actual):"); - Serial.print(spiData0, HEX); Serial.print(":"); - Serial.print(data, HEX); - - delay(100); - } - maskPhase = (maskPhase+1) % 2; - - if ((spiAddress0 % 32768) == 0) { -// Serial.print(", data = "); -// Serial.println(data, HEX); -// Serial.println(String(" loopPhase: ") + loopPhase + String(" maskPhase: ") + maskPhase); - } - - // Break out of test once the error count reaches 10 - if (spiErrorCount0 > 10) { break; } - - } - - if (spiErrorCount0 == 0) { Serial.println("SPI0 TEST PASSED!!!"); } - - - ////////////////////////////////////////////////////////////////// - // Write test data to the SPI Memory 1 - ////////////////////////////////////////////////////////////////// - maskPhase = 0; - for (spiAddress1=0; spiAddress1 <= BAHardwareConfig.getSpiMemMaxAddr(1); spiAddress1+=2) { - if ((spiAddress1 % 32768) == 0) { - //Serial.print("Writing to "); - //Serial.println(spiAddress1, HEX); - } - - spiData1 = calcData(spiAddress1, loopPhase, maskPhase); - spiMem1.write16(spiAddress1, spiData1); - maskPhase = (maskPhase+1) % 2; - } - Serial.println("SPI1 writing DONE!"); - - /////////////////////////////////////////////////////////////////// - // Read back from the SPI Memory 1 - /////////////////////////////////////////////////////////////////// - spiErrorCount1 = 0; - spiAddress1 = 0; - - maskPhase = 0; - for (spiAddress1=0; spiAddress1 <= BAHardwareConfig.getSpiMemMaxAddr(1); spiAddress1+=2) { - if ((spiAddress1 % 32768) == 0) { - //Serial.print("Reading "); - //Serial.print(spiAddress1, HEX); - } - - spiData1 = calcData(spiAddress1, loopPhase, maskPhase); - uint16_t data = spiMem1.read16(spiAddress1); - if (data != spiData1) { - spiErrorCount1++; - Serial.println(""); - Serial.print("ERROR MEM1: (expected) (actual):"); - Serial.print(spiData1, HEX); Serial.print(":"); - Serial.println(data, HEX); - delay(100); - } - maskPhase = (maskPhase+1) % 2; - - if ((spiAddress1 % 32768) == 0) { - //Serial.print(", data = "); - //Serial.println(data, HEX); - } - - // Break out of test once the error count reaches 10 - if (spiErrorCount1 > 10) { break; } - - } - - if (spiErrorCount1 == 0) { Serial.println("SPI1 TEST PASSED!!!"); } - - loopPhase = (loopPhase+1) % 2; - - /////////////////////////////////////////////////////////////////////// - // MIDI TESTING - // Connect a loopback cable between the MIDI IN and MIDI OUT on the - // GTA Pro. This test code will periodically send MIDI events which - // will loop back and get printed in the Serial Monitor. - /////////////////////////////////////////////////////////////////////// - DataByte note, velocity, channel, d1, d2; - - // Send MIDI OUT - int cc, val=0xA, channelSend = 1; - for (cc=32; cc<40; cc++) { - MIDI.sendControlChange(cc, val, channelSend); val++; channelSend++; - delay(100); - MIDI.sendNoteOn(10, 100, channelSend); - delay(100); - } - - if (MIDI.read()) { // Is there a MIDI message incoming ? - MidiType type = MIDI.getType(); - Serial.println(String("MIDI IS WORKING!!!")); - switch (type) { - case NoteOn: - note = MIDI.getData1(); - velocity = MIDI.getData2(); - channel = MIDI.getChannel(); - if (velocity > 0) { - Serial.println(String("Note On: ch=") + channel + ", note=" + note + ", velocity=" + velocity); - } else { - Serial.println(String("Note Off: ch=") + channel + ", note=" + note); - } - break; - case NoteOff: - note = MIDI.getData1(); - velocity = MIDI.getData2(); - channel = MIDI.getChannel(); - Serial.println(String("Note Off: ch=") + channel + ", note=" + note + ", velocity=" + velocity); - break; - default: - d1 = MIDI.getData1(); - d2 = MIDI.getData2(); - Serial.println(String("Message, type=") + type + ", data = " + d1 + " " + d2); - } - t = millis(); - } - - if (millis() - t > 10000) { - t += 10000; - Serial.println("(no MIDI activity, check cables)"); - } - - // Toggle the USR LED state - gpio.toggleLed(); - -} diff --git a/examples/Basic/BA4_TGA_Pro_delay_reverb/BA4_TGA_Pro_delay_reverb.ino b/examples/Basic/BA4_TGA_Pro_delay_reverb/BA4_TGA_Pro_delay_reverb.ino deleted file mode 100644 index e6ca5d2..0000000 --- a/examples/Basic/BA4_TGA_Pro_delay_reverb/BA4_TGA_Pro_delay_reverb.ino +++ /dev/null @@ -1,76 +0,0 @@ -/************************************************************************* - * This demo uses the BALibrary library to provide enhanced control of - * the TGA Pro board. - * - * The latest copy of the BA Guitar library can be obtained from - * https://github.com/Blackaddr/BALibrary - * - * This demo provides an example guitar tone consisting of some slap-back delay, - * followed by a reverb and a low-pass cabinet filter. - * - */ -#include -#include -#include -#include "BALibrary.h" - -using namespace BALibrary; - -BAAudioControlWM8731 codecControl; - -AudioInputI2S i2sIn; -AudioOutputI2S i2sOut; - -AudioMixer4 gainModule; // This will be used simply to reduce the gain before the reverb -AudioEffectDelay delayModule; // we'll add a little slapback echo -AudioEffectReverb reverb; // Add a bit of 'verb to our tone -AudioMixer4 mixer; // Used to mix the original dry with the wet (effects) path. -AudioFilterBiquad cabFilter; // We'll want something to cut out the highs and smooth the tone, just like a guitar cab. - - -// Audio Connections -AudioConnection patchIn(i2sIn,0, delayModule, 0); // route the input to the delay - -AudioConnection patch2(delayModule,0, gainModule, 0); // send the delay to the gain module -AudioConnection patch2b(gainModule, 0, reverb, 0); // then to the reverb - - -AudioConnection patch1(i2sIn,0, mixer,0); // mixer input 0 is our original dry signal -AudioConnection patch3(reverb, 0, mixer, 1); // mixer input 1 is our wet - -AudioConnection patch4(mixer, 0, cabFilter, 0); // mixer outpt to the cabinet filter - - -AudioConnection patch5(cabFilter, 0, i2sOut, 0); // connect the cab filter to the output. -AudioConnection patch5b(cabFilter, 0, i2sOut, 1); // connect the cab filter to the output. - -void setup() { - - delay(5); // wait a few ms to make sure the GTA Pro is fully powered up - AudioMemory(48); - - // If the codec was already powered up (due to reboot) power itd own first - codecControl.disable(); - delay(100); - codecControl.enable(); - delay(100); - - // Configure our effects - delayModule.delay(0, 50.0f); // 50 ms slapback delay - gainModule.gain(0, 0.25); // the reverb unit clips easily if the input is too high - mixer.gain(0, 1.0f); // unity gain on the dry - mixer.gain(1, 1.0f); // unity gain on the wet - - // Setup 2-stages of LPF, cutoff 4500 Hz, Q-factor 0.7071 (a 'normal' Q-factor) - cabFilter.setLowpass(0, 4500, .7071); - cabFilter.setLowpass(1, 4500, .7071); - - -} - -void loop() { - - // The audio flows automatically through the Teensy Audio Library - -} - diff --git a/examples/Modulation/TemoloDemo/TemoloDemo.ino b/examples/Modulation/TemoloDemo/TemoloDemo.ino index 014ecc2..0188002 100644 --- a/examples/Modulation/TemoloDemo/TemoloDemo.ino +++ b/examples/Modulation/TemoloDemo/TemoloDemo.ino @@ -31,22 +31,33 @@ BAAudioControlWM8731 codec; // YOU MUST USE TEENSYDUINO 1.41 or greater // YOU MUST COMPILE THIS DEMO USING Serial + Midi +//#define USE_CAB_FILTER // uncomment this line to add a simple low-pass filter to simulate a cabinet if you are going straight to headphones #define MIDI_DEBUG // uncomment to see raw MIDI info in terminal AudioEffectTremolo tremolo; +#if defined(USE_CAB_FILTER) AudioFilterBiquad cabFilter; // We'll want something to cut out the highs and smooth the tone, just like a guitar cab. +#endif -// Simply connect the input to the tremolo, and the output -// to both i2s channels AudioConnection input(i2sIn,0, tremolo,0); -AudioConnection tremoloOut(tremolo, 0, cabFilter, 0); +#if defined(USE_CAB_FILTER) +AudioConnection tremOut(tremolo, 0, cabFilter, 0); AudioConnection leftOut(cabFilter,0, i2sOut, 0); AudioConnection rightOut(cabFilter,0, i2sOut, 1); +#else +AudioConnection leftOut(tremolo,0, i2sOut, 0); +AudioConnection rightOut(tremolo,0, i2sOut, 1); +#endif -int loopCount = 0; +elapsedMillis timer; void setup() { + + TGA_PRO_MKII_REV1(); // Declare the version of the TGA Pro you are using. + //TGA_PRO_REVB(x); + //TGA_PRO_REVA(x); + delay(100); Serial.begin(57600); // Start the serial port @@ -78,9 +89,11 @@ void setup() { tremolo.bypass(false); tremolo.depth(0.5f); // 50% depth modulation - // Setup 2-stages of LPF, cutoff 4500 Hz, Q-factor 0.7071 (a 'normal' Q-factor) +#if defined(USE_CAB_FILTER) + // Guitar cabinet: Setup 2-stages of LPF, cutoff 4500 Hz, Q-factor 0.7071 (a 'normal' Q-factor) cabFilter.setLowpass(0, 4500, .7071); cabFilter.setLowpass(1, 4500, .7071); +#endif } void OnControlChange(byte channel, byte control, byte value) { @@ -101,13 +114,13 @@ void loop() { // each MIDI messages arrives, it return true. The message must // be fully processed before usbMIDI.read() is called again. - if (loopCount % 524288 == 0) { + if (timer > 1000) { + timer = 0; Serial.print("Processor Usage, Total: "); Serial.print(AudioProcessorUsage()); Serial.print("% "); Serial.print(" tremolo: "); Serial.print(tremolo.processorUsage()); Serial.println("%"); } - loopCount++; // check for new MIDI from USB if (usbMIDI.read()) { diff --git a/examples/Modulation/TremoloDemoExpansion/TremoloDemoExpansion.ino b/examples/Modulation/TremoloDemoExpansion/TremoloDemoExpansion.ino index fbbcc14..3dcba7e 100644 --- a/examples/Modulation/TremoloDemoExpansion/TremoloDemoExpansion.ino +++ b/examples/Modulation/TremoloDemoExpansion/TremoloDemoExpansion.ino @@ -8,11 +8,12 @@ * This example demonstrates teh BAAudioEffectsTremolo effect. It can * be controlled using the Blackaddr Audio "Expansion Control Board". * - * POT1 (left) controls amount of delay - * POT2 (right) controls amount of feedback - * POT3 (center) controls the wet/dry mix + * POT1 (left) controls the tremolo RATE + * POT2 (right) controls the tremolo DEPTH + * POT3 (center) controls the output VOLUME * SW1 will enable/bypass the audio effect. LED1 will be on when effect is enabled. - * SW2 will cycle through the 3 pre-programmed analog filters. LED2 will be on when SW2 is pressed. + * SW2 will cycle through the 3 pre-programmed waveforms. NOTE: any waveform other than Sine will cause + * pops/clicks since the waveforms are not bandlimited. * * * Using the Serial Montitor, send 'u' and 'd' characters to increase or decrease @@ -25,20 +26,27 @@ using namespace BAEffects; using namespace BALibrary; +//#define USE_CAB_FILTER // uncomment this line to add a simple low-pass filter to simulate a cabinet if you are going straight to headphones + AudioInputI2S i2sIn; AudioOutputI2S i2sOut; BAAudioControlWM8731 codec; AudioEffectTremolo tremolo; +#if defined(USE_CAB_FILTER) AudioFilterBiquad cabFilter; // We'll want something to cut out the highs and smooth the tone, just like a guitar cab. +#endif -// Simply connect the input to the delay, and the output -// to both i2s channels AudioConnection input(i2sIn,0, tremolo,0); -AudioConnection delayOut(tremolo, 0, cabFilter, 0); +#if defined(USE_CAB_FILTER) +AudioConnection tremOut(tremolo, 0, cabFilter, 0); AudioConnection leftOut(cabFilter,0, i2sOut, 0); AudioConnection rightOut(cabFilter,0, i2sOut, 1); +#else +AudioConnection leftOut(tremolo,0, i2sOut, 0); +AudioConnection rightOut(tremolo,0, i2sOut, 1); +#endif ////////////////////////////////////////// @@ -61,7 +69,8 @@ constexpr bool potSwapDirection = true; // Blackaddr Audio Expansion Board. BAPhysicalControls controls(BA_EXPAND_NUM_SW, BA_EXPAND_NUM_POT, BA_EXPAND_NUM_ENC, BA_EXPAND_NUM_LED); -int loopCount = 0; +elapsedMillis timer; + unsigned waveformIndex = 0; // variable for storing which analog filter we're currently using. constexpr unsigned MAX_HEADPHONE_VOL = 10; unsigned headphoneVolume = 8; // control headphone volume from 0 to 10. @@ -70,12 +79,14 @@ unsigned headphoneVolume = 8; // control headphone volume from 0 to 10. int bypassHandle, waveformHandle, rateHandle, depthHandle, volumeHandle, led1Handle, led2Handle; // Handles for the various controls void setup() { + TGA_PRO_MKII_REV1(); // Declare the version of the TGA Pro you are using. + //TGA_PRO_REVB(x); + //TGA_PRO_REVA(x); + delay(100); // wait a bit for serial to be available Serial.begin(57600); // Start the serial port delay(100); - TGA_PRO_EXPAND_REV2(); // Configure the expansion board revision - // Setup the controls. The return value is the handle to use when checking for control changes, etc. // pushbuttons bypassHandle = controls.addSwitch(BA_EXPAND_SW1_PIN); // will be used for bypass control @@ -104,6 +115,7 @@ void setup() { // Set some default values. // These can be changed using the controls on the Blackaddr Audio Expansion Board tremolo.bypass(false); + controls.setOutput(led1Handle, !tremolo.isBypass()); // Set the LED when NOT bypassed tremolo.rate(0.0f); tremolo.depth(1.0f); @@ -112,9 +124,11 @@ void setup() { // These are commented out, in this example we'll use SW2 to cycle through the different filters //tremolo.setWaveform(Waveform::SINE); // The default waveform +#if defined(USE_CAB_FILTER) // Guitar cabinet: Setup 2-stages of LPF, cutoff 4500 Hz, Q-factor 0.7071 (a 'normal' Q-factor) cabFilter.setLowpass(0, 4500, .7071); cabFilter.setLowpass(1, 4500, .7071); +#endif } void loop() { @@ -178,15 +192,14 @@ void loop() { } } - // Use the loopCounter to roughly measure human timescales. Every few seconds, print the CPU usage - // to the serial port. About 500,000 loops! - //if (loopCount % 524288 == 0) { - if (loopCount % 25000 == 0) { + delay(20); // Without some minimal delay here it will be difficult for the pots/switch changes to be detected. + + if (timer > 1000) { + timer = 0; Serial.print("Processor Usage, Total: "); Serial.print(AudioProcessorUsage()); Serial.print("% "); Serial.print(" tremolo: "); Serial.print(tremolo.processorUsage()); Serial.println("%"); } - loopCount++; } diff --git a/examples/Tests/MeasureNoise/MeasureNoise.ino b/examples/Tests/MeasureNoise/MeasureNoise.ino index b222ba0..d665d88 100644 --- a/examples/Tests/MeasureNoise/MeasureNoise.ino +++ b/examples/Tests/MeasureNoise/MeasureNoise.ino @@ -15,6 +15,8 @@ * be useful for frequency detection but is not appropriate for when sound quality is desired as * the modulation of the filter will result in audible artifacts. * + * ALLOW THE TEST TO RUN THROUGH SEVERAL CYCLE of toggling the HPF so the CODEC can calibrate correctly. + * */ #include #include @@ -39,6 +41,9 @@ AudioConnection patchOutL(rmsModule, 0, i2sOut, 0); // connect the cab filt AudioConnection patchOutR(rmsModule, 0, i2sOut, 1); // connect the cab filter to the output. void setup() { + TGA_PRO_MKII_REV1(); // Declare the version of the TGA Pro you are using. + //TGA_PRO_REVB(x); + //TGA_PRO_REVA(x); delay(5); // wait a few ms to make sure the GTA Pro is fully powered up AudioMemory(48); diff --git a/examples/Tests/TGA_PRO_MEM2_EXP/PhysicalControls.cpp b/examples/Tests/TGA_PRO_MEM2_EXP/PhysicalControls.cpp deleted file mode 100644 index 913587a..0000000 --- a/examples/Tests/TGA_PRO_MEM2_EXP/PhysicalControls.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "BALibrary.h" -using namespace BALibrary; - -constexpr int potCalibMin = 8; -constexpr int potCalibMax = 1016; -constexpr bool potSwapDirection = true; -int pot1Handle, pot2Handle, pot3Handle, sw1Handle, sw2Handle, led1Handle, led2Handle; -bool mute = false; -BAAudioControlWM8731 *codecPtr = nullptr; -BAPhysicalControls *controlPtr = nullptr; - -void configPhysicalControls(BAPhysicalControls &controls, BAAudioControlWM8731 &codec) -{ - // Setup the controls. The return value is the handle to use when checking for control changes, etc. - - // pushbuttons - sw1Handle = controls.addSwitch(BA_EXPAND_SW1_PIN); - sw2Handle = controls.addSwitch(BA_EXPAND_SW2_PIN); - // pots - pot1Handle = controls.addPot(BA_EXPAND_POT1_PIN, potCalibMin, potCalibMax, potSwapDirection); - pot2Handle = controls.addPot(BA_EXPAND_POT2_PIN, potCalibMin, potCalibMax, potSwapDirection); - pot3Handle = controls.addPot(BA_EXPAND_POT3_PIN, potCalibMin, potCalibMax, potSwapDirection); - // leds - led1Handle = controls.addOutput(BA_EXPAND_LED1_PIN); - led2Handle = controls.addOutput(BA_EXPAND_LED2_PIN); // will illuminate when pressing SW2 - - controlPtr = &controls; - codecPtr = &codec; -} - -void checkPot(unsigned id) -{ - float potValue; - unsigned handle; - switch(id) { - case 0 : - handle = pot1Handle; - break; - case 1 : - handle = pot2Handle; - break; - case 2 : - handle = pot3Handle; - break; - default : - handle = pot1Handle; - } - - if (controlPtr->checkPotValue(handle, potValue)) { - // Pot has changed - codecPtr->setHeadphoneVolume(potValue); - Serial.println(String("POT") + id + String(" value: ") + potValue); - } -} - -void checkSwitch(unsigned id) -{ - unsigned swHandle; - unsigned ledHandle; - switch(id) { - case 0 : - swHandle = sw1Handle; - ledHandle = led1Handle; - break; - case 1 : - swHandle = sw2Handle; - ledHandle = led2Handle; - break; - default : - swHandle = sw1Handle; - ledHandle = led1Handle; - } - - if (controlPtr->isSwitchToggled(swHandle)) { - Serial.println(String("Button ") + id + String(" pressed")); - } - - bool pressed = controlPtr->isSwitchHeld(swHandle); - controlPtr->setOutput(ledHandle, pressed); -} diff --git a/examples/Tests/TGA_PRO_MEM2_EXP/TGA_PRO_MEM2_EXP.ino b/examples/Tests/TGA_PRO_MEM2_EXP/TGA_PRO_MEM2_EXP.ino deleted file mode 100644 index e2115d8..0000000 --- a/examples/Tests/TGA_PRO_MEM2_EXP/TGA_PRO_MEM2_EXP.ino +++ /dev/null @@ -1,140 +0,0 @@ -/************************************************************************* - * This demo is used for manufacturing testing on the TGA Pro Expansion - * Control Board. - * - * This will test the following on the TGA Pro: - * - * - Audio INPUT and OUTPUT JACKS - * - Midi INPUT and Midi OUTPUT jacks - * - MEM0 (if installed) - * - MEM1 (if installed) - * - User LED - * - * This will also test the Expansion Control Board (if installed): - * - * - three POT knobs - * - two pushbutton SWitches - * - two LEDs - * - headphone output - * - * SETUP INSTRUCTIONS: - * - * 1) Connect an audio source to AUDIO INPUT. - * 2) Connect AUDIO OUTPUT to amp, stereo, headphone amplifier, etc. - * 3) if testing the MIDI ports, connect a MIDI cable between MIDI INPUT and MIDI OUTPUT - * 4) comment out any tests you want to skip - * 5) Compile and run the demo on your Teensy with TGA Pro. - * 6) Launch the Arduino Serial Monitor to see results. - * - * TESTING INSTRUCTIONS: - * - * 1) Check the Serial Monitor for the results of the MIDI testing, and external memory testing. - * 2) Confirm that the audio sent to the INPUT is coming out the OUTPUT. - * 3) Confirm the User LED is blinking every 1 or 2 seconds - * - * If using the Expansion Control Board: - * - * 1) Try pushing the pushbuttons. When pushed, they should turn on their corresponding LED. - * 2) Try turn each of the knobs one at a time. They should adjust the volume. - * - * The latest copy of the BA Guitar library can be obtained from - * https://github.com/Blackaddr/BALibrary - * - */ - -#define RUN_MIDI_TEST // Uncomment this line to run the MIDI test. -#define RUN_MEMO_TEST // Uncomment this line to run the MEM0 test. -//#define RUN_MEM1_TEST // (Teensy 3.5/3/6 only!) Uncomment this line to run the MEM1 test. -#define RUN_EXP_TEST // Test the Expansion board controls - -#include -#include "BALibrary.h" - -using namespace BALibrary; - -AudioInputI2S i2sIn; -AudioOutputI2S i2sOut; - -// Audio Thru Connection -AudioConnection patch0(i2sIn,0, i2sOut, 0); -AudioConnection patch1(i2sIn,1, i2sOut, 1); - -BAAudioControlWM8731 codec; -BAGpio gpio; // access to User LED - -#if defined(RUN_MEMO_TEST) -BASpiMemoryDMA spiMem0(SpiDeviceId::SPI_DEVICE0); -#endif - -#if defined(RUN_MEM1_TEST) && !defined(__IMXRT1062__) // SPI1 not supported on T4.0 -BASpiMemoryDMA spiMem1(SpiDeviceId::SPI_DEVICE1); -#endif - -// Create a control object using the number of switches, pots, encoders and outputs on the -// Blackaddr Audio Expansion Board. -BAPhysicalControls controls(BA_EXPAND_NUM_SW, BA_EXPAND_NUM_POT, BA_EXPAND_NUM_ENC, BA_EXPAND_NUM_LED); - -void configPhysicalControls(BAPhysicalControls &controls, BAAudioControlWM8731 &codec); -void checkPot(unsigned id); -void checkSwitch(unsigned id); -bool spiTest(BASpiMemory *mem, int id); // returns true if passed -bool uartTest(); // returns true if passed - -unsigned loopCounter = 0; - -void setup() { - Serial.begin(57600); - //while (!Serial) { yield(); } - delay(500); - - // Disable the audio codec first - codec.disable(); - delay(100); - AudioMemory(128); - codec.enable(); - codec.setHeadphoneVolume(0.8f); // Set headphone volume - configPhysicalControls(controls, codec); - - TGA_PRO_MKII_REV1(); - TGA_PRO_EXPAND_REV3(); // Macro to declare expansion board revision - - // Run the initial Midi connectivity and SPI memory tests. -#if defined(RUN_MIDI_TEST) - if (uartTest()) { Serial.println("MIDI Ports testing PASSED!"); } -#endif - -#if defined(RUN_MEMO_TEST) - //SPI_MEM0_1M(); - SPI_MEM0_4M(); - spiMem0.begin(); delay(10); - if (spiTest(&spiMem0, 0)) { Serial.println("SPI0 testing PASSED!");} -#endif - -#if defined(RUN_MEM1_TEST) && !defined(__IMXRT1062__) - SPI_MEM1_1M(); - //SPI_MEM1_4M(); - spiMem1.begin(); delay(10); - if (spiTest(&spiMem1, 1)) { Serial.println("SPI1 testing PASSED!");} -#endif - -#if defined(RUN_EXP_TEST) - Serial.println("Now monitoring for input from Expansion Control Board"); - #endif -} - -void loop() { - - #if defined(RUN_EXP_TEST) - checkPot(0); - checkPot(1); - checkPot(2); - checkSwitch(0); - checkSwitch(1); - #endif - - delay(20); - loopCounter++; - if ((loopCounter % 100) == 0) { - gpio.toggleLed(); - } -} diff --git a/examples/Tests/TGA_PRO_MEM2_EXP/UartTest.cpp b/examples/Tests/TGA_PRO_MEM2_EXP/UartTest.cpp deleted file mode 100644 index 3ae3953..0000000 --- a/examples/Tests/TGA_PRO_MEM2_EXP/UartTest.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "BAHardware.h" -#include "BASpiMemory.h" - -using namespace BALibrary; - -constexpr unsigned MIDI_RATE = 31250; -constexpr unsigned HIGH_RATE = 230400; -constexpr unsigned TEST_TIME = 5; // 5 second test each - -static unsigned baudRate = MIDI_RATE; // start with low speed -static uint8_t writeData = 0; -static unsigned loopCounter = 0; -static unsigned errorCount = 0; -static bool testFailed = false; -static bool testDone = false; -static unsigned testPhase = 0; // 0 for MIDI speed, 1 for high speed. - -bool uartTest(void) -{ - Serial1.begin(baudRate, SERIAL_8N1); - delay(100); - while(!Serial) {} - Serial.println(String("\nRunning MIDI Port speed test at ") + baudRate); - - // write the first data - Serial1.write(writeData); - - while(!testFailed && !testDone) { - - if (loopCounter >= (baudRate/4)) { // the divisor determines how long the test runs for - // next test - switch (testPhase) { - case 0 : - baudRate = HIGH_RATE; - break; - case 1 : - testDone = true; - } - - if (errorCount == 0) { Serial.println("TEST PASSED!"); } - else { - Serial.println("MIDI PORT TEST FAILED!"); - } - errorCount = 0; - testPhase++; - loopCounter = 0; - - if (!testDone) { - Serial.println(String("\nRunning MIDI Port speed test at ") + baudRate); - Serial1.begin(baudRate, SERIAL_8N1); - while (!Serial1) {} // wait for serial to be ready - } else { - Serial.println("MIDI PORT TEST DONE!\n"); - } - } - - // Wait for read data - if (Serial1.available()) { - uint8_t readData= Serial1.read(); - if (readData != writeData) { - Serial.println(String("MIDI ERROR: readData = ") + readData + String(" writeData = ") + writeData); - errorCount++; - } - - if ((loopCounter % (baudRate/64)) == 0) { // the divisor determines how often the period is printed - Serial.print("."); Serial.flush(); - } - - if (errorCount > 16) { - Serial.println("Halting test"); - testFailed = true; - } - - loopCounter++; - writeData++; - Serial1.write(writeData); - } - } - - return testFailed; -} diff --git a/examples/Tests/TGA_PRO_MEM2_EXP/spiTest.cpp b/examples/Tests/TGA_PRO_MEM2_EXP/spiTest.cpp deleted file mode 100644 index cd6475d..0000000 --- a/examples/Tests/TGA_PRO_MEM2_EXP/spiTest.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include -#include -#include "BAHardware.h" -#include "BASpiMemory.h" - -constexpr int NUM_TESTS = 12; -constexpr int NUM_BLOCK_WORDS = 128; -constexpr int mask0 = 0x5555; -constexpr int mask1 = 0xaaaa; - -//#define SANITY_CHECK - -using namespace BALibrary; - -int SPI_MAX_ADDR = 0; - -int calcData(int spiAddress, int loopPhase, int maskPhase) -{ - int data; - - int phase = ((loopPhase << 1) + maskPhase) & 0x3; - switch(phase) - { - case 0 : - data = spiAddress ^ mask0; - break; - case 1: - data = spiAddress ^ mask1; - break; - case 2: - data = ~spiAddress ^ mask0; - break; - case 3: - data = ~spiAddress ^ mask1; - - } - return (data & 0xffff); -} - -bool spiTest(BASpiMemory *mem, int id) -{ - int spiAddress = 0; - int spiErrorCount = 0; - - int maskPhase = 0; - int loopPhase = 0; - uint16_t memBlock[NUM_BLOCK_WORDS]; - uint16_t goldData[NUM_BLOCK_WORDS]; - - SPI_MAX_ADDR = BAHardwareConfig.getSpiMemMaxAddr(0); // assume for this test both memories are the same size so use MEM0 - const size_t SPI_MEM_SIZE_BYTES = BAHardwareConfig.getSpiMemSizeBytes(id); - - Serial.println(String("Starting SPI MEM Test of ") + SPI_MEM_SIZE_BYTES + String(" bytes")); - - for (int cnt = 0; cnt < NUM_TESTS; cnt++) { - - // Zero check - mem->zero16(0, SPI_MEM_SIZE_BYTES / sizeof(uint16_t)); - while (mem->isWriteBusy()) {} - - for (spiAddress = 0; spiAddress <= SPI_MAX_ADDR; spiAddress += NUM_BLOCK_WORDS*sizeof(uint16_t)) { - mem->read16(spiAddress, memBlock, NUM_BLOCK_WORDS); - while (mem->isReadBusy()) {} - for (int i=0; i= 10) break; - } - } - if (spiErrorCount >= 10) break; - } - - //if (spiErrorCount == 0) { Serial.println(String("SPI MEMORY(") + cnt + String("): Zero test PASSED!")); } - if (spiErrorCount == 0) { Serial.print("."); Serial.flush(); } - if (spiErrorCount > 0) { Serial.println(String("SPI MEMORY(") + cnt + String("): Zero test FAILED, error count = ") + spiErrorCount); return false;} - - - // Write all test data to the memory - maskPhase = 0; - for (spiAddress = 0; spiAddress <= SPI_MAX_ADDR; spiAddress += NUM_BLOCK_WORDS*sizeof(uint16_t)) { - // Calculate the data for a block - for (int i=0; iwrite16(spiAddress, memBlock, NUM_BLOCK_WORDS); - while (mem->isWriteBusy()) {} - } - - // Read back the test data - spiErrorCount = 0; - spiAddress = 0; - maskPhase = 0; - - for (spiAddress = 0; spiAddress <= SPI_MAX_ADDR; spiAddress += NUM_BLOCK_WORDS*sizeof(uint16_t)) { - - mem->read16(spiAddress, memBlock, NUM_BLOCK_WORDS); - // Calculate the golden data for a block - for (int i=0; iisReadBusy()) {} // wait for the read to finish - - for (int i=0; i= 10) break; - } - - //if (spiErrorCount == 0) { Serial.println(String("SPI MEMORY(") + cnt + String("): Data test PASSED!")); } - if (spiErrorCount == 0) { Serial.print("."); Serial.flush(); } - if (spiErrorCount > 0) { Serial.println(String("SPI MEMORY(") + cnt + String("): Data test FAILED, error count = ") + spiErrorCount); return false;} - - loopPhase = (loopPhase+1) % 2; - } - return true; -} diff --git a/src/effects/AudioEffectAnalogDelay.cpp b/src/effects/AudioEffectAnalogDelay.cpp index b9ef77a..914c705 100644 --- a/src/effects/AudioEffectAnalogDelay.cpp +++ b/src/effects/AudioEffectAnalogDelay.cpp @@ -36,7 +36,9 @@ AudioEffectAnalogDelay::AudioEffectAnalogDelay(ExtMemSlot *slot) : AudioStream(1, m_inputQueueArray) { m_memory = new AudioDelay(slot); - m_maxDelaySamples = (slot->size() / sizeof(int16_t)); + + // the delay cannot be exactly equal to the slot size, you need at least one sample so the wr/rd are not on top of each other. + m_maxDelaySamples = (slot->size() / sizeof(int16_t))-AUDIO_BLOCK_SAMPLES; m_externalMemory = true; m_constructFilter(); } @@ -164,21 +166,17 @@ void AudioEffectAnalogDelay::delay(float milliseconds) { size_t delaySamples = calcAudioSamples(milliseconds); - if (delaySamples > m_memory->getMaxDelaySamples()) { - // this exceeds max delay value, limit it. - delaySamples = m_memory->getMaxDelaySamples(); - } - - if (!m_memory) { Serial.println("delay(): m_memory is not valid"); } + if (!m_memory) { Serial.println("delay(): m_memory is not valid"); return; } if (!m_externalMemory) { // internal memory + m_maxDelaySamples = m_memory->getMaxDelaySamples(); //QueuePosition queuePosition = calcQueuePosition(milliseconds); //Serial.println(String("CONFIG: delay:") + delaySamples + String(" queue position ") + queuePosition.index + String(":") + queuePosition.offset); } else { // external memory - //Serial.println(String("CONFIG: delay:") + delaySamples); ExtMemSlot *slot = m_memory->getSlot(); + m_maxDelaySamples = (slot->size() / sizeof(int16_t))-AUDIO_BLOCK_SAMPLES; if (!slot) { Serial.println("ERROR: slot ptr is not valid"); } if (!slot->isEnabled()) { @@ -187,6 +185,10 @@ void AudioEffectAnalogDelay::delay(float milliseconds) } } + if (delaySamples > m_maxDelaySamples) { + // this exceeds max delay value, limit it. + delaySamples = m_maxDelaySamples; + } m_delaySamples = delaySamples; } @@ -196,43 +198,52 @@ void AudioEffectAnalogDelay::delay(size_t delaySamples) if (!m_externalMemory) { // internal memory + m_maxDelaySamples = m_memory->getMaxDelaySamples(); //QueuePosition queuePosition = calcQueuePosition(delaySamples); //Serial.println(String("CONFIG: delay:") + delaySamples + String(" queue position ") + queuePosition.index + String(":") + queuePosition.offset); } else { // external memory //Serial.println(String("CONFIG: delay:") + delaySamples); ExtMemSlot *slot = m_memory->getSlot(); + m_maxDelaySamples = (slot->size() / sizeof(int16_t))-AUDIO_BLOCK_SAMPLES; if (!slot->isEnabled()) { slot->enable(); } } - m_delaySamples = delaySamples; + + if (delaySamples > m_maxDelaySamples) { + // this exceeds max delay value, limit it. + delaySamples = m_maxDelaySamples; + } + m_delaySamples = delaySamples; } void AudioEffectAnalogDelay::delayFractionMax(float delayFraction) { size_t delaySamples = static_cast(static_cast(m_memory->getMaxDelaySamples()) * delayFraction); - if (delaySamples > m_memory->getMaxDelaySamples()) { - // this exceeds max delay value, limit it. - delaySamples = m_memory->getMaxDelaySamples(); - } - if (!m_memory) { Serial.println("delay(): m_memory is not valid"); } if (!m_externalMemory) { // internal memory + m_maxDelaySamples = m_memory->getMaxDelaySamples(); //QueuePosition queuePosition = calcQueuePosition(delaySamples); //Serial.println(String("CONFIG: delay:") + delaySamples + String(" queue position ") + queuePosition.index + String(":") + queuePosition.offset); } else { // external memory //Serial.println(String("CONFIG: delay:") + delaySamples); ExtMemSlot *slot = m_memory->getSlot(); + m_maxDelaySamples = (slot->size() / sizeof(int16_t))-AUDIO_BLOCK_SAMPLES; if (!slot->isEnabled()) { slot->enable(); } } - m_delaySamples = delaySamples; + + if (delaySamples > m_maxDelaySamples) { + // this exceeds max delay value, limit it. + delaySamples = m_maxDelaySamples; + } + m_delaySamples = delaySamples; } void AudioEffectAnalogDelay::m_preProcessing(audio_block_t *out, audio_block_t *dry, audio_block_t *wet) @@ -270,8 +281,8 @@ void AudioEffectAnalogDelay::processMidi(int channel, int control, int value) if ((m_midiConfig[DELAY][MIDI_CHANNEL] == channel) && (m_midiConfig[DELAY][MIDI_CONTROL] == control)) { // Delay - if (m_externalMemory) { m_maxDelaySamples = m_memory->getSlot()->size() / sizeof(int16_t); } - size_t delayVal = (size_t)(val * (float)m_maxDelaySamples); + if (m_externalMemory) { m_maxDelaySamples = (m_memory->getSlot()->size() / sizeof(int16_t))-AUDIO_BLOCK_SAMPLES; } + size_t delayVal = (size_t)(val * (float)(m_maxDelaySamples)); delay(delayVal); Serial.println(String("AudioEffectAnalogDelay::delay (ms): ") + calcAudioTimeMs(delayVal) + String(" (samples): ") + delayVal + String(" out of ") + m_maxDelaySamples);