![]() |
Gorgon Game Engine
|
This is sound resource. More...
Public Member Functions | |
Sound () | |
Default constructor. More... | |
virtual | ~Sound () |
Destructor. More... | |
void | Assign (const Containers::Wave &wave) |
Assigns the sound to the copy of the given data. More... | |
void | Assume (Containers::Wave &wave) |
Assumes the contents of the given wave as wave data. More... | |
void | Destroy () |
Destroys the data stored in the sound. More... | |
int | GetBits () const |
GID::Type | GetCompression () const |
Returns the compression type of this resource. More... | |
virtual GID::Type | GetGID () const override |
04010000h (Extended, Sound) More... | |
Containers::Wave & | GetWave () |
const Containers::Wave & | GetWave () const |
bool | IsLoaded () const |
Returns whether the sound data is loaded. More... | |
bool | IsPCM () const |
Returns if the wave data will be saved as PCM data. More... | |
bool | Load () |
Loads the sound from the disk. If sound is already loaded, this function will return true. More... | |
void | SetBits (int bits) |
Sets the number of bits per sample. More... | |
void | SetCompression (GID::Type compression) |
Changes the compression type of this resource. More... | |
void | SetPCM (bool pcm) |
Set whether the wave data should be saved in PCM format. More... | |
![]() | |
Base () | |
Default constructor. More... | |
const Containers::Collection< Base >::ConstIterator | begin () const |
Allows easy iteration through range based fors. More... | |
const Containers::Collection< Base >::ConstIterator | cbegin () const |
Beginning of children. More... | |
const Containers::Collection< Base >::ConstIterator | cend () const |
End of children. More... | |
bool | DeleteResource () |
Safely deletes the resource. More... | |
virtual void | Discard () |
This function shall discard any transitional data which is not vital after Prepare function is issued. More... | |
const Containers::Collection< Base >::ConstIterator | end () const |
Allows easy iteration through range based fors. More... | |
virtual SGuid | GetGuid () const |
Returns the guid of the object. More... | |
const std::string & | GetName () const |
Returns the name of this object. More... | |
Base & | GetParent () const |
Returns the parent. If no parent set, this function throws std::runtime_error. More... | |
Base * | GetParentPtr () const |
Returns the pointer to the parent. This function may return nullptr. More... | |
const Base & | GetRoot () const |
Returns the root of this resource. More... | |
bool | HasParent () const |
Returns whether this object has a parent. More... | |
virtual bool | IsEqual (const SGuid &guid) const |
This function tests whether this object has the given SGuid. More... | |
virtual void | Prepare () |
This function shall prepare this resource to be used after resource is loaded. More... | |
virtual void | Resolve (File &file) |
This function shall resolve links or similar constructs. More... | |
void | Save (Writer &writer) |
Saves this object into the given writer. The writer should be open prior to this call. More... | |
virtual void | SetGuid (SGuid guid) |
Changes the guid of the object. More... | |
virtual void | SetName (const std::string &name) |
Sets the name of the object. More... | |
Static Public Member Functions | |
static Sound * | LoadResource (std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size) |
This function loads a sound resource from the given file. More... | |
Protected Member Functions | |
void | checkfmt () const |
Checks if the format of the file is well-formed. More... | |
bool | load (std::shared_ptr< Reader > reader, unsigned long size, bool forceload) |
Loads the sound from the data stream. More... | |
void | save (Writer &writer) const override |
![]() | |
virtual | ~Base () |
Destructor, Always children gets destroyed first. More... | |
void | destroychildren () |
Destroys the children of this resource. More... | |
void | setparenttonullptr (Base &base) |
Sets the parent of an object to nullptr, provides access. More... | |
Protected Attributes | |
int | bits |
Number of bits per sample. More... | |
GID::Type | compression |
Compression mode of this sound resource. More... | |
Containers::Wave | data |
Sound data. More... | |
unsigned long | entrypoint |
Entry point of this resource within the physical file. More... | |
bool | isloaded |
Whether this sound is loaded or not. More... | |
bool | lateloading |
Whether to load this sound during initial loading. More... | |
bool | pcm |
std::shared_ptr< Reader > | reader |
Used to handle late loading. More... | |
![]() | |
Containers::Collection< Base > | children |
Child objects that this resource object have. More... | |
SGuid | guid |
SGuid to identify this resource object. More... | |
std::string | name |
Name of this resource object, may not be loaded. More... | |
Base * | parent |
Immediate parent of this resource. More... | |
const Base * | root |
Root of this resource. More... | |
Additional Inherited Members | |
![]() | |
const Containers::Collection< Base > & | Children |
The children this object have. More... | |
unsigned long | refcount |
INTERNAL, Reference count, used in linking mechanism. More... | |
This is sound resource.
It may contain 22kHz or 44kHz mono or stereo wave files. Also supports LZMA compression. No native sound compression is supported.
Sound | ( | ) |
Default constructor.
|
virtual |
Destructor.
void Assign | ( | const Containers::Wave & | wave | ) |
Assigns the sound to the copy of the given data.
Ownership of the given data is not transferred. If the given data is not required elsewhere, consider using Assume function. Also sets IsLoaded.
References Sound::data, Wave::Duplicate(), and Sound::isloaded.
void Assume | ( | Containers::Wave & | wave | ) |
Assumes the contents of the given wave as wave data.
The given parameter is moved from and will become empty. Also sets IsLoaded.
References Sound::data, and Sound::isloaded.
|
protected |
Checks if the format of the file is well-formed.
References Sound::bits, Sound::compression, Gorgon::Resource::GID::FLAC, Gorgon::Resource::GID::None, and Sound::pcm.
void Destroy | ( | ) |
Destroys the data stored in the sound.
References Sound::isloaded.
int GetBits | ( | ) | const |
References Sound::bits.
GID::Type GetCompression | ( | ) | const |
Returns the compression type of this resource.
References Sound::compression.
|
overridevirtual |
Containers::Wave& GetWave | ( | ) |
References Sound::data.
const Containers::Wave& GetWave | ( | ) | const |
References Sound::data.
bool IsLoaded | ( | ) | const |
Returns whether the sound data is loaded.
References Sound::isloaded.
bool IsPCM | ( | ) | const |
Returns if the wave data will be saved as PCM data.
References Sound::pcm.
bool Load | ( | ) |
Loads the sound from the disk. If sound is already loaded, this function will return true.
References Sound::entrypoint, Sound::isloaded, Sound::load(), and Sound::reader.
|
protected |
Loads the sound from the data stream.
References Gorgon::Utils::ASSERT_FALSE(), Sound::bits, Sound::checkfmt(), Sound::compression, Sound::data, FLAC::Decode(), Wave::Destroy(), Sound::entrypoint, Gorgon::Encoding::Flac, Gorgon::Resource::GID::FLAC, Gorgon::String::From(), Wave::GetChannelCount(), Wave::GetSize(), Sound::isloaded, Sound::lateloading, Gorgon::Resource::GID::None, Sound::pcm, Wave::RawData(), Sound::reader, Wave::Resize(), Wave::SetChannels(), Wave::SetSampleRate(), Gorgon::Resource::GID::Sound_Channels, Gorgon::Resource::GID::Sound_Cmp_Wave, Gorgon::Resource::GID::Sound_Fmt, Gorgon::Resource::GID::Sound_Props, Gorgon::Resource::GID::Sound_Wave, Gorgon::Audio::StandardChannels(), and LoadError::UnsupportedCompression.
|
static |
This function loads a sound resource from the given file.
References Sound::Sound(), and Sound::reader.
|
overrideprotectedvirtual |
Implements Base.
References Sound::bits, Sound::compression, Sound::data, FLAC::Encode(), Gorgon::Encoding::Flac, Gorgon::Resource::GID::FLAC, Gorgon::String::From(), Wave::Get(), Wave::GetBytes(), Wave::GetChannelCount(), Wave::GetChannelType(), Wave::GetSampleRate(), Wave::GetSize(), Writer::GetStream(), Sound::lateloading, Gorgon::Resource::GID::None, Sound::pcm, Wave::RawData(), Gorgon::Resource::GID::Sound_Channels, Gorgon::Resource::GID::Sound_Cmp_Wave, Gorgon::Resource::GID::Sound_Fmt, Gorgon::Resource::GID::Sound_Wave, Writer::WriteArray(), Writer::WriteBool(), Writer::WriteChunkHeader(), Writer::WriteChunkStart(), Writer::WriteEnd(), Writer::WriteEnum32(), Writer::WriteGID(), Writer::WriteInt16(), Writer::WriteObjectStart(), Writer::WriteUInt32(), and Writer::WriteUInt8().
void SetBits | ( | int | bits | ) |
Sets the number of bits per sample.
Only effects saving, in memory format is non-PCM 32bit float. Currently this does not have effect if data is saved non-PCM fashion.
References Sound::bits, and Sound::checkfmt().
void SetCompression | ( | GID::Type | compression | ) |
Changes the compression type of this resource.
Currently GID::None and GID::FLAC is supported. If Flac support is disabled, GID::FLAC will cause a runtime_error during save.
References Sound::checkfmt(), and Sound::compression.
void SetPCM | ( | bool | pcm | ) |
Set whether the wave data should be saved in PCM format.
FLAC supports only PCM while internal saving mechanism can save wave non-PCM mode as 32bit float.
References Sound::checkfmt(), and Sound::pcm.
|
protected |
Number of bits per sample.
|
protected |
Compression mode of this sound resource.
|
protected |
Sound data.
|
protected |
Entry point of this resource within the physical file.
This value is stored for late loading purposes
|
protected |
Whether this sound is loaded or not.
|
protected |
Whether to load this sound during initial loading.
|
protected |
|
protected |
Used to handle late loading.