dsplib 1.1.0
C++ DSP library for MATLAB-like coding
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
dsplib::ChunkBuffer< T > Class Template Reference

Accumulates data samples and processes them in fixed-size chunks. More...

#include <buffer.h>

Public Types

using Callback = std::function< void(span_t< T >)>
 Callback type for processing full chunks.
 

Public Member Functions

 ChunkBuffer (int chunk_size)
 Construct a chunk buffer with specified chunk size.
 
void write (span_t< T > data, Callback fn)
 Add data to buffer and process complete chunks.
 
void flush (Callback fn)
 Process remaining data.
 
void reset ()
 Clear buffer contents Resets buffer to empty state. Preserves allocated capacity.
 
int size () const noexcept
 Get current number of accumulated samples.
 

Detailed Description

template<typename T>
class dsplib::ChunkBuffer< T >

Accumulates data samples and processes them in fixed-size chunks.

Template Parameters
TData type of stored elements (typically real_t or cmplx_t)

This buffer collects incoming data samples and automatically processes complete chunks of specified size through a callback. Partial chunks are preserved between write operations. Useful for block-based DSP processing.

Constructor & Destructor Documentation

◆ ChunkBuffer()

template<typename T >
dsplib::ChunkBuffer< T >::ChunkBuffer ( int  chunk_size)
inlineexplicit

Construct a chunk buffer with specified chunk size.

Parameters
chunk_sizeFixed processing chunk size (must be > 1)
Warning
Triggers assertion if chunk_size <= 1
Note
Pre-allocates memory for 2*chunk_size elements

Member Function Documentation

◆ flush()

template<typename T >
void dsplib::ChunkBuffer< T >::flush ( Callback  fn)
inline

Process remaining data.

Parameters
fnCallback receiving all remaining samples

Clears buffer after processing. Safe to call with empty buffer (callback receives empty span). Use for end-of-stream processing.

Warning
Callback execution MUST NOT call write()/flush() on same buffer

◆ reset()

template<typename T >
void dsplib::ChunkBuffer< T >::reset ( )
inline

Clear buffer contents Resets buffer to empty state. Preserves allocated capacity.

Exceptions
Assertionif called during write/flush operation

◆ size()

template<typename T >
int dsplib::ChunkBuffer< T >::size ( ) const
inlinenoexcept

Get current number of accumulated samples.

Returns
Count of unprocessed samples in buffer

Always 0 ≤ size() < chunk_size after write() completes

◆ write()

template<typename T >
void dsplib::ChunkBuffer< T >::write ( span_t< T >  data,
Callback  fn 
)
inline

Add data to buffer and process complete chunks.

Parameters
dataInput data span
fnProcessing callback for each full chunk

Behavior:

  • No-op for empty input
  • Asserts on recursive calls
  • Preserves partial chunks between calls
  • Calls callback for each complete chunk
  • Maintains temporal order of samples
Warning
Callback execution MUST NOT call write()/flush() on same buffer

The documentation for this class was generated from the following file: