try new AudioDelay class...wip

pull/1/head
Steve Lascos 7 years ago
parent d2a8227f91
commit f47ffc78db
  1. 49
      src/LibBasicFunctions.cpp
  2. 28
      src/LibBasicFunctions.h
  3. 2
      src/LibMemoryManagement.h

@ -9,6 +9,55 @@
namespace BAGuitar {
AudioDelay::AudioDelay(MemType type, size_t maxSamples)
{
m_type = type;
if (type == MemType::INTERNAL) {
// INTERNAL memory consisting of audio_block_t data structures.
QueuePosition pos = calcQueuePosition(maxSamples);
m_ringBuffer = new RingBuffer<audio_block_t *>(pos.index+2); // If the delay is in queue x, we need to overflow into x+1, thus x+2 total buffers.
} else {
// TODO EXTERNAL memory
}
}
AudioDelay::AudioDelay(MemType type, float delayTimeMs)
: AudioDelay(type, calcAudioSamples(delayTimeMs))
{
}
AudioDelay::~AudioDelay()
{
if (m_ringBuffer) delete m_ringBuffer;
}
bool AudioDelay::addBlock(audio_block_t *block)
{
if (m_type != MemType::INTERNAL) return false; // ERROR
// purposefully don't check if block is valid, the ringBuffer can support nullptrs
if ( m_ringBuffer->size() < m_ringBuffer->max_size() ) {
// pop before adding
release(m_ringBuffer->front());
m_ringBuffer->pop_front();
}
// add the new buffer
m_ringBuffer->push_back(block);
}
void AudioDelay::getSamples(audio_block_t *dest, size_t offset, size_t numSamples = AUDIO_BLOCK_SAMPLES)
{
QueuePosition pos = calcQueuePosition(offset);
size_t readOffset = pos.offset;
size_t index = pos.index;
// Audio is stored in reverse order. That means the first sample (in time) goes in the last location in the audio block.
}
}

@ -9,15 +9,39 @@
#include <new>
#include "Arduino.h"
#include "Audio.H"
#include "LibMemoryManagement.h"
#ifndef SRC_LIBBASICFUNCTIONS_H_
#define SRC_LIBBASICFUNCTIONS_H_
namespace BAGuitar {
class RingBuffer; // forward declare
enum MemType : unsigned {
INTERNAL,
EXTERNAL
};
struct INTERNAL_MEMORY {};
struct EXTERNAL_MEMORY {};
class AudioDelay {
AudioDelay() = delete;
AudioDelay(MemType type, size_t maxSamples);
AudioDelay(MemType type, float delayTimeMs);
~AudioDelay();
void addBlock(audio_block_t *block);
void getSamples(size_t offset, size_t numSamples);
private:
MemType m_type;
RingBuffer *m_ringBuffer = nullptr;
};
template <class T>
class RingBuffer {
public:
@ -74,6 +98,10 @@ public:
return size;
}
size_t max_size() const {
return m_maxSize;
}
T& operator[] (size_t index) {
return m_buffer[index];
}

@ -15,7 +15,7 @@
#include "BAHardware.h"
#include "BASpiMemory.h"
#include "LibBasicFunctions.h"
//#include "LibBasicFunctions.h"
namespace BAGuitar {

Loading…
Cancel
Save