diff --git a/src/LibBasicFunctions.h b/src/LibBasicFunctions.h index 1dba21a..900794b 100644 --- a/src/LibBasicFunctions.h +++ b/src/LibBasicFunctions.h @@ -201,7 +201,7 @@ public: /// @returns true if suceess, false if an error occurs bool setSpiDmaCopyBuffer(void); - /// Ween using INTERNAL memory, thsi function can return a pointer to the underlying RingBuffer that contains + /// When using INTERNAL memory, this function can return a pointer to the underlying RingBuffer that contains /// audio_block_t * pointers. /// @returns pointer to the underlying RingBuffer RingBuffer *getRingBuffer() const { return m_ringBuffer; } diff --git a/src/common/AudioDelay.cpp b/src/common/AudioDelay.cpp index 10c420b..69a6522 100644 --- a/src/common/AudioDelay.cpp +++ b/src/common/AudioDelay.cpp @@ -79,6 +79,14 @@ audio_block_t* AudioDelay::addBlock(audio_block_t *block) if (!m_slot) { Serial.println("addBlock(): m_slot is not valid"); } if (block) { + + // KLUGE! The Teensy Audio Library doesn't support DMA buffers correctly on the T4.0. We need to + // use an intermediate copy buffer kluge here. +#if defined(__IMXRT1062__) + // This is a T4.0 build + setSpiDmaCopyBuffer(); +#endif + // this causes pops m_slot->writeAdvance16(block->data, AUDIO_BLOCK_SAMPLES); } @@ -164,6 +172,7 @@ bool AudioDelay::m_getSamples(int16_t *dest, size_t offsetSamples, size_t numSam } else { // EXTERNAL Memory if (numSamples*sizeof(int16_t) <= m_slot->size() ) { // check for overflow + // current position is considered the write position subtracted by the number of samples we're going // to read since this is the smallest delay we can get without reading past the write position into // the "future". @@ -216,8 +225,11 @@ bool AudioDelay::setSpiDmaCopyBuffer(void) // For DMA use on T4.0 we need this kluge BASpiMemoryDMA * spiDma = static_cast(m_slot->getSpiMemoryHandle()); if (spiDma) { - spiDma->setDmaCopyBufferSize(sizeof(int16_t) * AUDIO_BLOCK_SAMPLES); - returnValue = true; + // Check if the size is already set + if (spiDma->getDmaCopyBufferSize() == 0) { + spiDma->setDmaCopyBufferSize(sizeof(int16_t) * AUDIO_BLOCK_SAMPLES); + returnValue = true; + } } } return returnValue;