Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::SoundBuffer Class Reference

Audio class that represents a buffer for sound. More...

Inheritance diagram for Nz::SoundBuffer:
Nz::RefCounted Nz::Resource

Public Member Functions

 SoundBuffer (AudioFormat format, UInt64 sampleCount, UInt32 sampleRate, const Int16 *samples)
 Constructs a SoundBuffer object. More...
 
 SoundBuffer (const SoundBuffer &)=delete
 
 SoundBuffer (SoundBuffer &&)=delete
 
 ~SoundBuffer ()
 Destructs the object and calls Destroy. More...
 
bool Create (AudioFormat format, UInt64 sampleCount, UInt32 sampleRate, const Int16 *samples)
 Creates the SoundBuffer object. More...
 
void Destroy ()
 Destroys the current sound buffer and frees resources.
 
UInt32 GetDuration () const
 Gets the duration of the sound buffer. More...
 
AudioFormat GetFormat () const
 Gets the format of the sound buffer. More...
 
const Int16 * GetSamples () const
 Gets the internal raw samples. More...
 
UInt64 GetSampleCount () const
 Gets the number of samples in the sound buffer. More...
 
UInt32 GetSampleRate () const
 Gets the rates of sample in the sound buffer. More...
 
bool IsValid () const
 Checks whether the sound buffer is valid. More...
 
bool LoadFromFile (const String &filePath, const SoundBufferParams &params=SoundBufferParams())
 Loads the sound buffer from file. More...
 
bool LoadFromMemory (const void *data, std::size_t size, const SoundBufferParams &params=SoundBufferParams())
 Loads the sound buffer from memory. More...
 
bool LoadFromStream (Stream &stream, const SoundBufferParams &params=SoundBufferParams())
 Loads the sound buffer from stream. More...
 
SoundBufferoperator= (const SoundBuffer &)=delete
 
SoundBufferoperator= (SoundBuffer &&)=delete
 
 NazaraSignal (OnSoundBufferDestroy, const SoundBuffer *)
 
 NazaraSignal (OnSoundBufferRelease, const SoundBuffer *)
 
- Public Member Functions inherited from Nz::RefCounted
 RefCounted (bool persistent=true)
 Constructs a RefCounted object with a persistance aspect. More...
 
 RefCounted (const RefCounted &)=delete
 
 RefCounted (RefCounted &&)=default
 
virtual ~RefCounted ()
 Destructs the object. More...
 
void AddReference () const
 Adds a reference to the object.
 
unsigned int GetReferenceCount () const
 Gets the number of references to the object. More...
 
bool IsPersistent () const
 Checks whether the object is persistent. More...
 
bool RemoveReference () const
 Removes a reference to the object. More...
 
bool SetPersistent (bool persistent=true, bool checkReferenceCount=false)
 Sets the persistence of the object. More...
 
RefCountedoperator= (const RefCounted &)=delete
 
RefCountedoperator= (RefCounted &&)=default
 
- Public Member Functions inherited from Nz::Resource
 Resource (const Resource &)=default
 
 Resource (Resource &&) noexcept=default
 
const StringGetFilePath () const
 Gets the file path associated with the resource. More...
 
void SetFilePath (const String &filePath)
 Sets the file path associated with the resource. More...
 
Resourceoperator= (const Resource &)=default
 
Resourceoperator= (Resource &&) noexcept=default
 

Static Public Member Functions

static bool IsFormatSupported (AudioFormat format)
 Checks whether the format is supported by the engine. More...
 
template<typename... Args>
static SoundBufferRef New (Args &&... args)
 Creates a new sound buffer from the arguments. More...
 

Friends

class Audio
 

Detailed Description

Audio class that represents a buffer for sound.

Remarks
Module Audio needs to be initialized to use this class

Constructor & Destructor Documentation

◆ SoundBuffer()

Nz::SoundBuffer::SoundBuffer ( AudioFormat  format,
UInt64  sampleCount,
UInt32  sampleRate,
const Int16 *  samples 
)

Constructs a SoundBuffer object.

Parameters
formatFormat for the audio
sampleCountNumber of samples
sampleRateRate of samples
samplesSamples raw data
Remarks
Produces a NazaraError if creation went wrong with NAZARA_AUDIO_SAFE defined
Produces a std::runtime_error if creation went wrong with NAZARA_AUDIO_SAFE defined
See also
Create

◆ ~SoundBuffer()

Nz::SoundBuffer::~SoundBuffer ( )

Destructs the object and calls Destroy.

See also
Destroy

Member Function Documentation

◆ Create()

bool Nz::SoundBuffer::Create ( AudioFormat  format,
UInt64  sampleCount,
UInt32  sampleRate,
const Int16 *  samples 
)

Creates the SoundBuffer object.

Returns
true if creation is successful
Parameters
formatFormat for the audio
sampleCountNumber of samples
sampleRateRate of samples
samplesSamples raw data
Remarks
Produces a NazaraError if creation went wrong with NAZARA_AUDIO_SAFE defined, this could happen if parameters are invalid or creation of OpenAL buffers failed

◆ GetDuration()

UInt32 Nz::SoundBuffer::GetDuration ( ) const

Gets the duration of the sound buffer.

Returns
Duration of the sound buffer in milliseconds
Remarks
Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined

◆ GetFormat()

AudioFormat Nz::SoundBuffer::GetFormat ( ) const

Gets the format of the sound buffer.

Returns
Enumeration of type AudioFormat (mono, stereo, ...)
Remarks
Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined

◆ GetSampleCount()

UInt64 Nz::SoundBuffer::GetSampleCount ( ) const

Gets the number of samples in the sound buffer.

Returns
Count of samples (number of seconds * sample rate * channel count)
Remarks
Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined

◆ GetSampleRate()

UInt32 Nz::SoundBuffer::GetSampleRate ( ) const

Gets the rates of sample in the sound buffer.

Returns
Rate of sample in Hertz (Hz)
Remarks
Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined

◆ GetSamples()

const Int16 * Nz::SoundBuffer::GetSamples ( ) const

Gets the internal raw samples.

Returns
Pointer to raw data
Remarks
Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined

◆ IsFormatSupported()

bool Nz::SoundBuffer::IsFormatSupported ( AudioFormat  format)
static

Checks whether the format is supported by the engine.

Returns
true if it is the case
Parameters
formatFormat to check

◆ IsValid()

bool Nz::SoundBuffer::IsValid ( ) const

Checks whether the sound buffer is valid.

Returns
true if it is the case

◆ LoadFromFile()

bool Nz::SoundBuffer::LoadFromFile ( const String filePath,
const SoundBufferParams &  params = SoundBufferParams() 
)

Loads the sound buffer from file.

Returns
true if loading is successful
Parameters
filePathPath to the file
paramsParameters for the sound buffer

◆ LoadFromMemory()

bool Nz::SoundBuffer::LoadFromMemory ( const void *  data,
std::size_t  size,
const SoundBufferParams &  params = SoundBufferParams() 
)

Loads the sound buffer from memory.

Returns
true if loading is successful
Parameters
dataRaw memory
sizeSize of the memory
paramsParameters for the sound buffer

◆ LoadFromStream()

bool Nz::SoundBuffer::LoadFromStream ( Stream stream,
const SoundBufferParams &  params = SoundBufferParams() 
)

Loads the sound buffer from stream.

Returns
true if loading is successful
Parameters
streamStream to the sound buffer
paramsParameters for the sound buffer

◆ New()

template<typename... Args>
SoundBufferRef Nz::SoundBuffer::New ( Args &&...  args)
static

Creates a new sound buffer from the arguments.

Returns
A reference to the newly created sound buffer
Parameters
argsArguments for the sound buffer

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