Switchboard Extension SDK
Loading...
Searching...
No Matches
AudioBuffer.hpp
1//
2// AudioBuffer.hpp
3// SwitchboardSDK
4//
5// Created by Balázs Kiss on 2022. 02. 22..
6// Copyright © 2022. Synervoz Inc. All rights reserved.
7//
8
9#pragma once
10
11#include <switchboard/export.h>
12#include <switchboard_core/SwitchboardCore.hpp>
13
14namespace switchboard {
15
21template <typename T>
22class SWITCHBOARDSDK_EXPORT AudioBuffer final {
23public:
33 AudioBuffer(uint numberOfChannels, uint numberOfFrames, bool isInterleaved, uint sampleRate, T** data);
34
43 AudioBuffer(uint numberOfChannels, uint numberOfFrames, uint sampleRate, T* data);
44
50 uint getNumberOfChannels() const;
51
57 uint getNumberOfFrames() const;
58
64 void setNumberOfFrames(const uint newNumberOfFrames);
65
71 bool getIsInterleaved() const;
72
78 uint getSampleRate() const;
79
85 void setSampleRate(const uint newSampleRate);
86
92 bool isMono() const;
93
102 T getSample(uint channel, uint sampleIndex) const;
103
111 void setSample(uint channel, uint sampleIndex, T value);
112
120 const T* getReadPointer(uint channel) const;
121
129 T* getWritePointer(uint channel);
130
136 const T** getReadPointer() const;
137
144
151 void copyFrom(const AudioBuffer<T>& srcBuffer);
152
156 void clear();
157
158private:
159 uint numberOfChannels;
160 uint numberOfFrames;
161 bool isInterleaved;
162 uint sampleRate;
163 T** data;
164 T* channelData;
165
166 uint getBufferSizeBytes() const;
167 uint getNumberOfBuffers() const;
168};
169
170}
uint getNumberOfFrames() const
Returns the number of frames stored in the audio buffer.
T * getWritePointer(uint channel)
Returns a write pointer to the data for a channel in the audio buffer.
T ** getWritePointer()
Returns a write pointer to the data in the audio buffer.
uint getSampleRate() const
Gets the sample rate of the audio buffer.
AudioBuffer(uint numberOfChannels, uint numberOfFrames, bool isInterleaved, uint sampleRate, T **data)
Creates an AudioBuffer instance from already allocated memory.
T getSample(uint channel, uint sampleIndex) const
Returns a sample value from the audio buffer.
void setNumberOfFrames(const uint newNumberOfFrames)
Sets the number of frames in the buffer.
void setSampleRate(const uint newSampleRate)
Sets the sample rate of the audio buffer.
bool getIsInterleaved() const
Returns whether the audio buffer contains interleaved or non-interleaved data. Always false if the au...
bool isMono() const
Returns whether the audio buffer is mono.
const T ** getReadPointer() const
Returns a read pointer to the data in the audio buffer.
void copyFrom(const AudioBuffer< T > &srcBuffer)
Copies data from another AudioBuffer instance.
AudioBuffer(uint numberOfChannels, uint numberOfFrames, uint sampleRate, T *data)
Creates a mono or interleaved AudioBuffer instance from already allocated memory.
void clear()
Sets all audio sample values to zero.
void setSample(uint channel, uint sampleIndex, T value)
Sets a sample value in the audio buffer.
const T * getReadPointer(uint channel) const
Returns a read pointer to the data for a channel in the audio buffer.
uint getNumberOfChannels() const
Returns the number of channels stored in the audio buffer.