Reorganized the library, add hooks for future boards, and have revamped the BAAudioEffectExternalDelay class

pull/1/head
Steve Lascos 7 years ago
parent a99e7aaca4
commit df9ff8fefc
  1. 75
      examples/BA5_TGA_Pro_ExternalDelay_demo/BA5_TGA_Pro_ExternalDelay_demo.ino
  2. 4
      src/BAAudioControlWM8731.cpp
  3. 13
      src/BAAudioControlWM8731.h
  4. 2
      src/BAAudioEffectDelayExternal.cpp
  5. 59
      src/BAAudioEffectDelayExternal.h
  6. 17
      src/BACommon.h
  7. 17
      src/BAGpio.cpp
  8. 35
      src/BAGpio.h
  9. 16
      src/BAGuitar.h
  10. 86
      src/BAHardware.h
  11. 32
      src/BASpiMemory.h

@ -5,22 +5,13 @@
* The latest copy of the BA Guitar library can be obtained from
* https://github.com/Blackaddr/BAGuitar
*
* This demo demonstrates how to override the default AudioEffectDelayExternal
* in the Teensy Library with the one in the BAGuitar library. This is necessary
* because the SPI pins in AudioEffectDelayExternal are hard-coded and not the
* same at the TGA Pro.
* This demo shows to use the BAAudioEffectDelayExternal audio class
* to create long delays using external SPI RAM.
*
* Simply replace AudioEffectDelayExternal with BAAudioEffectDelayExternal
* and it should work the same as the default Audio library.
*
* This demo mixes the original guitar signal with one delayed by 1.45 ms
* the the external SRAM MEM0 on the TGA Pro
* Eight delay taps are configured from a single SRAM device.
*
*/
#include <Wire.h>
//#include <Audio.h>
#include <MIDI.h>
#include <SPI.h>
#include "BAGuitar.h"
using namespace BAGuitar;
@ -29,13 +20,26 @@ AudioInputI2S i2sIn;
AudioOutputI2S i2sOut;
BAAudioControlWM8731 codecControl;
BAAudioEffectDelayExternal longDelay;
AudioMixer4 delayMixer;
BAAudioEffectDelayExternal longDelay(MemSelect::MEM0); // comment this line to use MEM1
//BAAudioEffectDelayExternal longDelay(MemSelect::MEM1); // and uncomment this one to use MEM1
AudioMixer4 delayOutMixerA, delayOutMixerB, delayMixer;
// Audio Connections
AudioConnection fromInput(i2sIn,0, longDelay, 0);
AudioConnection fromDelayL(longDelay, 0, delayMixer, 0);
AudioConnection dry(i2sIn, 1, delayMixer, 1);
AudioConnection fromDelay0(longDelay,0, delayOutMixerA,0);
AudioConnection fromDelay1(longDelay,1, delayOutMixerA,1);
AudioConnection fromDelay2(longDelay,2, delayOutMixerA,2);
AudioConnection fromDelay3(longDelay,3, delayOutMixerA,3);
AudioConnection fromDelay4(longDelay,4, delayOutMixerB,0);
AudioConnection fromDelay5(longDelay,5, delayOutMixerB,1);
AudioConnection fromDelay6(longDelay,6, delayOutMixerB,2);
AudioConnection fromDelay7(longDelay,7, delayOutMixerB,3);
AudioConnection fromDelayA(delayOutMixerA, 0, delayMixer, 0);
AudioConnection fromDelayB(delayOutMixerB, 0, delayMixer, 1);
AudioConnection dry(i2sIn, 0, delayMixer, 2);
AudioConnection outputLeft(delayMixer, 0, i2sOut, 0);
AudioConnection outputRight(delayMixer, 0, i2sOut, 1);
@ -43,20 +47,42 @@ AudioConnection outputRight(delayMixer, 0, i2sOut, 1);
void setup() {
Serial.begin(57600);
delay(1000);
// If the codec was already powered up (due to reboot) power itd own first
codecControl.disable();
delay(100);
AudioMemory(128);
delay(3000);
Serial.println(String("Starting...\n"));
delay(1000);
Serial.println("Enabling codec...\n");
codecControl.enable();
delay(1000);
longDelay.delay(0, 1450.0f);
// Set up 8 delay taps, each with evenly spaced, longer delays
longDelay.delay(0, 150.0f);
longDelay.delay(1, 300.0f);
longDelay.delay(2, 450.0f);
longDelay.delay(3, 600.0f);
longDelay.delay(4, 750.0f);
longDelay.delay(5, 900.0f);
longDelay.delay(6, 1050.0f);
longDelay.delay(7, 1200.0f);
// mix the first four taps together with increasing attenuation (lower volume)
delayOutMixerA.gain(0, 1.0f);
delayOutMixerA.gain(1, 0.8f);
delayOutMixerA.gain(2, 0.4f);
delayOutMixerA.gain(3, 0.2f);
// mix the next four taps with decreasing volume
delayOutMixerB.gain(0, 0.1f);
delayOutMixerB.gain(1, 0.05f);
delayOutMixerB.gain(2, 0.025f);
delayOutMixerB.gain(3, 0.0125f);
// mix the original signal with the two delay mixers
delayMixer.gain(0, 1.0f);
delayMixer.gain(1, 1.0f);
delayMixer.gain(2, 1.0f);
}
@ -65,4 +91,3 @@ void loop() {
}

@ -1,5 +1,5 @@
/*
* BAAudioControlWM8731.h
* BAAudioControlWM8731.cpp
*
* Created on: May 22, 2017
* Author: slascos
@ -132,6 +132,8 @@ void BAAudioControlWM8731::disable(void)
void BAAudioControlWM8731::enable(void)
{
disable(); // disable first in case it was already powered up
//Serial.println("Enabling codec");
if (m_wireStarted == false) { Wire.begin(); m_wireStarted = true; }
// Sequence from WAN0111.pdf

@ -1,12 +1,13 @@
/**************************************************************************//**
* @file
* @author Steve Lascos
* @company Blackaddr Audio
*
* BAAudioContromWM8731 is a class for controlling a WM8731 Codec via I2C.
* @details The Codec power ups in a silent state, with non-optimal
* configuration. This class will enable codec and set some initial gain levels.
* The user can than use the API to changing settings for their specific needs.
*
* @file
* @author Steve Lascos
* @company Blackaddr Audio
* @copyright 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
@ -21,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef INC_BAAUDIOCONTROLWM8731_H_
#define INC_BAAUDIOCONTROLWM8731_H_
#ifndef __INC_BAAUDIOCONTROLWM8731_H
#define __INC_BAAUDIOCONTROLWM8731_H
namespace BAGuitar {
@ -127,4 +128,4 @@ private:
} /* namespace BAGuitar */
#endif /* INC_BAAUDIOCONTROLWM8731_H_ */
#endif /* __INC_BAAUDIOCONTROLWM8731_H */

@ -1,5 +1,5 @@
/*
* BAAudioControlWM8731.h
* BAAudioEffectDelayExternal.cpp
*
* Created on: November 1, 2017
* Author: slascos

@ -1,41 +1,70 @@
/*
* BAAudioEffectDelayExternal.h
/**************************************************************************//**
* @file
* @author Steve Lascos
* @company Blackaddr Audio
*
* Created on: Nov 5, 2017
* Author: slascos
*/
* BAAudioEffectDelayExternal is a class for using an external SPI SRAM chip
* as an audio delay line. The external memory can be shared among several
* different instances of BAAudioEffectDelayExternal by specifying the max delay
* length during construction.
*
* @copyright 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 <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef __BAGUITAR_BAAUDIOEFFECTDELAYEXTERNAL_H
#define __BAGUITAR_BAAUDIOEFFECTDELAYEXTERNAL_H
#include <Audio.h>
#include "Arduino.h"
#include "AudioStream.h"
#include "spi_interrupt.h"
#include "BACommon.h"
#include "BAHardware.h"
namespace BAGuitar {
enum MemSelect : unsigned {
MEM0 = 0,
MEM1 = 1
};
/**************************************************************************//**
* BAAudioEffectDelayExternal can use external SPI RAM for delay rather than
* the limited RAM available on the Teensy itself.
*****************************************************************************/
class BAAudioEffectDelayExternal : public AudioStream
{
public:
/// Default constructor will use all memory available in MEM0
BAAudioEffectDelayExternal();
/// Specifiy which external memory to use
/// @param type specify which memory to use
BAAudioEffectDelayExternal(BAGuitar::MemSelect type);
/// Specify external memory, and how much of the memory to use
/// @param type specify which memory to use
/// @param delayLengthMs maximum delay length in milliseconds
BAAudioEffectDelayExternal(BAGuitar::MemSelect type, float delayLengthMs);
virtual ~BAAudioEffectDelayExternal();
/// set the actual amount of delay on a given delay tap
/// @param channel specify channel tap 1-8
/// @param milliseconds specify how much delay for the specified tap
void delay(uint8_t channel, float milliseconds);
/// Disable a delay channel tap
/// @param channel specify channel tap 1-8
void disable(uint8_t channel);
virtual void update(void);
static unsigned m_usingSPICount[2];
static unsigned m_usingSPICount[2]; // internal use for all instances
private:
void initialize(BAGuitar::MemSelect mem, unsigned delayLength = 1e6);
@ -50,8 +79,6 @@ private:
static unsigned m_allocated[2];
audio_block_t *m_inputQueueArray[1];
BAGuitar::MemSelect m_mem;
SPIClass *m_spi = nullptr;
int m_spiChannel = 0;

@ -1,17 +0,0 @@
/*
* BACommon.h
*
* Created on: Nov 19, 2017
* Author: slascos
*/
#ifndef SRC_BACOMMON_H_
#define SRC_BACOMMON_H_
namespace BAGuitar {
constexpr int MEM0_MAX_ADDR = 131071; ///< Max address size per chip
constexpr int MEM1_MAX_ADDR = 131071; ///< Max address size per chip
}
#endif /* SRC_BACOMMON_H_ */

@ -1,9 +1,22 @@
/*
* BAGpio.cpp
*
* Created on: Sep 17, 2017
* Created on: November 1, 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 <http://www.gnu.org/licenses/>.
*/
#include "Arduino.h"
#include "BAGpio.h"

@ -1,10 +1,11 @@
/**************************************************************************//**
* BAGPio is convenience class for accessing the the various GPIOs available
* on the Teensy Guitar Audio series boards.
*
* @file
* @author Steve Lascos
* @company Blackaddr Audio
*
* BAGPio is convenience class for accessing the the various GPIOs available
* on the Teensy Guitar Audio series boards.
*
* @copyright 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
@ -19,30 +20,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef SRC_BAGPIO_H_
#define SRC_BAGPIO_H_
#ifndef __SRC_BAGPIO_H
#define __SRC_BAGPIO_H
namespace BAGuitar {
#include "BAHardware.h"
constexpr uint8_t USR_LED_ID = 16; ///< Teensy IO number for the user LED.
/**************************************************************************//**
* GPIOs and Testpoints are accessed via enumerated class constants.
*****************************************************************************/
enum class GPIO : uint8_t {
GPIO0 = 2,
GPIO1 = 3,
GPIO2 = 4,
GPIO3 = 6,
GPIO4 = 12,
GPIO5 = 32,
GPIO6 = 27,
GPIO7 = 28,
TP1 = 34,
TP2 = 33
};
namespace BAGuitar {
/**************************************************************************//**
* BAGpio provides a convince class to easily control the direction and state
@ -89,4 +72,4 @@ private:
} /* namespace BAGuitar */
#endif /* SRC_BAGPIO_H_ */
#endif /* __SRC_BAGPIO_H */

@ -18,20 +18,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SRC_BATGUITAR_H_
#define SRC_BATGUITAR_H_
#ifndef __SRC_BATGUITAR_H
#define __SRC_BATGUITAR_H
#include "BAHardware.h" // contains the Blackaddr hardware board definitions
#include "BAAudioControlWM8731.h" // Codec Control
#include "BASpiMemory.h"
#include "BAGpio.h"
#include "BAAudioEffectDelayExternal.h"
/**************************************************************************//**
* BAGuitar is a namespace/Library for Guitar processing from Blackaddr Audio.
*****************************************************************************/
namespace BAGuitar {
}
#endif /* SRC_BATGUITAR_H_ */
#endif /* __SRC_BATGUITAR_H */

@ -0,0 +1,86 @@
/**************************************************************************//**
* @file
* @author Steve Lascos
* @company Blackaddr Audio
*
* This file contains specific definitions for each Blackaddr Audio hardware
* board.
*
* @copyright 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 <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef SRC_BAHARDWARE_H_
#define SRC_BAHARDWARE_H_
/**************************************************************************//**
* BAGuitar is a namespace/Library for Guitar processing from Blackaddr Audio.
*****************************************************************************/
namespace BAGuitar {
// uncomment the line that corresponds to your hardware
#define TGA_PRO_REVA
//#define TGA_PRO_REVB // does not exist yet
#ifdef TGA_PRO_REVA
constexpr uint8_t USR_LED_ID = 16; ///< Teensy IO number for the user LED.
/**************************************************************************//**
* GPIOs and Testpoints are accessed via enumerated class constants.
*****************************************************************************/
enum class GPIO : uint8_t {
GPIO0 = 2,
GPIO1 = 3,
GPIO2 = 4,
GPIO3 = 6,
GPIO4 = 12,
GPIO5 = 32,
GPIO6 = 27,
GPIO7 = 28,
TP1 = 34,
TP2 = 33
};
/**************************************************************************//**
* Optionally installed SPI RAM
*****************************************************************************/
enum MemSelect : unsigned {
MEM0 = 0, ///< SPI RAM MEM0
MEM1 = 1 ///< SPI RAM MEM1
};
constexpr int MEM0_MAX_ADDR = 131071; ///< Max address size per chip
constexpr int MEM1_MAX_ADDR = 131071; ///< Max address size per chip
/**************************************************************************//**
* General Purpose SPI Interfaces
*****************************************************************************/
enum class SpiDeviceId {
SPI_DEVICE0, ///< Arduino SPI device
SPI_DEVICE1 ///< Arduino SPI1 device
};
constexpr int SPI_MAX_ADDR = 131071; ///< Max address size per chip
#else
#error "No hardware declared"
#endif
} // namespace BAGuitar
#endif /* SRC_BAHARDWARE_H_ */

@ -1,10 +1,11 @@
/**************************************************************************//**
* BASpiMemory is convenience class for accessing the optional SPI RAMs on
* the GTA Series boards.
*
* @file
* @author Steve Lascos
* @company Blackaddr Audio
*
* BASpiMemory is convenience class for accessing the optional SPI RAMs on
* the GTA Series boards.
*
* @copyright 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
@ -18,23 +19,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef SRC_BASPIMEMORY_H_
#define SRC_BASPIMEMORY_H_
#ifndef __SRC_BASPIMEMORY_H
#define __SRC_BASPIMEMORY_H
#include <SPI.h>
namespace BAGuitar {
constexpr int SPI_MAX_ADDR = 131071; ///< Max address size per chip
#include "BAHardware.h"
/**************************************************************************//**
* This class enumerates access to the two potential SPI RAMs.
*****************************************************************************/
enum class SpiDeviceId {
SPI_DEVICE0,
SPI_DEVICE1
};
namespace BAGuitar {
/**************************************************************************//**
* This wrapper class uses the Arduino SPI (Wire) library to access the SPI ram.
@ -64,10 +56,14 @@ public:
void write16(int address, uint16_t data);
/// read a single data word from the specified address
/// read a single 8-bit data word from the specified address
/// @param address the address in the SPI RAM to read from
/// @return the data that was read
int read(int address);
/// read a single 16-bit data word from the specified address
/// @param address the address in the SPI RAM to read from
/// @return the data that was read
uint16_t read16(int address);
private:
@ -82,4 +78,4 @@ class BASpiMemoryException {};
} /* namespace BAGuitar */
#endif /* SRC_BASPIMEMORY_H_ */
#endif /* __SRC_BASPIMEMORY_H */

Loading…
Cancel
Save