Gorgon Game Engine
Wave Class Reference

This class is a container for wave data. More...

Classes

class  Iterator
 Iterates the elements of a Wave. More...
 
class  Sample
 Represents a sample in the Wave data. More...
 

Public Member Functions

 Wave ()
 Constructs an empty wave data. More...
 
 Wave (const Wave &)=delete
 Copy constructor is disabled. More...
 
 Wave (unsigned long size, unsigned samplerate, std::vector< Audio::Channel > channels={Audio::Channel::Mono})
 Constructs a new wave data with the given number of samples and channels. More...
 
 Wave (Wave &&data)
 Move constructor. More...
 
 ~Wave ()
 Destructor. More...
 
void Assign (float *newdata)
 Copies the given data assigns the new data to this object, size is the number of samples. More...
 
void Assign (float *newdata, unsigned long size)
 Copies the given data assigns the new data to this object, size is the number of samples. More...
 
void Assign (float *newdata, unsigned long size, std::vector< Audio::Channel > channels)
 Copies the given data assigns the new data to this object, size is the number of samples. More...
 
void Assume (float *newdata)
 
void Assume (float *newdata, unsigned long size)
 Assumes the ownership of the data. More...
 
void Assume (float *newdata, unsigned long size, std::vector< Audio::Channel > channels)
 Assumes the ownership of the given data. More...
 
Iterator begin ()
 
void Clear ()
 Cleans the contents of the buffer by setting every byte it contains to 0. More...
 
void Destroy ()
 Destroys this wave by setting its size to 0 and freeing the memory used by its data. More...
 
Wave Duplicate () const
 Duplicates this wave, essentially performing the work of copy constructor. More...
 
Iterator end ()
 
bool ExportWav (const std::string &filename, int bits=16)
 Exports a PCM based wav file. Bits can be 8 or 16. More...
 
bool ExportWav (std::ostream &file, int bits=16)
 Exports a PCM based wav file. Bits can be 8 or 16. More...
 
int FindChannel (Audio::Channel channel) const
 Returns the index of the given channel. If the given channel does not exists, this function returns -1. More...
 
float Get (unsigned long p, unsigned ch) const
 Allows access to individual members. More...
 
unsigned long GetBytes () const
 Returns the size of the wave in bytes. More...
 
unsigned GetChannelCount () const
 Returns the number of channels that this wave data has. More...
 
Audio::Channel GetChannelType (int channel) const
 Returns the type of the channel at the given index. More...
 
float GetLength () const
 Returns the length of the wave data in seconds. More...
 
unsigned GetSampleRate () const
 Returns the number of samples per second. More...
 
unsigned long GetSize () const
 Returns the size of the wave. More...
 
bool ImportWav (const std::string &filename, std::vector< Audio::Channel > channels={})
 Imports a PCM based wav file. Leave channels empty to determine them automatically. More...
 
bool ImportWav (std::istream &file, std::vector< Audio::Channel > channels={})
 
float & operator() (unsigned long p, unsigned ch)
 Allows access to individual members. More...
 
float operator() (unsigned long p, unsigned ch) const
 Allows access to individual members. More...
 
Waveoperator= (const Wave &)=delete
 Copy assignment is disabled. More...
 
Waveoperator= (Wave &&other)
 Move assignment. More...
 
float * RawData ()
 Returns the raw data pointer. More...
 
const float * RawData () const
 Returns the raw data pointer. More...
 
float * Release ()
 Returns and disowns the current data buffer. If wave is empty, this method will return a nullptr. More...
 
void Resize (unsigned long size)
 Resizes the wave to the given size. More...
 
void Resize (unsigned long size, std::vector< Audio::Channel > channels)
 Resizes the wave to the given size and channels. More...
 
void SetChannels (std::vector< Audio::Channel > channels)
 Sets the channel assignment to this wave data. More...
 
void SetSampleRate (unsigned rate)
 Sets the number samples per second. More...
 
void Swap (Wave &other)
 Swaps this wave with another. This function is used to implement move semantics. More...
 

Protected Attributes

std::vector< Audio::Channelchannels
 Number of channels. More...
 
float * data
 Data that stores pixels of the wave. More...
 
unsigned samplerate
 Sampling rate of the wave. More...
 
unsigned long size
 Number of samples in the wave. More...
 

Detailed Description

This class is a container for wave data.

It supports different color modes and access to the underlying data through () operator. This object implements move semantics. Since copy constructor is expensive, it is deleted against accidental use. If a copy of the object is required, use Duplicate function.

Constructor & Destructor Documentation

◆ Wave() [1/4]

Wave ( )

Constructs an empty wave data.

◆ Wave() [2/4]

Wave ( unsigned long  size,
unsigned  samplerate,
std::vector< Audio::Channel channels = {Audio::Channel::Mono} 
)
explicit

Constructs a new wave data with the given number of samples and channels.

This constructor does not initialize data inside the wave

◆ Wave() [3/4]

Wave ( const Wave )
delete

Copy constructor is disabled.

◆ Wave() [4/4]

Wave ( Wave &&  data)

Move constructor.

References Wave::data, and Wave::Swap().

◆ ~Wave()

~Wave ( )

Destructor.

References Wave::Destroy().

Member Function Documentation

◆ Assign() [1/3]

void Assign ( float *  newdata)

Copies the given data assigns the new data to this object, size is the number of samples.

Assumes number of channels and samples stays the same. newdata should have size*channels number of entries

References Wave::channels, Wave::data, and Wave::size.

◆ Assign() [2/3]

void Assign ( float *  newdata,
unsigned long  size 
)

Copies the given data assigns the new data to this object, size is the number of samples.

Assumes number of channels stays the same. newdata should have size*channels number of entries

References Wave::channels, Wave::data, and Wave::size.

◆ Assign() [3/3]

void Assign ( float *  newdata,
unsigned long  size,
std::vector< Audio::Channel channels 
)

Copies the given data assigns the new data to this object, size is the number of samples.

newdata should have size*channels number of entries

References Wave::channels, Wave::data, and Wave::size.

◆ Assume() [1/3]

void Assume ( float *  newdata)

References Wave::data.

◆ Assume() [2/3]

void Assume ( float *  newdata,
unsigned long  size 
)

Assumes the ownership of the data.

References Wave::data, and Wave::size.

◆ Assume() [3/3]

void Assume ( float *  newdata,
unsigned long  size,
std::vector< Audio::Channel channels 
)

Assumes the ownership of the given data.

This variant changes the size and channels of the wave. The given data should have the size of size*channels. This function does not perform any checks for the data size while assuming it. newdata could be nullptr however, in this case size should be 0.

References Wave::channels, Wave::data, and Wave::size.

◆ begin()

Iterator begin ( )

References Wave::channels, and Wave::data.

◆ Clear()

void Clear ( )

Cleans the contents of the buffer by setting every byte it contains to 0.

References Wave::channels, Wave::data, and Wave::size.

◆ Destroy()

void Destroy ( )

Destroys this wave by setting its size to 0 and freeing the memory used by its data.

References Wave::data, and Wave::size.

◆ Duplicate()

Wave Duplicate ( ) const

Duplicates this wave, essentially performing the work of copy constructor.

References Wave::channels, Wave::data, Wave::samplerate, and Wave::size.

◆ end()

Iterator end ( )

◆ ExportWav() [1/2]

bool ExportWav ( const std::string &  filename,
int  bits = 16 
)

Exports a PCM based wav file. Bits can be 8 or 16.

◆ ExportWav() [2/2]

bool ExportWav ( std::ostream &  file,
int  bits = 16 
)

◆ FindChannel()

int FindChannel ( Audio::Channel  channel) const

Returns the index of the given channel. If the given channel does not exists, this function returns -1.

References Wave::channels.

◆ Get()

float Get ( unsigned long  p,
unsigned  ch 
) const

Allows access to individual members.

References Wave::channels, Wave::data, and Wave::size.

◆ GetBytes()

unsigned long GetBytes ( ) const

Returns the size of the wave in bytes.

References Wave::channels, and Wave::size.

◆ GetChannelCount()

unsigned GetChannelCount ( ) const

Returns the number of channels that this wave data has.

References Wave::channels.

◆ GetChannelType()

Audio::Channel GetChannelType ( int  channel) const

Returns the type of the channel at the given index.

References Wave::channels, and Gorgon::Audio::Unknown.

◆ GetLength()

float GetLength ( ) const

Returns the length of the wave data in seconds.

References Wave::samplerate, and Wave::size.

◆ GetSampleRate()

unsigned GetSampleRate ( ) const

Returns the number of samples per second.

References Wave::samplerate.

◆ GetSize()

unsigned long GetSize ( ) const

Returns the size of the wave.

References Wave::size.

◆ ImportWav() [1/2]

bool ImportWav ( const std::string &  filename,
std::vector< Audio::Channel channels = {} 
)

Imports a PCM based wav file. Leave channels empty to determine them automatically.

◆ ImportWav() [2/2]

bool ImportWav ( std::istream &  file,
std::vector< Audio::Channel channels = {} 
)

◆ operator()() [1/2]

float& operator() ( unsigned long  p,
unsigned  ch 
)

Allows access to individual members.

References Wave::channels, Wave::data, and Wave::size.

◆ operator()() [2/2]

float operator() ( unsigned long  p,
unsigned  ch 
) const

Allows access to individual members.

References Wave::channels, Wave::data, and Wave::size.

◆ operator=() [1/2]

Wave& operator= ( const Wave )
delete

Copy assignment is disabled.

◆ operator=() [2/2]

Wave& operator= ( Wave &&  other)

Move assignment.

References Wave::Destroy(), and Wave::Swap().

◆ RawData() [1/2]

float* RawData ( )

Returns the raw data pointer.

References Wave::data.

◆ RawData() [2/2]

const float* RawData ( ) const

Returns the raw data pointer.

References Wave::data.

◆ Release()

float* Release ( )

Returns and disowns the current data buffer. If wave is empty, this method will return a nullptr.

References Wave::data, and Wave::Destroy().

◆ Resize() [1/2]

void Resize ( unsigned long  size)

Resizes the wave to the given size.

This function discards the contents of the wave and does not perform any initialization. Previously set number of channels is used

References Wave::channels, Wave::data, and Wave::size.

◆ Resize() [2/2]

void Resize ( unsigned long  size,
std::vector< Audio::Channel channels 
)

Resizes the wave to the given size and channels.

This function discards the contents of the wave and does not perform any initialization.

References Wave::channels, Wave::data, and Wave::size.

◆ SetChannels()

void SetChannels ( std::vector< Audio::Channel channels)

Sets the channel assignment to this wave data.

This function should not change the number of channels, failing that would throw std::runtime_error

References Wave::channels, and Wave::size.

◆ SetSampleRate()

void SetSampleRate ( unsigned  rate)

Sets the number samples per second.

References Wave::samplerate.

◆ Swap()

void Swap ( Wave other)

Swaps this wave with another. This function is used to implement move semantics.

References Wave::channels, Wave::data, Wave::samplerate, Wave::size, and Gorgon::Containers::swap().

Member Data Documentation

◆ channels

std::vector<Audio::Channel> channels
protected

Number of channels.

◆ data

float* data
protected

Data that stores pixels of the wave.

◆ samplerate

unsigned samplerate
protected

Sampling rate of the wave.

◆ size

unsigned long size
protected

Number of samples in the wave.


The documentation for this class was generated from the following file: