Class thl::core::Buffer#

template<typename T>
class Buffer#

Planar audio buffer backed by a contiguous MemoryBlock with cached channel pointers.

Memory layout: ch0[0..N-1], ch1[0..N-1], …

Supports zero-copy swap_data() operations and direct channel-pointer array access for interoperability with C-style audio APIs.

Failure semantics (no logging, no platform dependencies):

  • Allocation failure throws std::bad_alloc.

  • swap_data() with mismatched dimensions is a contract violation: it asserts in debug builds and is a no-op in release builds.

Public Functions

Buffer() = default#
inline Buffer(size_t num_channels, size_t num_frames, double sample_rate = 0.0)#
inline Buffer(const Buffer &other)#
inline Buffer(Buffer &&other) noexcept#
inline ~Buffer()#
inline Buffer &operator=(const Buffer &other)#

Copy-and-swap: if the copy throws (std::bad_alloc) *this is unchanged.

inline Buffer &operator=(Buffer &&other) noexcept#
inline size_t get_num_samples() const#
inline size_t get_num_channels() const#
inline double get_sample_rate() const#
inline bool empty() const#
inline const T *get_read_pointer(size_t channel) const#
inline const T *get_read_pointer(size_t channel, size_t sample_index) const#
inline T *get_write_pointer(size_t channel)#
inline T *get_write_pointer(size_t channel, size_t sample_index)#
inline const T *const *get_array_of_read_pointers() const#
inline T *const *get_array_of_write_pointers()#
inline T *data()#
inline const T *data() const#
inline MemoryBlock<T> &get_memory_block()#
inline T get_sample(size_t channel, size_t sample_index) const#
inline void set_sample(size_t channel, size_t sample_index, T value)#
inline void set_size(size_t num_channels, size_t num_frames, double sample_rate)#

Resize and set the sample rate.

Contents are not preserved: the buffer is zeroed. If the allocation fails (std::bad_alloc) the buffer is left unchanged.

inline void resize(size_t num_channels, size_t num_frames)#

Resize; see set_size(). Leaves the buffer unchanged if allocation fails.

inline void clear()#
inline void swap_data(Buffer &other)#

Precondition: same channel count and frame count.

inline void swap_data(MemoryBlock<T> &other)#

Precondition: other.size() == get_num_channels() * get_num_samples().

inline void swap_data(T *&raw_data, size_t size)#

Precondition: size == get_num_channels() * get_num_samples().

inline void reset_channel_ptr()#
inline BasicBufferView<T> view()#
inline BasicBufferView<const T> view() const#