sfFDN
Loading...
Searching...
No Matches
audio_buffer.h
1// Copyright (C) 2025 Alexandre St-Onge
2// SPDX-License-Identifier: MIT
3#pragma once
4
5#include <cstddef>
6#include <cstdint>
7#include <iterator>
8#include <span>
9
10namespace sfFDN
11{
18{
19 public:
22
24 explicit AudioBuffer(std::span<float> buffer);
25
33 AudioBuffer(uint32_t frame_size, uint32_t channels, std::span<float> buffer);
34
39 uint32_t SampleCount() const;
40
45 uint32_t ChannelCount() const;
46
51 float* Data();
52
57 const float* Data() const;
58
64 std::span<const float> GetChannelSpan(uint32_t channel) const;
65
71 std::span<float> GetChannelSpan(uint32_t channel);
72
78 AudioBuffer GetChannelBuffer(uint32_t channel) const;
79
81 AudioBuffer Offset(uint32_t offset, uint32_t frame_size) const;
82
83 private:
84 uint32_t frame_size_;
85 uint32_t channel_count_;
86 std::span<float> buffer_;
87
88 uint32_t offset_;
89 uint32_t chunk_size_;
90};
91} // namespace sfFDN
A class representing an audio buffer with multiple channels of non-interleaved audio data.
Definition audio_buffer.h:18
AudioBuffer GetChannelBuffer(uint32_t channel) const
Returns an AudioBuffer object representing the audio data for a specific channel.
uint32_t SampleCount() const
Returns the number of samples in one channel of the audio buffer.
AudioBuffer(std::span< float > buffer)
Constructs a mono audio buffer.
const float * Data() const
Provides direct access to the audio data.
uint32_t ChannelCount() const
Returns the number of channels in the audio buffer.
AudioBuffer()
Constructs an empty audio buffer.
std::span< float > GetChannelSpan(uint32_t channel)
Returns a span representing the audio data for a specific channel.
float * Data()
Provides direct access to the audio data.
std::span< const float > GetChannelSpan(uint32_t channel) const
Returns a span representing the audio data for a specific channel.
AudioBuffer(uint32_t frame_size, uint32_t channels, std::span< float > buffer)
Constructs a multi-channel audio buffer.
AudioBuffer Offset(uint32_t offset, uint32_t frame_size) const
Returns a new AudioBuffer where every channel is offset by a certain number of samples.