![]() |
Gorgon Game Engine
|
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... | |
Wave & | operator= (const Wave &)=delete |
Copy assignment is disabled. More... | |
Wave & | operator= (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::Channel > | channels |
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... | |
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.
Wave | ( | ) |
Constructs an empty wave data.
|
explicit |
Constructs a new wave data with the given number of samples and channels.
This constructor does not initialize data inside the wave
Move constructor.
References Wave::data, and Wave::Swap().
~Wave | ( | ) |
Destructor.
References Wave::Destroy().
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.
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.
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.
void Assume | ( | float * | newdata | ) |
References Wave::data.
void Assume | ( | float * | newdata, |
unsigned long | size | ||
) |
Assumes the ownership of the data.
References Wave::data, and Wave::size.
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.
Iterator begin | ( | ) |
References Wave::channels, and Wave::data.
void Clear | ( | ) |
Cleans the contents of the buffer by setting every byte it contains to 0.
References Wave::channels, Wave::data, and Wave::size.
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.
Wave Duplicate | ( | ) | const |
Duplicates this wave, essentially performing the work of copy constructor.
References Wave::channels, Wave::data, Wave::samplerate, and Wave::size.
Iterator end | ( | ) |
References Wave::channels, Wave::data, and Wave::size.
bool ExportWav | ( | const std::string & | filename, |
int | bits = 16 |
||
) |
Exports a PCM based wav file. Bits can be 8 or 16.
bool ExportWav | ( | std::ostream & | file, |
int | bits = 16 |
||
) |
Exports a PCM based wav file. Bits can be 8 or 16.
References Wave::data, Wave::end(), Wave::GetChannelCount(), Wave::GetSampleRate(), Wave::GetSize(), Gorgon::IO::WriteInt16(), Gorgon::IO::WriteInt32(), Gorgon::IO::WriteString(), and Gorgon::IO::WriteUInt8().
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.
float Get | ( | unsigned long | p, |
unsigned | ch | ||
) | const |
Allows access to individual members.
References Wave::channels, Wave::data, and Wave::size.
unsigned long GetBytes | ( | ) | const |
Returns the size of the wave in bytes.
References Wave::channels, and Wave::size.
unsigned GetChannelCount | ( | ) | const |
Returns the number of channels that this wave data has.
References Wave::channels.
Audio::Channel GetChannelType | ( | int | channel | ) | const |
Returns the type of the channel at the given index.
References Wave::channels, and Gorgon::Audio::Unknown.
float GetLength | ( | ) | const |
Returns the length of the wave data in seconds.
References Wave::samplerate, and Wave::size.
unsigned GetSampleRate | ( | ) | const |
Returns the number of samples per second.
References Wave::samplerate.
unsigned long GetSize | ( | ) | const |
Returns the size of the wave.
References Wave::size.
bool ImportWav | ( | const std::string & | filename, |
std::vector< Audio::Channel > | channels = {} |
||
) |
Imports a PCM based wav file. Leave channels empty to determine them automatically.
bool ImportWav | ( | std::istream & | file, |
std::vector< Audio::Channel > | channels = {} |
||
) |
float& operator() | ( | unsigned long | p, |
unsigned | ch | ||
) |
Allows access to individual members.
References Wave::channels, Wave::data, and Wave::size.
float operator() | ( | unsigned long | p, |
unsigned | ch | ||
) | const |
Allows access to individual members.
References Wave::channels, Wave::data, and Wave::size.
Move assignment.
References Wave::Destroy(), and Wave::Swap().
float* RawData | ( | ) |
Returns the raw data pointer.
References Wave::data.
const float* RawData | ( | ) | const |
Returns the raw data pointer.
References Wave::data.
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().
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.
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.
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.
void SetSampleRate | ( | unsigned | rate | ) |
Sets the number samples per second.
References Wave::samplerate.
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().
|
protected |
Number of channels.
|
protected |
Data that stores pixels of the wave.
|
protected |
Sampling rate of the wave.
|
protected |
Number of samples in the wave.