How do you buffer data for block processing

A simple ring buffer that is accessed only from the audio thread (the process() method) is also very trivial to implement yourself. You just need a buffer, its length and a counter as member variables of the Module subclass.

// member variables
int m_bufferCounter = 0;
int m_bufferLength = 4096;
float m_buffer[4096];

void process(const ProcessArgs& args) override
{
  float insample = inputs[IN_AUDIO].getVoltageSum();
  m_buffer[m_bufferCounter] = insample;
  ++m_bufferCounter;
  if (m_bufferCounter == m_bufferLength)
  {
      m_bufferCounter = 0;
      // buffer now has enough data to process
  }
}

However, in many cases you will end up needing multiple ring buffers, so it’s probably a good idea to abstract the ring buffering into a separate class (or use an existing implementation).

1 Like