VAE - Virtual Audio Engine 1
Small Data Driven Audio Engine
|
Class for handling the most basic audio needs. More...
#include <TAudioBuffer.hpp>
Public Types | |
using | Sample = T |
using | Storage = STORAGE |
using | uchar = unsigned char |
using | ushort = unsigned short |
using | uint = unsigned int |
using | Size = typename Storage::Size |
Public Member Functions | |
AudioBufferTpl () | |
Empty buffer with no memory allocated yet. More... | |
AudioBufferTpl (const Size length, const uchar channels) | |
Buffer with memory allocated. More... | |
~AudioBufferTpl () | |
AudioBufferTpl (AudioBufferTpl &&source)=default | |
move contructor is implicitly deleted Don't know why More... | |
AudioBufferTpl & | operator= (AudioBufferTpl &&source)=default |
AudioBufferTpl & | operator= (const AudioBufferTpl &)=delete |
AudioBufferTpl (const AudioBufferTpl &)=delete | |
AudioBufferTpl (const AudioBufferTpl *)=delete | |
template<typename T2 > | |
void | set (const T2 *samples, Size length, const uchar channel=0, const Size offsetDst=0) |
Set a single channel from an array. More... | |
template<typename T2 > | |
void | set (T2 **const samples, const Size length, const uchar channels, const Size offsetSrc=0, const Size offsetDst=0) |
Set multiple channels from a 2D array. More... | |
template<typename T2 , class STORAGE2 > | |
void | set (const AudioBufferTpl< T2, STORAGE2 > &buffer, Size length=0, const Size offsetSrc=0, const Size offsetDst=0) |
Set from another buffer object, will not adjust size and channel count! Use clone() instead. More... | |
void | set (T value=0, Size length=0, const Size offsetDst=0) |
Set the entire buffer to a constant value. More... | |
template<typename T2 > | |
void | setFromInterleaved (const T2 *samples, Size length, const uchar channels, Size offsetSrc=0, const Size offsetDst=0) |
Set multiple channels from an interleaved array. More... | |
template<typename T2 , class STORAGE2 > | |
void | clone (const AudioBufferTpl< T2, STORAGE2 > &buffer) |
Match the size of the provided buffer and copy the contents. More... | |
bool | resize (const Size length, uchar channels) |
! Will not keep the contents! Resizes the buffer to the desired length and channel count. More... | |
void | resize (const Size length) |
Resize to the provided length and keep the channelcount. More... | |
template<typename T2 , class STORAGE2 > | |
void | resize (const AudioBufferTpl< T2, STORAGE2 > &buffer) |
Resize to match the provided buffer. More... | |
template<typename T2 , class STORAGE2 > | |
void | add (const AudioBufferTpl< T2, STORAGE2 > &buffer, Size length=0, Size offsetSrc=0, Size offsetDst=0) |
Add the provided buffer. More... | |
template<typename T2 , class STORAGE2 > | |
void | multiply (const AudioBufferTpl< T2, STORAGE2 > &buffer, Size length=0, Size offsetSrc=0, Size offsetDst=0) |
Multiply two buffers. More... | |
void | multiply (T value) |
Mutliplies the content of the buffer with a constant. More... | |
void | add (T value) |
Adds a constant to the contents of the buffer. More... | |
bool | inject (T *mem, const Size size, const uchar channels) |
Inject forgeign memory to be used by the buffer. More... | |
bool | inject (const T *mem, const Size size, const uchar channels) |
Inject const forgeign memory to be used by the buffer. More... | |
uchar | channels () const |
Returns the amount of channels. More... | |
Size | size () const |
Returns the allocated length of the buffer. More... | |
Size | validSize () const |
Returns the length of actually valid audio in the buffer. More... | |
void | setValidSize (const Size v) |
Set the amount of valid samples currently in the buffer This is mostly a convenience flag since the actual size of the buffer may be larger. More... | |
T * | get (const uchar channel) |
const T * | get (const uchar channel) const |
const T * | operator[] (const uchar channel) const |
T * | operator[] (const uchar channel) |
void | getRaw (T **put) |
Fills an 2d array of size maxChannels() with pointers to each channel. More... | |
void | getRaw (const T **put) const |
Fills an 2d array of size maxChannels() with pointers to each channel. More... | |
template<typename T2 > | |
Size | put (T2 *target, Size length=0, const uchar channel=0, const Size offset=0) const |
Fill the provided array with the contents of this buffer. More... | |
template<typename T2 > | |
Size | put (T2 **target, const Size length=0, uchar channels=0, const Size offset=0) const |
Fill the provided 2D array with the contents of this buffer. More... | |
template<typename T2 > | |
Size | putInterleaved (T2 *buffer, Size length=0, const Size offset=0) const |
Puts the interleaved contents in the target buffer. More... | |
Static Public Member Functions | |
template<typename T2 > | |
static constexpr bool | needsScaling () |
Figure out if conversions between types like float -> int or int -> short need scaling applied. More... | |
template<typename T1 , typename T2 , typename Ratio = float> | |
static constexpr Ratio | getConversionScale () |
calculate the scale factor needed between the types More... | |
Public Attributes | |
ushort | sampleRate = 0 |
Only relevant for resampling and oversampling. More... | |
Static Public Attributes | |
static constexpr Size | Stride = xsimd::simd_type<T>::size |
Private Member Functions | |
void | assertOnConstMem () |
Private Attributes | |
Storage | mBuffer |
Size | mValidSize = 0 |
uchar | mChannels = 0 |
Class for handling the most basic audio needs.
Does convenient type conversions TODO check if using a single buffer instead of one for each channel improves performance
T | Sample type. Can be anything std::is_arithmetic |
STORAGE | Storage type, tklb::HeapBuffer for now since there are a few things missing in a std::vector |
Definition at line 36 of file TAudioBuffer.hpp.
using tklb::AudioBufferTpl< T, STORAGE >::Sample = T |
Definition at line 39 of file TAudioBuffer.hpp.
using tklb::AudioBufferTpl< T, STORAGE >::Size = typename Storage::Size |
Definition at line 44 of file TAudioBuffer.hpp.
using tklb::AudioBufferTpl< T, STORAGE >::Storage = STORAGE |
Definition at line 40 of file TAudioBuffer.hpp.
using tklb::AudioBufferTpl< T, STORAGE >::uchar = unsigned char |
Definition at line 41 of file TAudioBuffer.hpp.
using tklb::AudioBufferTpl< T, STORAGE >::uint = unsigned int |
Definition at line 43 of file TAudioBuffer.hpp.
using tklb::AudioBufferTpl< T, STORAGE >::ushort = unsigned short |
Definition at line 42 of file TAudioBuffer.hpp.
|
inline |
|
inline |
Buffer with memory allocated.
Definition at line 70 of file TAudioBuffer.hpp.
|
inline |
Definition at line 74 of file TAudioBuffer.hpp.
|
default |
move contructor is implicitly deleted Don't know why
|
delete |
|
delete |
|
inline |
Add the provided buffer.
buffer | Source buffer object |
length | Samples to add from the source buffer |
offsetSrc | Start offset in the source buffer |
offsetDst | Start offset in the target buffer |
Definition at line 318 of file TAudioBuffer.hpp.
|
inline |
Adds a constant to the contents of the buffer.
value |
Definition at line 441 of file TAudioBuffer.hpp.
|
inlineprivate |
|
inline |
Returns the amount of channels.
Definition at line 505 of file TAudioBuffer.hpp.
|
inline |
Match the size of the provided buffer and copy the contents.
Definition at line 264 of file TAudioBuffer.hpp.
|
inline |
|
inline |
Definition at line 535 of file TAudioBuffer.hpp.
|
inlinestaticconstexpr |
calculate the scale factor needed between the types
T1 | Source type |
T2 | target type |
Ratio | Floating point type since the value can be smaller than 1 |
Definition at line 114 of file TAudioBuffer.hpp.
|
inline |
Fills an 2d array of size maxChannels() with pointers to each channel.
put | Pointers go here |
Definition at line 559 of file TAudioBuffer.hpp.
|
inline |
Fills an 2d array of size maxChannels() with pointers to each channel.
put | Pointers go here |
Definition at line 548 of file TAudioBuffer.hpp.
|
inline |
Inject const forgeign memory to be used by the buffer.
Potentially dangerous but useful when splitting up channels for processing
mem | Const memory (No type conversions here) |
size | Size of the entire buffer |
channels | How many channels are contained in mem |
Definition at line 491 of file TAudioBuffer.hpp.
|
inline |
Inject forgeign memory to be used by the buffer.
Potentially dangerous but useful when splitting up channels for processing
mem | Modifiable memory (No type conversions here) |
size | Size of the entire buffer |
channels | How many channels are contained in mem |
Definition at line 473 of file TAudioBuffer.hpp.
|
inline |
Multiply two buffers.
buffer | Source buffer object |
length | Samples to multiply from the source buffer |
offsetIn | Start offset in the source buffer |
offset | Start offset in the target buffer |
Definition at line 367 of file TAudioBuffer.hpp.
|
inline |
Mutliplies the content of the buffer with a constant.
value | Constant to multiply the buffer with |
Definition at line 412 of file TAudioBuffer.hpp.
|
inlinestaticconstexpr |
Figure out if conversions between types like float -> int or int -> short need scaling applied.
T2 | Other type compared to own type |
Definition at line 99 of file TAudioBuffer.hpp.
|
default |
|
delete |
|
inline |
|
inline |
|
inline |
Fill the provided 2D array with the contents of this buffer.
target | The array to fill |
channels | How many channels there are in the target buffer |
length | The length of the output |
Definition at line 612 of file TAudioBuffer.hpp.
|
inline |
Fill the provided array with the contents of this buffer.
target | The arry to fill |
channel | Which source channel to use |
length | The length of the output |
offset | Start offset in the source (this) buffer |
Definition at line 574 of file TAudioBuffer.hpp.
|
inline |
Puts the interleaved contents in the target buffer.
buffer | The array to fill with interleaved audio |
length | Number of frames to interleave (not the length of the interleaved buffer) |
offset | Offset for the sourcebuffer (this) |
Definition at line 634 of file TAudioBuffer.hpp.
|
inline |
Resize to match the provided buffer.
Definition at line 306 of file TAudioBuffer.hpp.
|
inline |
Resize to the provided length and keep the channelcount.
If the channel count was 0 it will assume 1 channel instead.
length | The desired length in samples. 0 will deallocate. |
Definition at line 298 of file TAudioBuffer.hpp.
|
inline |
! Will not keep the contents! Resizes the buffer to the desired length and channel count.
If the validSize = 0 it will be set to the new size for convenience. The size reported back when calling size is can be larger if the data is aligned
length | The desired length in Samples. 0 will deallocate. |
channels | Desired channel count. 0 will deallocate. |
Definition at line 276 of file TAudioBuffer.hpp.
|
inline |
Set from another buffer object, will not adjust size and channel count! Use clone() instead.
e.g. offset=10 and length=15 will copy 15 samples into the buffer starting at the 10th sample
buffer | Source buffer object |
length | Samples to copy in |
offsetSrc | Start offset in the source buffer |
offsetDst | Start offset in the target buffer |
Definition at line 193 of file TAudioBuffer.hpp.
|
inline |
Set a single channel from an array.
samples | An Array containing the audio samples |
length | Amount of sample to copy |
channel | Channel index |
offsetDst | The offset for the destination buffer (this) |
Definition at line 130 of file TAudioBuffer.hpp.
|
inline |
Set the entire buffer to a constant value.
value | Value to fill the buffer with |
length | Samples to set. 0 Sets all |
offsetDst | Start offset in the target buffer |
Definition at line 211 of file TAudioBuffer.hpp.
|
inline |
Set multiple channels from a 2D array.
samples | A 2D Array containing the audio samples (float or double) |
length | Samples to copy in (single channel) |
channels | Channel count |
offsetSrc | Offset in the source buffer |
offsetDst | Offset in the destination buffer |
Definition at line 170 of file TAudioBuffer.hpp.
|
inline |
Set multiple channels from an interleaved array.
samples | A 1D Array containing the interleaved audio samples (float or double) |
length | The length of a single channel |
channels | Channel count |
offsetSrc | Start offset in the source buffer |
offsetDst | Start offset in the target buffer |
Definition at line 232 of file TAudioBuffer.hpp.
|
inline |
Set the amount of valid samples currently in the buffer This is mostly a convenience flag since the actual size of the buffer may be larger.
Definition at line 524 of file TAudioBuffer.hpp.
|
inline |
Returns the allocated length of the buffer.
Definition at line 510 of file TAudioBuffer.hpp.
|
inline |
Returns the length of actually valid audio in the buffer.
TODO tklb make sure this is used consistently
Definition at line 518 of file TAudioBuffer.hpp.
|
private |
Definition at line 51 of file TAudioBuffer.hpp.
|
private |
Definition at line 53 of file TAudioBuffer.hpp.
|
private |
Definition at line 52 of file TAudioBuffer.hpp.
ushort tklb::AudioBufferTpl< T, STORAGE >::sampleRate = 0 |
Only relevant for resampling and oversampling.
TODO higher sample rates wont work, maybe use enum
Definition at line 60 of file TAudioBuffer.hpp.
|
staticconstexpr |
Definition at line 47 of file TAudioBuffer.hpp.