class audio_data<Interleaved> audio¶
template <bool Interleaved = false>
struct audio_data { … } Contiguous audio buffer with optional interleaving.
Stores multi-channel audio either as planar (separate channel buffers) or interleaved (single strided buffer). Provides allocation, slicing, arithmetic, and traversal utilities.
| Interleaved | If true, samples are interleaved; otherwise planar per-channel pointers. |
variable channels ¶
uint32_t channels = 0 Number of channels.
Defined at audio/data.hpp:457
variable data ¶
chan<fbase*, Interleaved> data{} Pointers to channel data.
Defined at audio/data.hpp:458
variable size ¶
size_t size Number of samples per channel.
Defined at audio/data.hpp:459
variable capacity ¶
size_t capacity Allocated capacity per channel.
Defined at audio/data.hpp:460
variable position ¶
int64_t position = 0 Position of the first sample in the audio data.
Defined at audio/data.hpp:461
variable deallocator ¶
std::shared_ptr<void> deallocator Deallocator for the data.
Defined at audio/data.hpp:462
function operator==(const audio_data<Interleaved> &) ¶
bool operator==(const audio_data& other) const noexcept = default Defined at audio/data.hpp:464
constructor audio_data<Interleaved>() ¶
Defined at audio/data.hpp:466
constructor audio_data<Interleaved>(const audio_data<Interleaved> &) ¶
audio_data(const audio_data&) noexcept = default Converts between planar and interleaved layouts.
| other | Source buffer with the opposite interleaving layout. |
Defined at audio/data.hpp:491
constructor audio_data<Interleaved>(audio_data<Interleaved> &&) ¶
audio_data(audio_data&&) noexcept = default Defined at audio/data.hpp:492
function operator=(const audio_data<Interleaved> &) ¶
audio_data& operator=(const audio_data&) noexcept = default Defined at audio/data.hpp:493
function operator=(audio_data<Interleaved> &&) ¶
audio_data& operator=(audio_data&&) noexcept = default Defined at audio/data.hpp:494
function audio_data<Interleaved>(std::span<fbase *const>, size_t, Fn &&) ¶
template <std::invocable Fn>
[[nodiscard]] audio_data(std::span<fbase* const> pointers, size_t size, Fn&& deallocator)
requires(!Interleaved) Defined at audio/data.hpp:497
constructor audio_data<Interleaved>(std::span<fbase *const>, size_t) ¶
[[nodiscard]] audio_data(std::span<fbase* const> pointers, size_t size)
requires(!Interleaved) Defined at audio/data.hpp:504
constructor audio_data<Interleaved>(fbase *, size_t, size_t) ¶
[[nodiscard]] audio_data(fbase* pointer, size_t channels, size_t size)
requires(Interleaved) Defined at audio/data.hpp:507
function audio_data<Interleaved>(fbase *, size_t, size_t, Fn &&) ¶
template <std::invocable Fn>
[[nodiscard]] audio_data(fbase* pointer, size_t channels, size_t size, Fn&& deallocator)
requires(Interleaved) Defined at audio/data.hpp:511
constructor audio_data<Interleaved>(size_t, size_t) ¶
[[nodiscard]] explicit audio_data(size_t channels, size_t size = 0) Constructs an audio_data buffer with the specified channel count and optional initial size.
Allocates aligned storage and initializes channel pointers according to layout: - Interleaved: a single contiguous block. - Planar: per-channel blocks aligned to 64 bytes (allocated as single memory block).If size is 0, an empty buffer is created without allocating sample storage.Capacity is set to size, and can be increased later via reserve().
| channels | Number of audio channels (1..max_audio_channels). |
| size | Optional initial number of samples per channel (capacity); 0 defers allocation. |
Defined at audio/data.hpp:536
constructor audio_data<Interleaved>(size_t, size_t, fbase) ¶
[[nodiscard]] audio_data(size_t channels, size_t size, fbase value) Constructs an audio buffer and initializes all samples to a constant value.
| channels | Number of channels to allocate. |
| size | Number of samples per channel. |
| value | Initial sample value applied to every element. |
Note
Equivalent to constructing with (channels, size) and then filling with value.
Defined at audio/data.hpp:546
function total_samples() ¶
size_t total_samples() const noexcept Calculates the total number of audio samples.
This function computes the total number of samples by multiplying the size (number of frames) by the number of channels in the audio data.
| The total number of samples as a size_t value. |
Defined at audio/data.hpp:556
function reset() ¶
void reset() Resets the object to its default state.
This function assigns a default-constructed instance of the object to itself, effectively resetting all its members to their default values.
Defined at audio/data.hpp:564
function fill(fbase) ¶
void fill(fbase value) Fills the audio data with the specified value.
This function sets all elements of the audio data to the given value.
| value | The value to fill the audio data with. |
Defined at audio/data.hpp:573
function multiply(fbase) ¶
void multiply(fbase value) Multiplies the audio data by a specified scalar value.
This function scales the audio data by the given factor, modifying the current data in place.
| value | The scalar value to multiply the audio data by. |
Defined at audio/data.hpp:583
function clear() ¶
void clear() Clears all audio data, leaving the container empty (size == 0).
Defined at audio/data.hpp:588
function resize(size_t) ¶
void resize(size_t new_size) Resizes the container to hold exactly new_size elements.
- If new_size <= current capacity, adjusts size without reallocating. - Otherwise, increases capacity (rounded up) via reserve() and then updates size.Preserves existing elements up to min(old_size, new_size). When growing, newly added elements may be left uninitialized. Shrinking does not reduce capacity. May reallocate on growth, invalidating pointers/references to elements.
| new_size | Number of elements desired. |
Defined at audio/data.hpp:602
function resize(size_t, fbase) ¶
void resize(size_t new_size, fbase value) Resize to the specified length and initialize newly added samples.
Preserves existing data. If the size grows, the appended region is filled with the given value; if it shrinks, the buffer is truncated. Works with both interleaved and planar layouts, applying initialization across all channels as appropriate.
| new_size | Target number of frames (samples per channel). |
| value | Sample value used to initialize newly created elements. |
Defined at audio/data.hpp:614
function reserve(size_t) ¶
void reserve(size_t new_capacity) Defined at audio/data.hpp:616
function append(const audio_data<!Interleaved> &) ¶
void append(const audio_data<!Interleaved>& other) Defined at audio/data.hpp:622
function prepend(const audio_data<!Interleaved> &) ¶
void prepend(const audio_data<!Interleaved>& other) Defined at audio/data.hpp:624
function swap(audio_data<Interleaved> &, audio_data<Interleaved> &) ¶
friend void swap(audio_data& a, audio_data& b) noexcept Defined at audio/data.hpp:626
function swap(audio_data<Interleaved> &) ¶
void swap(audio_data& other) noexcept Defined at audio/data.hpp:628
function empty() ¶
[[nodiscard]] bool empty() const noexcept Check whether this audio data container is empty.
Considered empty if either the number of channels is zero or the size (samples/frames) is zero.
| true if no channels or no samples. |
Defined at audio/data.hpp:636
function channel(size_t) ¶
[[nodiscard]] strided_channel<fbase> channel(size_t index) const noexcept
requires(Interleaved) Retrieves a reference to the audio data of a specific channel.
This function returns a univector_ref<fbase> representing the audio data for the specified channel index. It is only available when the audio data is not interleaved (i.e., Interleaved is false).
| index | The index of the channel to retrieve. Must be less than the total number of channels. |
A univector_ref<fbase> representing the audio data for the specified channel. |
Defined at audio/data.hpp:656
function interlaved() ¶
[[nodiscard]] univector_ref<fbase> interlaved() const noexcept
requires(Interleaved) Returns a reference to the interleaved audio data.
This function provides access to the interleaved audio data as a univector_ref<fbase>. It is only available when the audio data is interleaved (i.e., Interleaved is true).
A univector_ref<fbase> representing the interleaved audio data. The size of the returned reference is calculated as size * channels. |
Defined at audio/data.hpp:672
function pointers() ¶
[[nodiscard]] fbase* const* pointers() const noexcept
requires(!Interleaved) Retrieves an array of pointers to the base type of the audio data.
This function returns a pointer to the underlying data array, which contains pointers to the base type (fbase*). It is only available when the audio data is not interleaved (i.e., Interleaved is false).
A pointer to the array of fbase* representing the audio data. |
Defined at audio/data.hpp:687
function channel_count() ¶
[[nodiscard]] size_t channel_count() const noexcept Retrieves the number of audio channels.
Defined at audio/data.hpp:696
function slice(size_t, size_t) ¶
[[nodiscard]] audio_data slice(size_t start, size_t length = SIZE_MAX) const Creates a slice of the audio data starting at a specified position and with a specified length.
| start | The starting position of the slice (in samples). |
| length | The length of the slice (in samples). Defaults to SIZE_MAX, which means the slice will extend to the end of the audio data if not specified. |
| audio_data A new audio_data object representing the sliced portion of the original data. |
Note
The function ensures that the slice does not exceed the bounds of the audio data. If the requested length exceeds the available data, the slice will be truncated to fit within the bounds.
- The position of the resulting slice is updated to reflect the starting position of the slice.
Defined at audio/data.hpp:714
function truncate(size_t) ¶
[[nodiscard]] audio_data truncate(size_t length) const Truncates the audio data to the specified length.
This function creates a new audio_data object that contains only the first length samples from the current audio data. If the specified length is greater than the size of the current audio data, the entire audio data is returned.
| length | The number of samples to retain in the truncated audio data. |
| A new audio_data object containing the truncated data. |
Defined at audio/data.hpp:727
function slice_past_end(size_t) ¶
[[nodiscard]] audio_data slice_past_end(size_t length) Creates a new audio_data object representing a slice of audio data starting past the end of the current data.
This function reserves additional space in the current audio data to accommodate the specified length, then creates a new audio_data object that represents a slice of the specified length starting from the end of the current data. The new slice shares the same underlying data buffer as the original object.
| length | The length of the slice to create, in samples. |
| A new audio_data object representing the slice. |
Defined at audio/data.hpp:742
function stat() ¶
[[nodiscard]] audio_stat stat() const noexcept Retrieves the statistical information of the audio data.
Defined at audio/data.hpp:747
function is_silent(fbase) ¶
[[nodiscard]] bool is_silent(fbase threshold = fbase(1e-5)) const noexcept Checks whether all samples in the buffer are effectively silent within a given amplitude threshold.
| threshold | Non-negative amplitude threshold. Any sample with absolute value strictly greater than this threshold makes the buffer non-silent. Values exactly equal to the threshold are treated as silent. Default: 1e-5. |
| true if every sample lies within [-threshold, threshold]; false otherwise. |
Defined at audio/data.hpp:758
function find_peak() ¶
[[nodiscard]] size_t find_peak() const noexcept Defined at audio/data.hpp:760
function for_channel(Fn &&) ¶
template <std::invocable<univector_ref<fbase>> Fn>
void for_channel(Fn&& fn) Applies a given function to the audio data for each channel.
This function iterates over the audio channels and applies the provided function object fn to the data. The behavior depends on whether the audio data is interleaved or not:- If the data is interleaved, the function is called once with a single univector containing all the interleaved data. - If the data is not interleaved, the function is called for each channel separately with a univector containing the data for that specific channel.
| Fn | The type of the function object to be applied. |
| fn | The function object to be applied to the audio data. It should accept a univector as its argument. |
Defined at audio/data.hpp:809
Defined at audio/data.hpp:455