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_core/SwitchboardCore.hpp>
12
13namespace switchboard {
14
20template <typename T>
21class AudioBuffer final {
22public:
23 SB_WASM_EXPORT(AudioBuffer)
24
25
34 SB_WASM AudioBuffer(uint numberOfChannels, uint numberOfFrames, bool isInterleaved, uint sampleRate, T** data);
35
44 AudioBuffer(uint numberOfChannels, uint numberOfFrames, uint sampleRate, T* data);
45
51 SB_WASM uint getNumberOfChannels() const;
52
58 SB_WASM uint getNumberOfFrames() const;
59
65 SB_WASM void setNumberOfFrames(const uint newNumberOfFrames);
66
72 SB_WASM bool getIsInterleaved() const;
73
79 SB_WASM uint getSampleRate() const;
80
86 SB_WASM void setSampleRate(const uint newSampleRate);
87
93 SB_WASM bool isMono() const;
94
103 SB_WASM T getSample(uint channel, uint sampleIndex) const;
104
112 SB_WASM void setSample(uint channel, uint sampleIndex, T value);
113
121 SB_WASM const T* getReadPointer(uint channel) const;
122
130 SB_WASM T* getWritePointer(uint channel);
131
137 const T** getReadPointer() const;
138
145
152 void copyFrom(const AudioBuffer<T>& srcBuffer);
153
157 void clear();
158
159private:
160 uint numberOfChannels;
161 uint numberOfFrames;
162 bool isInterleaved;
163 uint sampleRate;
164 T** data;
165 T* channelData;
166
167 uint getBufferSizeBytes() const;
168 uint getNumberOfBuffers() const;
169};
170
171}
SB_WASM const T * getReadPointer(uint channel) const
Returns a read pointer to the data for a channel in the audio buffer.
SB_WASM uint getNumberOfFrames() const
Returns the number of frames stored in the audio buffer.
SB_WASM void setSample(uint channel, uint sampleIndex, T value)
Sets a sample value in the audio buffer.
SB_WASM bool getIsInterleaved() const
Returns whether the audio buffer contains interleaved or non-interleaved data. Always false if the au...
SB_WASM T getSample(uint channel, uint sampleIndex) const
Returns a sample value from the audio buffer.
SB_WASM bool isMono() const
Returns whether the audio buffer is mono.
SB_WASM void setNumberOfFrames(const uint newNumberOfFrames)
Sets the number of frames in the buffer.
void copyFrom(const AudioBuffer< T > &srcBuffer)
Copies data from another AudioBuffer instance.
SB_WASM AudioBuffer(uint numberOfChannels, uint numberOfFrames, bool isInterleaved, uint sampleRate, T **data)
Creates an AudioBuffer instance from already allocated memory.
SB_WASM void setSampleRate(const uint newSampleRate)
Sets the sample rate of the audio buffer.
void clear()
Sets all audio sample values to zero.
SB_WASM T * getWritePointer(uint channel)
Returns a write pointer to the data for a channel in the audio buffer.
SB_WASM uint getNumberOfChannels() const
Returns the number of channels stored in the audio buffer.
SB_WASM uint getSampleRate() const
Gets the sample rate of the audio buffer.