Further development of the external memory, correct naming issue with teh examples

pull/1/head
Steve Lascos 7 years ago
parent 6816a08dc6
commit 9fabb92d0d
  1. 0
      examples/0_TGA_Pro_TRY_FIRST/0_TGA_Pro_nolib_demo.ino
  2. 0
      examples/1_TGA_Pro_demo/1_TGA_Pro_demo.ino
  3. 0
      examples/2_TGA_Pro_1MEM/2_TGA_Pro_1MEM.ino
  4. 0
      examples/3_TGA_Pro_2MEM/3_TGA_Pro_2MEM.ino
  5. 0
      examples/4_TGA_Pro_delay_reverb/4_TGA_Pro_delay_reverb.ino
  6. 0
      examples/5_TGA_Pro_ExternalDelay_demo/5_TGA_Pro_ExternalDelay_demo.ino
  7. 61
      src/BAAudioEffectDelayExternal.cpp
  8. 20
      src/BAAudioEffectDelayExternal.h

@ -36,17 +36,18 @@ struct MemSpiConfig {
constexpr MemSpiConfig Mem0Config = {7, 8, 14, 15, 65536 }; constexpr MemSpiConfig Mem0Config = {7, 8, 14, 15, 65536 };
constexpr MemSpiConfig Mem1Config = {21, 5, 20, 31, 65536 }; constexpr MemSpiConfig Mem1Config = {21, 5, 20, 31, 65536 };
unsigned BAAudioEffectDelayExternal::m_usingSPICount[2] = {0,0};
BAAudioEffectDelayExternal::BAAudioEffectDelayExternal() BAAudioEffectDelayExternal::BAAudioEffectDelayExternal()
: AudioStream(1, inputQueueArray) : AudioStream(1, inputQueueArray)
{ {
initialize(MemSelect::MEM0, Mem0Config.memSize); initialize(MemSelect::MEM0);
} }
BAAudioEffectDelayExternal::BAAudioEffectDelayExternal(MemSelect mem, float milliseconds) BAAudioEffectDelayExternal::BAAudioEffectDelayExternal(MemSelect mem)
: AudioStream(1, inputQueueArray) : AudioStream(1, inputQueueArray)
{ {
uint32_t n = (milliseconds*(AUDIO_SAMPLE_RATE_EXACT/1000.0f))+0.5f; initialize(mem);
initialize(mem, n);
} }
void BAAudioEffectDelayExternal::delay(uint8_t channel, float milliseconds) { void BAAudioEffectDelayExternal::delay(uint8_t channel, float milliseconds) {
@ -59,7 +60,7 @@ void BAAudioEffectDelayExternal::delay(uint8_t channel, float milliseconds) {
n = memory_length - AUDIO_BLOCK_SAMPLES; n = memory_length - AUDIO_BLOCK_SAMPLES;
delay_length[channel] = n; delay_length[channel] = n;
uint8_t mask = activemask; uint8_t mask = activemask;
if (activemask == 0) AudioStartUsingSPI(); if (activemask == 0) m_startUsingSPI(m_spiChannel);
activemask = mask | (1<<channel); activemask = mask | (1<<channel);
} }
@ -67,7 +68,7 @@ void BAAudioEffectDelayExternal::disable(uint8_t channel) {
if (channel >= 8) return; if (channel >= 8) return;
uint8_t mask = activemask & ~(1<<channel); uint8_t mask = activemask & ~(1<<channel);
activemask = mask; activemask = mask;
if (mask == 0) AudioStopUsingSPI(); if (mask == 0) m_stopUsingSPI(m_spiChannel);
} }
void BAAudioEffectDelayExternal::update(void) void BAAudioEffectDelayExternal::update(void)
@ -132,8 +133,9 @@ void BAAudioEffectDelayExternal::update(void)
uint32_t BAAudioEffectDelayExternal::allocated[2] = {0, 0}; uint32_t BAAudioEffectDelayExternal::allocated[2] = {0, 0};
void BAAudioEffectDelayExternal::initialize(MemSelect mem, uint32_t samples) void BAAudioEffectDelayExternal::initialize(MemSelect mem)
{ {
uint32_t samples = 0;
uint32_t memsize, avail; uint32_t memsize, avail;
activemask = 0; activemask = 0;
@ -144,6 +146,8 @@ void BAAudioEffectDelayExternal::initialize(MemSelect mem, uint32_t samples)
switch (mem) { switch (mem) {
case MemSelect::MEM0 : case MemSelect::MEM0 :
{ {
samples = Mem0Config.memSize;
m_spiChannel = 0;
m_misoPin = Mem0Config.misoPin; m_misoPin = Mem0Config.misoPin;
m_mosiPin = Mem0Config.mosiPin; m_mosiPin = Mem0Config.mosiPin;
m_sckPin = Mem0Config.sckPin; m_sckPin = Mem0Config.sckPin;
@ -156,6 +160,9 @@ void BAAudioEffectDelayExternal::initialize(MemSelect mem, uint32_t samples)
break; break;
} }
case MemSelect::MEM1 : case MemSelect::MEM1 :
{
m_spiChannel = 1;
samples = Mem1Config.memSize;
m_misoPin = Mem1Config.misoPin; m_misoPin = Mem1Config.misoPin;
m_mosiPin = Mem1Config.mosiPin; m_mosiPin = Mem1Config.mosiPin;
m_sckPin = Mem1Config.sckPin; m_sckPin = Mem1Config.sckPin;
@ -167,6 +174,7 @@ void BAAudioEffectDelayExternal::initialize(MemSelect mem, uint32_t samples)
SPI1.begin(); SPI1.begin();
break; break;
} }
}
pinMode(m_csPin, OUTPUT); pinMode(m_csPin, OUTPUT);
digitalWriteFast(m_csPin, HIGH); digitalWriteFast(m_csPin, HIGH);
@ -262,7 +270,44 @@ void BAAudioEffectDelayExternal::write(uint32_t offset, uint32_t count, const in
// PRIVATE METHODS // PRIVATE METHODS
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
void BAAudioEffectDelayExternal::zero(uint32_t address, uint32_t count) { void BAAudioEffectDelayExternal::zero(uint32_t address, uint32_t count) {
write(address, count, NULL); write(address, count, NULL);
}
#ifdef SPI_HAS_NOTUSINGINTERRUPT
inline void BAAudioEffectDelayExternal::m_startUsingSPI(int spiBus) {
if (spiBus == 0) {
SPI.usingInterrupt(IRQ_SOFTWARE);
} else if (spiBus == 1) {
SPI1.usingInterrupt(IRQ_SOFTWARE);
}
m_usingSPICount[spiBus]++;
}
inline void BAAudioEffectDelayExternal::m_stopUsingSPI(int spiBus) {
if (m_usingSPICount[spiBus] == 0 || --m_usingSPICount[spiBus] == 0)
{
if (spiBus == 0) {
SPI.notUsingInterrupt(IRQ_SOFTWARE);
} else if (spiBus == 1) {
SPI1.notUsingInterrupt(IRQ_SOFTWARE);
}
}
}
#else
inline void BAAudioEffectDelayExternal::m_startUsingSPI(int spiBus) {
if (spiBus == 0) {
SPI.usingInterrupt(IRQ_SOFTWARE);
} else if (spiBus == 1) {
SPI1.usingInterrupt(IRQ_SOFTWARE);
} }
}
inline void BAAudioEffectDelayExternal::m_stopUsingSPI(int spiBus) {
}
#endif
} /* namespace BAGuitar */ } /* namespace BAGuitar */

@ -26,14 +26,16 @@ class BAAudioEffectDelayExternal : public AudioStream
public: public:
BAAudioEffectDelayExternal(); BAAudioEffectDelayExternal();
BAAudioEffectDelayExternal(MemSelect type, float milliseconds=1e6); BAAudioEffectDelayExternal(MemSelect type);
void delay(uint8_t channel, float milliseconds); void delay(uint8_t channel, float milliseconds);
void disable(uint8_t channel); void disable(uint8_t channel);
virtual void update(void); virtual void update(void);
static unsigned m_usingSPICount[2];
private: private:
void initialize(MemSelect mem, uint32_t samples); void initialize(MemSelect mem);
void read(uint32_t address, uint32_t count, int16_t *data); void read(uint32_t address, uint32_t count, int16_t *data);
void write(uint32_t address, uint32_t count, const int16_t *data); void write(uint32_t address, uint32_t count, const int16_t *data);
void zero(uint32_t address, uint32_t count); void zero(uint32_t address, uint32_t count);
@ -46,11 +48,17 @@ private:
static uint32_t allocated[2]; static uint32_t allocated[2];
audio_block_t *inputQueueArray[1]; audio_block_t *inputQueueArray[1];
MemSelect m_mem; MemSelect m_mem;
int m_misoPin; int m_spiChannel = 0;
int m_mosiPin; int m_misoPin = 0;
int m_sckPin; int m_mosiPin = 0;
int m_csPin; int m_sckPin = 0;
int m_csPin = 0;
void m_startUsingSPI(int spiBus);
void m_stopUsingSPI(int spiBus);
}; };

Loading…
Cancel
Save