vsdk 8.1.0
 
Loading...
Searching...
No Matches
Vsdk::Audio::Buffer

16-bit PCM audio buffer used for all audio operations More...

#include <Buffer.hpp>

Public Member Functions

 Buffer () noexcept
 Default constructs an empty, 16kHz mono channel buffer.
 
 Buffer (int sampleRate, int channelCount)
 Constructs an empty buffer with specified sample rate and channel count.
 
 Buffer (int16_t const *data, std::size_t sz, int sampleRate, int channelCount)
 
 Buffer (std::vector< int16_t > data, int sampleRate, int channelCount)
 
 Buffer (std::vector< float > const &data, int sampleRate, int channelCount)
 Converts a floating-point audio buffer into a 16-bit audio buffer.
 
void append (std::vector< int16_t > const &data)
 
void append (int16_t const *data, std::size_t sz)
 
auto sampleRate () const -> int
 
auto channelCount () const -> int
 
auto maxSize () const -> std::size_t
 
auto size () const -> std::size_t
 
auto data () const -> std::vector< int16_t > const &
 
auto data () -> std::vector< int16_t > &
 
auto rawData () -> int16_t *
 
auto rawData () const -> int16_t const *
 
auto takeData () -> std::vector< int16_t > &&
 
bool empty () const
 
void clear ()
 
void setMaxSize (std::size_t sz)
 Sets the maximum amount of int16_t values this buffer can hold.
 
void setSampleRate (int rate)
 
void setChannelCount (int count)
 
void saveToFile (std::string const &path, bool truncate=true) const
 Saves the buffer to a headerless (PCM) 16-bit audio file.
 

Detailed Description

16-bit PCM audio buffer used for all audio operations

Constructor & Destructor Documentation

◆ Buffer() [1/5]

Buffer::Buffer ( )
noexcept

Default constructs an empty, 16kHz mono channel buffer.

◆ Buffer() [2/5]

Buffer::Buffer ( int  sampleRate,
int  channelCount 
)

Constructs an empty buffer with specified sample rate and channel count.

◆ Buffer() [3/5]

Buffer::Buffer ( int16_t const *  data,
std::size_t  sz,
int  sampleRate,
int  channelCount 
)
Warning
Don't pass nullptr into data! Use Buffer(int, int) instead

◆ Buffer() [4/5]

Buffer::Buffer ( std::vector< int16_t >  data,
int  sampleRate,
int  channelCount 
)

◆ Buffer() [5/5]

Buffer::Buffer ( std::vector< float > const &  data,
int  sampleRate,
int  channelCount 
)

Converts a floating-point audio buffer into a 16-bit audio buffer.

Warning
This is - by nature - a lossy operation!

Member Function Documentation

◆ append() [1/2]

void Buffer::append ( std::vector< int16_t > const &  data)

◆ append() [2/2]

void Buffer::append ( int16_t const *  data,
std::size_t  sz 
)

◆ sampleRate()

auto Buffer::sampleRate ( ) const -> int

◆ channelCount()

auto Buffer::channelCount ( ) const -> int

◆ maxSize()

auto Buffer::maxSize ( ) const -> std::size_t

◆ size()

auto Buffer::size ( ) const -> std::size_t

◆ data() [1/2]

auto Buffer::data ( ) const -> std::vector<int16_t> const &

◆ data() [2/2]

auto Buffer::data ( ) -> std::vector<int16_t> &

◆ rawData() [1/2]

auto Buffer::rawData ( ) -> int16_t *

◆ rawData() [2/2]

auto Buffer::rawData ( ) const -> int16_t const *

◆ takeData()

auto Buffer::takeData ( ) -> std::vector<int16_t> &&

◆ empty()

bool Buffer::empty ( ) const

◆ clear()

void Buffer::clear ( )

◆ setMaxSize()

void Buffer::setMaxSize ( std::size_t  sz)

Sets the maximum amount of int16_t values this buffer can hold.

Note
  • 0 means unlimited (std::vector::max_size()) ;
  • Any other value turns this buffer into a circular buffer ;
  • This is not a strict limit, the buffer can go past it sometimes ;
  • Reducing a previously set size is Undefined Behavior.
Exceptions
Vsdk::Exceptionif sz > std::vector::max_size()

◆ setSampleRate()

void Buffer::setSampleRate ( int  rate)

◆ setChannelCount()

void Buffer::setChannelCount ( int  count)

◆ saveToFile()

void Buffer::saveToFile ( std::string const &  path,
bool  truncate = true 
) const

Saves the buffer to a headerless (PCM) 16-bit audio file.