From 492659ddb2da5cd41d85fbdf2e0fc9b57bc83b91 Mon Sep 17 00:00:00 2001 From: Steve Lascos Date: Thu, 13 Sep 2018 20:29:25 -0400 Subject: [PATCH] Major cleanup of the Library and reorganization of the examples --- .../BA0_TGA_Pro_TRY_FIRST.ino | 124 ----------------- .../BA1_TGA_Pro_demo/SerialMonitorResults.txt | 51 ------- .../BAExpansionCalibrate.ino | 19 ++- .../BA1_TGA_Pro_NOMEM_demo.ino} | 69 ---------- .../BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino | 2 - .../BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino | 3 - .../BA4_TGA_Pro_delay_reverb.ino | 1 - .../Delay/AnalogDelayDemo/AnalogDelayDemo.ino | 29 ++-- .../AnalogDelayDemoExpansion.ino | 26 +++- .../ExternalDelayDemo/ExternalDelayDemo.ino} | 9 +- .../SoundOnSoundDemo/SoundOnSoundDemo.ino | 10 +- .../SoundOnSoundExpansionDemo.ino | 7 + examples/README.TXT | 6 + .../Tests/TGA_PRO_MEM2/PhysicalControls.cpp | 79 ----------- examples/Tests/TGA_PRO_MEM2/TGA_PRO_MEM2.ino | 71 ---------- examples/Tests/TGA_PRO_MEM2/UartTest.cpp | 86 ------------ examples/Tests/TGA_PRO_MEM2/spiTest.cpp | 125 ------------------ .../TGA_PRO_MEM2_EXP/TGA_PRO_MEM2_EXP.ino | 75 +++++++++-- examples/Tests/TGA_PRO_MEM2_EXP/UartTest.cpp | 10 +- src/BAEffects.h | 29 ++++ src/BALibrary.h | 5 +- 21 files changed, 183 insertions(+), 653 deletions(-) delete mode 100644 examples/BA0_TGA_Pro_TRY_FIRST/BA0_TGA_Pro_TRY_FIRST.ino delete mode 100644 examples/BA1_TGA_Pro_demo/SerialMonitorResults.txt rename examples/{BA1_TGA_Pro_demo/BA1_TGA_Pro_demo.ino => Basic/BA1_TGA_Pro_NOMEM_demo/BA1_TGA_Pro_NOMEM_demo.ino} (61%) rename examples/{ => Basic}/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino (99%) rename examples/{ => Basic}/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino (99%) rename examples/{ => Basic}/BA4_TGA_Pro_delay_reverb/BA4_TGA_Pro_delay_reverb.ino (98%) rename examples/{BA5_TGA_Pro_ExternalDelay_demo/BA5_TGA_Pro_ExternalDelay_demo.ino => Delay/ExternalDelayDemo/ExternalDelayDemo.ino} (97%) create mode 100644 examples/README.TXT delete mode 100644 examples/Tests/TGA_PRO_MEM2/PhysicalControls.cpp delete mode 100644 examples/Tests/TGA_PRO_MEM2/TGA_PRO_MEM2.ino delete mode 100644 examples/Tests/TGA_PRO_MEM2/UartTest.cpp delete mode 100644 examples/Tests/TGA_PRO_MEM2/spiTest.cpp create mode 100644 src/BAEffects.h diff --git a/examples/BA0_TGA_Pro_TRY_FIRST/BA0_TGA_Pro_TRY_FIRST.ino b/examples/BA0_TGA_Pro_TRY_FIRST/BA0_TGA_Pro_TRY_FIRST.ino deleted file mode 100644 index 820f046..0000000 --- a/examples/BA0_TGA_Pro_TRY_FIRST/BA0_TGA_Pro_TRY_FIRST.ino +++ /dev/null @@ -1,124 +0,0 @@ -/************************************************************************* - * This demo uses only the built-in libraries provided with the Arudino - * Teensy libraries. - * - * IT IS STRONGLY RECOMMENDED to use the BALibrary Library located at - * https://github.com/Blackaddr/BALibrary - * The BALibrary library will made it easier to use the features of your - * GTA Pro board, as well and configure it correctly to eliminate - * unneccesary noise. - * - * The built-in support for the WM8731 codec in the Teensy Library is very - * limited. Without proper configuration, the codec will produce a noisy - * output. This is caused by the default configuration the WM8731 powers - * up in. This can easily be corrected by installing the BALibrary library - * - * For instructions on installing additional libraries follow the - * instructions at https://www.arduino.cc/en/Guide/Libraries after downloading - * the BALibrary repo from github as a zip file. - * - */ - -#include -#include -#include - -MIDI_CREATE_DEFAULT_INSTANCE(); -using namespace midi; - -AudioInputI2S i2sIn; -AudioOutputI2S i2sOut; - -// Audio connections, just connect the I2S input directly to the I2S output. -AudioConnection patch0(i2sIn,0, i2sOut, 0); -AudioConnection patch1(i2sIn,1, i2sOut, 1); - -AudioControlWM8731 codecControl; // needed to enable the codec - -unsigned long t=0; -const int usrLED = 16; // the location of the GTA Pro user LED (not the LED on the Teensy itself) -int usrLEDState = 0; - -void setup() { - - // Configure the user LED pin as output - pinMode(usrLED, OUTPUT); - digitalWrite(usrLED, usrLEDState); - - // Enable the MIDI to listen on all channels - MIDI.begin(MIDI_CHANNEL_OMNI); - Serial.begin(57600); // Enable the serial monitor - Wire.begin(); // Enable the I2C bus for controlling the codec - delay(5); - - delay(100); - codecControl.disable(); // Turn off the codec first (in case it was in an unknown state) - delay(100); - AudioMemory(24); - - Serial.println("Enabling codec...\n"); - codecControl.enable(); // Enable the codec - 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 no MIDI IN activity, print a message every 10 seconds - if (millis() - t > 10000) { - t += 10000; - Serial.println("(no MIDI activity, check cables)"); - } - - // Toggle the USR LED state - usrLEDState = ~usrLEDState; - digitalWrite(usrLED, usrLEDState); - -} - diff --git a/examples/BA1_TGA_Pro_demo/SerialMonitorResults.txt b/examples/BA1_TGA_Pro_demo/SerialMonitorResults.txt deleted file mode 100644 index dea1bd7..0000000 --- a/examples/BA1_TGA_Pro_demo/SerialMonitorResults.txt +++ /dev/null @@ -1,51 +0,0 @@ -SPI writing DONE! -SPI TEST PASSED!!! -SPI writing DONE! -SPI TEST PASSED!!! -SPI writing DONE! -SPI TEST PASSED!!! -MIDI IS WORKING!!! -Message, type=176, data = 32 10 -SPI writing DONE! -SPI TEST PASSED!!! -SPI writing DONE! -SPI TEST PASSED!!! -SPI writing DONE! -SPI TEST PASSED!!! -MIDI IS WORKING!!! -Note On: ch=2, note=10, velocity=100 -SPI writing DONE! -SPI TEST PASSED!!! -SPI writing DONE! -SPI TEST PASSED!!! -SPI writing DONE! -SPI TEST PASSED!!! -MIDI IS WORKING!!! -Message, type=176, data = 33 11 -SPI writing DONE! -SPI TEST PASSED!!! -SPI writing DONE! -SPI TEST PASSED!!! -SPI writing DONE! -SPI TEST PASSED!!! -MIDI IS WORKING!!! -Note On: ch=3, note=10, velocity=100 -SPI writing DONE! -SPI TEST PASSED!!! -SPI writing DONE! -SPI TEST PASSED!!! -SPI writing DONE! -SPI TEST PASSED!!! -MIDI IS WORKING!!! -Message, type=176, data = 34 12 -SPI writing DONE! -SPI TEST PASSED!!! -SPI writing DONE! -SPI TEST PASSED!!! -SPI writing DONE! -SPI TEST PASSED!!! -MIDI IS WORKING!!! -Note On: ch=4, note=10, velocity=100 -SPI writing DONE! -SPI TEST PASSED!!! - diff --git a/examples/BAExpansionCalibrate/BAExpansionCalibrate.ino b/examples/BAExpansionCalibrate/BAExpansionCalibrate.ino index aaed076..c438734 100644 --- a/examples/BAExpansionCalibrate/BAExpansionCalibrate.ino +++ b/examples/BAExpansionCalibrate/BAExpansionCalibrate.ino @@ -1,5 +1,20 @@ -#define TGA_PRO_REVB -#define TGA_PRO_EXPAND_REV2 +/************************************************************************* + * 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. + */ +#define TGA_PRO_REVB // Specify our hardware revision +#define TGA_PRO_EXPAND_REV2 // Specify we are using the EXPANSION CONTROL BOARD REV2 #include "BALibrary.h" diff --git a/examples/BA1_TGA_Pro_demo/BA1_TGA_Pro_demo.ino b/examples/Basic/BA1_TGA_Pro_NOMEM_demo/BA1_TGA_Pro_NOMEM_demo.ino similarity index 61% rename from examples/BA1_TGA_Pro_demo/BA1_TGA_Pro_demo.ino rename to examples/Basic/BA1_TGA_Pro_NOMEM_demo/BA1_TGA_Pro_NOMEM_demo.ino index 36b3506..8eb459f 100644 --- a/examples/BA1_TGA_Pro_demo/BA1_TGA_Pro_demo.ino +++ b/examples/Basic/BA1_TGA_Pro_NOMEM_demo/BA1_TGA_Pro_NOMEM_demo.ino @@ -18,11 +18,7 @@ MIDI_CREATE_DEFAULT_INSTANCE(); using namespace midi; - -//#define ENABLE_MEM_TEST // uncomment this line and 'Save As' to a new location to test the SPI memory - using namespace BALibrary; -using namespace BAEffects; AudioInputI2S i2sIn; AudioOutputI2S i2sOut; @@ -33,16 +29,9 @@ 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 -int spiAddress = 0; -int spiData = 0xff; -int spiErrorCount = 0; - - void setup() { MIDI.begin(MIDI_CHANNEL_OMNI); @@ -62,64 +51,6 @@ void setup() { void loop() { -#ifdef ENABLE_MEM_TEST - - ////////////////////////////////////////////////////////////////// - // Write test data to the SPI Memory - ////////////////////////////////////////////////////////////////// - for (spiAddress=0; spiAddress <= SPI_MAX_ADDR; spiAddress++) { - if ((spiAddress % 32768) == 0) { - //Serial.print("Writing to "); - //Serial.println(spiAddress, HEX); - } - - //mem0Write(spiAddress, spiData); - spiMem0.write(spiAddress, spiData); - spiData = (spiData-1) & 0xff; - } - Serial.println("SPI writing DONE!"); - - /////////////////////////////////////////////////////////////////// - // Read back from the SPI memory - /////////////////////////////////////////////////////////////////// - spiErrorCount = 0; - spiAddress = 0; - spiData = 0xff; - - for (spiAddress=0; spiAddress <= SPI_MAX_ADDR; spiAddress++) { - if ((spiAddress % 32768) == 0) { - //Serial.print("Reading "); - //Serial.print(spiAddress, HEX); - } - - //int data = mem0Read(spiAddress); - int data = spiMem0.read(spiAddress); - if (data != spiData) { - spiErrorCount++; - Serial.println(""); - Serial.print("ERROR MEM0: (expected) (actual):"); - Serial.print(spiData, HEX); Serial.print(":"); - Serial.println(data, HEX); - delay(100); - } - - if ((spiAddress % 32768) == 0) { - //Serial.print(", data = "); - //Serial.println(data, HEX); - } - - spiData = (spiData-1) & 0xff; - - // Break out of test once the error count reaches 10 - if (spiErrorCount > 10) { break; } - - } - - if (spiErrorCount == 0) { Serial.println("SPI TEST PASSED!!!"); } - -#endif - - /////////////////////////////////////////////////////////////////////// // MIDI TESTING // Connect a loopback cable between the MIDI IN and MIDI OUT on the diff --git a/examples/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino b/examples/Basic/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino similarity index 99% rename from examples/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino rename to examples/Basic/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino index fc1d1ef..44ceee4 100644 --- a/examples/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino +++ b/examples/Basic/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino @@ -14,7 +14,6 @@ * pins. * */ -//#include #include #include #include @@ -24,7 +23,6 @@ MIDI_CREATE_DEFAULT_INSTANCE(); using namespace midi; using namespace BALibrary; -using namespace BAEffects; AudioInputI2S i2sIn; AudioOutputI2S i2sOut; diff --git a/examples/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino b/examples/Basic/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino similarity index 99% rename from examples/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino rename to examples/Basic/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino index 9e38753..1887512 100644 --- a/examples/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino +++ b/examples/Basic/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino @@ -15,7 +15,6 @@ * pins. * */ -//#include #include #include #include @@ -23,8 +22,6 @@ MIDI_CREATE_DEFAULT_INSTANCE(); using namespace midi; - -using namespace BAEffects; using namespace BALibrary; AudioInputI2S i2sIn; diff --git a/examples/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 similarity index 98% rename from examples/BA4_TGA_Pro_delay_reverb/BA4_TGA_Pro_delay_reverb.ino rename to examples/Basic/BA4_TGA_Pro_delay_reverb/BA4_TGA_Pro_delay_reverb.ino index 00cf62f..e6ca5d2 100644 --- a/examples/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 @@ -14,7 +14,6 @@ #include #include "BALibrary.h" -using namespace BAEffects; using namespace BALibrary; BAAudioControlWM8731 codecControl; diff --git a/examples/Delay/AnalogDelayDemo/AnalogDelayDemo.ino b/examples/Delay/AnalogDelayDemo/AnalogDelayDemo.ino index d41781b..f68612e 100644 --- a/examples/Delay/AnalogDelayDemo/AnalogDelayDemo.ino +++ b/examples/Delay/AnalogDelayDemo/AnalogDelayDemo.ino @@ -1,5 +1,23 @@ -#include +/************************************************************************* + * 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 example demonstrates teh BAAudioEffectsAnalogDelay effect. It can + * be controlled using USB MIDI. You can get a free USB MIDI Controller + * appliation at + * http://www.blackaddr.com/downloads/BAMidiTester/ + * or the source code at + * https://github.com/Blackaddr/BAMidiTester + * + * Even if you don't control the guitar effect with USB MIDI, you must set + * the Arduino IDE USB-Type under Tools to "Serial + MIDI" + */ + #include #include "BALibrary.h" +#include "BAEffects.h" using namespace midi; using namespace BAEffects; @@ -14,7 +32,6 @@ BAAudioControlWM8731 codec; // YOU MUST COMPILE THIS DEMO USING Serial + Midi //#define USE_EXT // uncomment this line to use External MEM0 - #define MIDI_DEBUG // uncomment to see raw MIDI info in terminal #ifdef USE_EXT @@ -32,22 +49,18 @@ AudioEffectAnalogDelay analogDelay(&delaySlot); // by passing it the maximum amount of delay we will use in millseconds. Note that // audio delay lengths are very limited when using internal memory due to limited // internal RAM size. -AudioEffectAnalogDelay analogDelay(200.0f); // max delay of 200 ms. +AudioEffectAnalogDelay analogDelay(200.0f); // max delay of 200 ms or internal. +// If you use external SPI memory you can get up to 1485.0f ms of delay! #endif AudioFilterBiquad cabFilter; // We'll want something to cut out the highs and smooth the tone, just like a guitar cab. -// Record the audio to the PC -//AudioOutputUSB usb; - // Simply connect the input to the delay, and the output // to both i2s channels AudioConnection input(i2sIn,0, analogDelay,0); AudioConnection delayOut(analogDelay, 0, cabFilter, 0); AudioConnection leftOut(cabFilter,0, i2sOut, 0); AudioConnection rightOut(cabFilter,0, i2sOut, 1); -//AudioConnection leftOutUSB(cabFilter,0, usb, 0); -//AudioConnection rightOutUSB(cabFilter,0, usb, 1); int loopCount = 0; diff --git a/examples/Delay/AnalogDelayDemoExpansion/AnalogDelayDemoExpansion.ino b/examples/Delay/AnalogDelayDemoExpansion/AnalogDelayDemoExpansion.ino index 4b8f892..a0fd4ad 100644 --- a/examples/Delay/AnalogDelayDemoExpansion/AnalogDelayDemoExpansion.ino +++ b/examples/Delay/AnalogDelayDemoExpansion/AnalogDelayDemoExpansion.ino @@ -5,17 +5,28 @@ * The latest copy of the BA Guitar library can be obtained from * https://github.com/Blackaddr/BALibrary * - * This demo combines the Blackaddr Audio Expansion board to add physical controls - * to the BAAudioEffectAnalogDelay. + * This example demonstrates teh BAAudioEffectsAnalogDelay effect. It can + * be controlled using the Blackaddr Audio "Expansion Control Board". * - * You can control the amount of delay, feedback and mix in realtime, as well as cycle - * through the various analog filters built into the effect. + * POT1 (left) controls amount of delay + * POT2 (right) controls amount of feedback + * POT3 (center) controls the wet/dry mix + * 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. * + * !!! SET POTS TO REASONABLE VALUES BEFORE STARTING TO AVOID SCREECHING FEEDBACK!!!! + * - set POT1 (delay) fully counter-clockwise then increase it slowly. + * - set POT2 (feedback) fully counter-clockwise, then increase it slowly + * - set POT3 (wet/dry mix) to half-way at the detent. + * + * Using the Serial Montitor, send 'u' and 'd' characters to increase or decrease + * the headphone volume between values of 0 and 9. */ #define TGA_PRO_REVB // Set which hardware revision of the TGA Pro we're using #define TGA_PRO_EXPAND_REV2 // pull in the pin definitions for the Blackaddr Audio Expansion Board. #include "BALibrary.h" +#include "BAEffects.h" using namespace BAEffects; using namespace BALibrary; @@ -41,7 +52,8 @@ AudioEffectAnalogDelay analogDelay(&delaySlot); // by passing it the maximum amount of delay we will use in millseconds. Note that // audio delay lengths are very limited when using internal memory due to limited // internal RAM size. -AudioEffectAnalogDelay analogDelay(200.0f); // max delay of 200 ms. +AudioEffectAnalogDelay analogDelay(200.0f); // set the max delay of 200 ms. +// If you use external SPI memory you can get up to 1485.0f ms of delay! #endif AudioFilterBiquad cabFilter; // We'll want something to cut out the highs and smooth the tone, just like a guitar cab. @@ -77,7 +89,7 @@ BAPhysicalControls controls(BA_EXPAND_NUM_SW, BA_EXPAND_NUM_POT, BA_EXPAND_NUM_E int loopCount = 0; unsigned filterIndex = 0; // variable for storing which analog filter we're currently using. constexpr unsigned MAX_HEADPHONE_VOL = 10; -unsigned headphoneVolume = MAX_HEADPHONE_VOL; // control headphone volume from 0 to 10. +unsigned headphoneVolume = 8; // control headphone volume from 0 to 10. // BAPhysicalControls returns a handle when you register a new control. We'll uses these handles when working with the controls. int bypassHandle, filterHandle, delayHandle, feedbackHandle, mixHandle, led1Handle, led2Handle; // Handles for the various controls @@ -154,7 +166,7 @@ void loop() { } // Use SW2 to cycle through the filters - controls.setOutput(led2Handle, !controls.getSwitchValue(led2Handle)); + controls.setOutput(led2Handle, controls.getSwitchValue(led2Handle)); if (controls.isSwitchToggled(filterHandle)) { filterIndex = (filterIndex + 1) % 3; // update and potentionall roll the counter 0, 1, 2, 0, 1, 2, ... // cast the index between 0 to 2 to the enum class AudioEffectAnalogDelay::Filter diff --git a/examples/BA5_TGA_Pro_ExternalDelay_demo/BA5_TGA_Pro_ExternalDelay_demo.ino b/examples/Delay/ExternalDelayDemo/ExternalDelayDemo.ino similarity index 97% rename from examples/BA5_TGA_Pro_ExternalDelay_demo/BA5_TGA_Pro_ExternalDelay_demo.ino rename to examples/Delay/ExternalDelayDemo/ExternalDelayDemo.ino index e67658d..a6a4eac 100644 --- a/examples/BA5_TGA_Pro_ExternalDelay_demo/BA5_TGA_Pro_ExternalDelay_demo.ino +++ b/examples/Delay/ExternalDelayDemo/ExternalDelayDemo.ino @@ -11,8 +11,9 @@ * Eight delay taps are configured from a single SRAM device. * */ - +#include #include "BALibrary.h" +#include "BAEffects.h" using namespace BAEffects; using namespace BALibrary; @@ -50,13 +51,13 @@ void setup() { Serial.begin(57600); AudioMemory(128); - delay(3000); + delay(100); Serial.println(String("Starting...\n")); - delay(1000); + delay(100); Serial.println("Enabling codec...\n"); codecControl.enable(); - delay(1000); + delay(100); // Set up 8 delay taps, each with evenly spaced, longer delays longDelay.delay(0, 150.0f); diff --git a/examples/Delay/SoundOnSoundDemo/SoundOnSoundDemo.ino b/examples/Delay/SoundOnSoundDemo/SoundOnSoundDemo.ino index d23cb65..7209d07 100644 --- a/examples/Delay/SoundOnSoundDemo/SoundOnSoundDemo.ino +++ b/examples/Delay/SoundOnSoundDemo/SoundOnSoundDemo.ino @@ -5,10 +5,13 @@ * 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. + * THIS DEMO REQUIRES THE EXTERNAL SRAM MEM0 * - * It can optionally exercise the SPI MEM0 if installed on the TGA Pro board. + * This demo combines MIDI control with the BAAudioEffectSoundOnSound. You can use + * the BAMidiTester to control the effect but it's best to use external MIDI footswitch + * or the Blackaddr Audio Expansion Control Board. + * + * Use must set the Arduino IDE USB-Type to "Serial + MIDI" in the Tools menu. * */ #include @@ -16,6 +19,7 @@ #include #include #include "BALibrary.h" +#include "BAEffects.h" #include static const unsigned sUsbTransportBufferSize = 16; diff --git a/examples/Delay/SoundOnSoundExpansionDemo/SoundOnSoundExpansionDemo.ino b/examples/Delay/SoundOnSoundExpansionDemo/SoundOnSoundExpansionDemo.ino index cc04a54..fea6ec0 100644 --- a/examples/Delay/SoundOnSoundExpansionDemo/SoundOnSoundExpansionDemo.ino +++ b/examples/Delay/SoundOnSoundExpansionDemo/SoundOnSoundExpansionDemo.ino @@ -13,11 +13,18 @@ * * The pots control the feedback, as well as the gate opening and close times. * + * POT1 - Gate open time. Middle position (detent) is about 2100 ms. + * POT2 - gate close time. Middle position (detent) is about 2100 ms. + * POT3 - Effect volume. Controls the volume of the SOS effect separate from the normal volume + * SW1 - Strum and hold a chord then push this button. Continue holding the button until the LED1 light goes out. + * SW2 - Push this button to clear out the sound circulating in the delay. + * */ #define TGA_PRO_REVB // Set which hardware revision of the TGA Pro we're using #define TGA_PRO_EXPAND_REV2 // pull in the pin definitions for the Blackaddr Audio Expansion Board. #include "BALibrary.h" +#include "BAEffects.h" using namespace BAEffects; using namespace BALibrary; diff --git a/examples/README.TXT b/examples/README.TXT new file mode 100644 index 0000000..e3d5a70 --- /dev/null +++ b/examples/README.TXT @@ -0,0 +1,6 @@ +If you've never used the the library examples before, start with the "Basic" ones. + +Pick the correct one based on how many SPI SRAMs you have. (0, 1 or 2 SRAMs). + +Use BAExpansionCalibrate to test our the Blackaddr Audio Expanson Control Board if +you purchased one. diff --git a/examples/Tests/TGA_PRO_MEM2/PhysicalControls.cpp b/examples/Tests/TGA_PRO_MEM2/PhysicalControls.cpp deleted file mode 100644 index 3ed1e89..0000000 --- a/examples/Tests/TGA_PRO_MEM2/PhysicalControls.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#define TGA_PRO_EXPAND_REV2 - -#include "BALibrary.h" -using namespace BALibrary; - -constexpr int potCalibMin = 1; -constexpr int potCalibMax = 1018; -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); - } -} - -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; - } - - bool pressed = controlPtr->isSwitchHeld(swHandle); - controlPtr->setOutput(ledHandle, pressed); -} - - diff --git a/examples/Tests/TGA_PRO_MEM2/TGA_PRO_MEM2.ino b/examples/Tests/TGA_PRO_MEM2/TGA_PRO_MEM2.ino deleted file mode 100644 index 9b91d9c..0000000 --- a/examples/Tests/TGA_PRO_MEM2/TGA_PRO_MEM2.ino +++ /dev/null @@ -1,71 +0,0 @@ -/************************************************************************* - * This demo is used for manufacturing tests on the TGA Pro Expansion - * Control Board. Pushing the buttons turns on the LEDs. Adjusting - * any know will adjust the volume. - * - * The latest copy of the BA Guitar library can be obtained from - * https://github.com/Blackaddr/BALibrary - * - */ -#include -#include -#include - -#define TGA_PRO_EXPAND_REV2 -#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 - -BASpiMemoryDMA spiMem0(SpiDeviceId::SPI_DEVICE0); -BASpiMemoryDMA spiMem1(SpiDeviceId::SPI_DEVICE1); - -// 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(BASpiMemoryDMA *mem); // returns true if passed -bool uartTest(); // returns true if passed - -void setup() { - Serial.begin(57600); - - spiMem0.begin(); - spiMem1.begin(); - - // Disable the audio codec first - codec.disable(); - delay(100); - AudioMemory(128); - codec.enable(); - codec.setHeadphoneVolume(0.8f); // Set headphone volume - configPhysicalControls(controls, codec); - - // Run the initial Midi connectivity and SPI memory tests. - if (uartTest()) { Serial.println("MIDI Ports testing PASSED!"); } - if (spiTest(&spiMem0)) { Serial.println("SPI0 testing PASSED!");} - if (spiTest(&spiMem1)) { Serial.println("SPI1 testing PASSED!");} -} - -void loop() { - // put your main code here, to run repeatedly: - checkPot(0); - checkPot(1); - checkPot(2); - checkSwitch(0); - checkSwitch(1); - - delay(10); -} diff --git a/examples/Tests/TGA_PRO_MEM2/UartTest.cpp b/examples/Tests/TGA_PRO_MEM2/UartTest.cpp deleted file mode 100644 index 0fb866b..0000000 --- a/examples/Tests/TGA_PRO_MEM2/UartTest.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "BAHardware.h" -#include "BASpiMemory.h" - -using namespace BALibrary; - -constexpr unsigned LOW_RATE = 2400; -constexpr unsigned MIDI_RATE = 31250; -constexpr unsigned HIGH_RATE = 250000; -constexpr unsigned TEST_TIME = 5; // 5 second test each - -static unsigned baudRate = LOW_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 low speed, 1 for MIDI speed, 2 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 = MIDI_RATE; - break; - case 1 : - baudRate = HIGH_RATE; - break; - case 2 : - 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("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/spiTest.cpp b/examples/Tests/TGA_PRO_MEM2/spiTest.cpp deleted file mode 100644 index fce9b22..0000000 --- a/examples/Tests/TGA_PRO_MEM2/spiTest.cpp +++ /dev/null @@ -1,125 +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 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(BASpiMemoryDMA *mem) -{ - int spiAddress = 0; - int spiErrorCount = 0; - - int maskPhase = 0; - int loopPhase = 0; - uint16_t memBlock[NUM_BLOCK_WORDS]; - uint16_t goldData[NUM_BLOCK_WORDS]; - - Serial.println("Starting SPI MEM Test"); - - for (int cnt = 0; cnt < NUM_TESTS; cnt++) { - - // Zero check - mem->zero16(0, SPI_MEM0_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/examples/Tests/TGA_PRO_MEM2_EXP/TGA_PRO_MEM2_EXP.ino b/examples/Tests/TGA_PRO_MEM2_EXP/TGA_PRO_MEM2_EXP.ino index 9b91d9c..ba1660e 100644 --- a/examples/Tests/TGA_PRO_MEM2_EXP/TGA_PRO_MEM2_EXP.ino +++ b/examples/Tests/TGA_PRO_MEM2_EXP/TGA_PRO_MEM2_EXP.ino @@ -1,15 +1,52 @@ /************************************************************************* - * This demo is used for manufacturing tests on the TGA Pro Expansion - * Control Board. Pushing the buttons turns on the LEDs. Adjusting - * any know will adjust the volume. + * 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 * */ -#include + +#define RUN_MIDI_TEST // Comment out or delete this line to skip the MIDI test. +#define RUN_MEMO_TEST // Comment out or delete this line to skip the MEM0 test. +#define RUN_MEM1_TEST // (Teensy 3.5/3/6 only!) Comment out or delete this line to skip the MEM1 test. + #include -#include #define TGA_PRO_EXPAND_REV2 #include "BALibrary.h" @@ -26,8 +63,13 @@ 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) 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. @@ -39,11 +81,10 @@ void checkSwitch(unsigned id); bool spiTest(BASpiMemoryDMA *mem); // returns true if passed bool uartTest(); // returns true if passed +unsigned loopCounter = 0; + void setup() { Serial.begin(57600); - - spiMem0.begin(); - spiMem1.begin(); // Disable the audio codec first codec.disable(); @@ -54,13 +95,25 @@ void setup() { configPhysicalControls(controls, codec); // 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) + spiMem0.begin(); delay(10); if (spiTest(&spiMem0)) { Serial.println("SPI0 testing PASSED!");} +#endif + +#if defined(RUN_MEM1_TEST) + spiMem1.begin(); delay(10); if (spiTest(&spiMem1)) { Serial.println("SPI1 testing PASSED!");} +#endif + + Serial.println("Now monitoring for input from Expansion Control Board"); } void loop() { - // put your main code here, to run repeatedly: + checkPot(0); checkPot(1); checkPot(2); @@ -68,4 +121,8 @@ void loop() { checkSwitch(1); delay(10); + 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 index 0fb866b..0e2602e 100644 --- a/examples/Tests/TGA_PRO_MEM2_EXP/UartTest.cpp +++ b/examples/Tests/TGA_PRO_MEM2_EXP/UartTest.cpp @@ -3,18 +3,17 @@ using namespace BALibrary; -constexpr unsigned LOW_RATE = 2400; constexpr unsigned MIDI_RATE = 31250; constexpr unsigned HIGH_RATE = 250000; constexpr unsigned TEST_TIME = 5; // 5 second test each -static unsigned baudRate = LOW_RATE; // start with low speed +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 low speed, 1 for MIDI speed, 2 for high speed. +static unsigned testPhase = 0; // 0 for MIDI speed, 1 for high speed. bool uartTest(void) { @@ -32,12 +31,9 @@ bool uartTest(void) // next test switch (testPhase) { case 0 : - baudRate = MIDI_RATE; - break; - case 1 : baudRate = HIGH_RATE; break; - case 2 : + case 1 : testDone = true; } diff --git a/src/BAEffects.h b/src/BAEffects.h new file mode 100644 index 0000000..4b906a4 --- /dev/null +++ b/src/BAEffects.h @@ -0,0 +1,29 @@ +/* + * BAEffects.h + * + * Created on: May 22, 2017 + * Author: slascos + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version.* + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ +#ifndef __BAEFFECTS_H +#define __BAEFFECTS_H + +#include "BALibrary.h" // contains the Blackaddr hardware board definitions + +#include "BAAudioEffectDelayExternal.h" +#include "AudioEffectAnalogDelay.h" +#include "AudioEffectSOS.h" + +#endif /* __BAEFFECTS_H */ diff --git a/src/BALibrary.h b/src/BALibrary.h index c04b0b8..9a0a3d3 100644 --- a/src/BALibrary.h +++ b/src/BALibrary.h @@ -23,11 +23,12 @@ #include "BAHardware.h" // contains the Blackaddr hardware board definitions #include "BATypes.h" +#include "LibBasicFunctions.h" +#include "LibMemoryManagement.h" + #include "BAAudioControlWM8731.h" // Codec Control #include "BASpiMemory.h" #include "BAGpio.h" -#include "LibBasicFunctions.h" -#include "LibMemoryManagement.h" #include "BAPhysicalControls.h" #endif /* __BALIBRARY_H */