Ring Buffer API

class RingBuffer

Ring buffer for managing Eigen::MatrixXf buffers with write/read pointers.

Provides efficient circular buffer functionality for maintaining input history in convolutional layers. Automatically handles buffer wrapping when needed.

Public Functions

inline RingBuffer()

Default constructor.

void Reset(const int channels, const int max_buffer_size)

Initialize/resize storage.

Parameters:
  • channels – Number of channels (rows in the storage matrix)

  • max_buffer_size – Maximum amount that will be written or read at once

void Write(const Eigen::MatrixXf &input, const int num_frames)

Write new data at write pointer.

NOTE: This function expects a full, pre-allocated, column-major MatrixXf covering the entire valid buffer range. Callers should not pass Block expressions (e.g. .leftCols()) across the API boundary; instead, pass the full buffer and slice inside the callee. This avoids Eigen evaluating Blocks into temporaries (which would allocate) when binding to MatrixXf.

Parameters:
  • input – Input matrix (channels x num_frames)

  • num_frames – Number of frames to write

Eigen::Block<Eigen::MatrixXf> Read(const int num_frames, const long lookback = 0)

Read data with optional lookback.

Parameters:
  • num_frames – Number of frames to read

  • lookback – Number of frames to look back from write pointer (default 0)

Returns:

Block reference to the storage data

void Advance(const int num_frames)

Advance write pointer.

Parameters:

num_frames – Number of frames to advance

inline int GetMaxBufferSize() const

Get max buffer size (the value passed to Reset())

Returns:

Maximum buffer size

inline int GetChannels() const

Get number of channels (rows)

Returns:

Number of channels

inline void SetMaxLookback(const long max_lookback)

Set the max lookback (maximum history needed when rewinding)

Parameters:

max_lookback – Maximum lookback distance