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()#
-
inline Buffer &operator=(const Buffer &other)#
Copy-and-swap: if the copy throws (std::bad_alloc) *this is unchanged.
-
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 MemoryBlock<T> &get_memory_block()#
-
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(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#