Gorgon Game Engine
Sound Class Reference

This is sound resource. More...

Inheritance diagram for Sound:
[legend]

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::WaveGetWave ()
 
const Containers::WaveGetWave () 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...
 
- Public Member Functions inherited from Base
 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...
 
BaseGetParent () const
 Returns the parent. If no parent set, this function throws std::runtime_error. More...
 
BaseGetParentPtr () const
 Returns the pointer to the parent. This function may return nullptr. More...
 
const BaseGetRoot () 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 SoundLoadResource (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
 
- Protected Member Functions inherited from Base
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< Readerreader
 Used to handle late loading. More...
 
- Protected Attributes inherited from Base
Containers::Collection< Basechildren
 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...
 
Baseparent
 Immediate parent of this resource. More...
 
const Baseroot
 Root of this resource. More...
 

Additional Inherited Members

- Public Attributes inherited from Base
const Containers::Collection< Base > & Children
 The children this object have. More...
 
unsigned long refcount
 INTERNAL, Reference count, used in linking mechanism. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Sound()

Sound ( )

Default constructor.

◆ ~Sound()

virtual ~Sound ( )
virtual

Destructor.

Member Function Documentation

◆ Assign()

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.

◆ Assume()

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.

◆ checkfmt()

void checkfmt ( ) const
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.

◆ Destroy()

void Destroy ( )

Destroys the data stored in the sound.

References Sound::isloaded.

◆ GetBits()

int GetBits ( ) const

References Sound::bits.

◆ GetCompression()

GID::Type GetCompression ( ) const

Returns the compression type of this resource.

References Sound::compression.

◆ GetGID()

virtual GID::Type GetGID ( ) const
overridevirtual

04010000h (Extended, Sound)

Implements Base.

References Gorgon::Resource::GID::Sound.

◆ GetWave() [1/2]

Containers::Wave& GetWave ( )

References Sound::data.

◆ GetWave() [2/2]

const Containers::Wave& GetWave ( ) const

References Sound::data.

◆ IsLoaded()

bool IsLoaded ( ) const

Returns whether the sound data is loaded.

References Sound::isloaded.

◆ IsPCM()

bool IsPCM ( ) const

Returns if the wave data will be saved as PCM data.

References Sound::pcm.

◆ Load()

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.

◆ load()

◆ LoadResource()

Sound * LoadResource ( std::weak_ptr< File file,
std::shared_ptr< Reader reader,
unsigned long  size 
)
static

This function loads a sound resource from the given file.

References Sound::Sound(), and Sound::reader.

◆ save()

◆ SetBits()

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().

◆ SetCompression()

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.

◆ SetPCM()

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.

Member Data Documentation

◆ bits

int bits
protected

Number of bits per sample.

◆ compression

GID::Type compression
protected

Compression mode of this sound resource.

◆ data

Containers::Wave data
protected

Sound data.

◆ entrypoint

unsigned long entrypoint
protected

Entry point of this resource within the physical file.

This value is stored for late loading purposes

◆ isloaded

bool isloaded
protected

Whether this sound is loaded or not.

◆ lateloading

bool lateloading
protected

Whether to load this sound during initial loading.

◆ pcm

bool pcm
protected

◆ reader

std::shared_ptr<Reader> reader
protected

Used to handle late loading.


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