"L. Spiro Engine"
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends

lss::CSoundBuffer Class Reference

Shared raw sound data. More...

#include <LSSSoundBuffer.h>

Inheritance diagram for lss::CSoundBuffer:
lss::CSoundBufferEx

List of all members.

Public Types

enum  LSS_ERROR { LSS_E_INVALID_BUFFER = 0 }

Public Member Functions

LSUINT32 LSE_CALL GetId () const
LSVOID LSE_CALL IncRef () const
LSVOID LSE_CALL DecRef () const
LSUINT32 LSE_CALL GetRef () const
LSUINT64 LSE_CALL GetLengthInMicros () const
virtual LSBOOL LSE_CALL CanSoftUnload () const

Protected Types

enum  { LSS_INVALID_BUFFER = 0 }

Protected Member Functions

LSE_CALLCTOR CSoundBuffer (const LSUINT8 *_pui8Data, LSUINT32 _ui32Length, LSUINT32 _ui32Freq, LSUINT32 _ui32Bits, LSUINT32 _ui32Channels, CAllocator *_paAllocator, LSBOOL _bRetain, LSUINTPTR _uiptrUserData)

Protected Attributes

LSUINT64 m_ui64BufferTime
LSUINT8 * m_pui8Data
LSUINT32 m_ui32Size
LSBOOL m_bRetain
LSUINT32 m_ui32Freq
LSUINT16 m_ui16BitDepth
LSUINT16 m_ui16Channels
CAllocator * m_paAllocator
LSUINT32 m_ui32Id
LSINT32 m_i32Ref
ALuint m_uiAlBufferId

Static Protected Attributes

static LSUINT32 m_ui32MasterId

Friends

class CSoundManager
class CStaticSoundSource
class CStreamingSoundSource

Detailed Description

Shared raw sound data.

Class CSoundBuffer Description: Buffers are the shared sound data. Load a WAV or OGG (etc.) file and its raw PCM data will be held in a buffer which sound sources (CSoundSource) can use to play. This is shared data, following exactly the same concept as with 3D models, which are loaded once and then instanced. This class forms the shared sound data and CSoundSource forms the instances of the sound data played at various locations in the game world. This class cannot be instanced directly. Use CSoundManager to create instances of these.

There are 2 possible system states when these objects are created: One where there is a valid device already set and one without a valid device. Additionally, these buffers must support changing devices during run-time. Normally we could impose a restriction that requires a device to be set when buffers are created, but the fact is, because we need a system that allows changing devices anyway, it becomes very simple to modify the class just slightly so that it can handle both cases instead of only one. This allows us to impose no restrictions on the device state with no extra development time. Nice!

When the buffer is created it will be given a pointer to data which it will copy and store. The buffer can be set to keep the copy for forever or to free it once it has sent the copy to the hardware. Creating a buffer does not automatically make it try to send anything to hardware. The sound manager will, as soon as a device is ready (which will be immediately if there is already a device) notify the buffer that there is a device, and the buffer will then upload its contents. If set to free its copy it will do so then. The same notification is used to tell the buffer that a new device has been set, and the buffer will react the same way by uploading and optionally freeing its copy.

When the buffer needs to upload its copy to the hardware, it may have a NULL copy as a result of having uploaded and freed it previously. In this case the buffer calls the virtual function GetOriginalData(). the default implementation returns failure and the re-upload will fail. Therefore, if this class is not subclassed, and the user has the ability to change devices, the buffers must never be set to automatically free their copies. If the device can be changed, in order to save RAM this class should be subclassed so that the buffers may be flushed after being sent to the sound system.


Member Enumeration Documentation

An invalid buffer ID (not related to OpenAL etc.)


Member Function Documentation

virtual LSBOOL LSE_CALL lss::CSoundBuffer::CanSoftUnload ( ) const [virtual]

Set the value indicating whether this buffer should resist soft unloads or not. A soft unload is an unload that is used to save RAM even though it is assumed the buffer may be needed (and will be reloaded) later. A hard unload is performed to force all buffers out of memory. A hard unload always destroys and releases the buffer, whereas a soft unload is optional and can only be done on buffers with a zero reference count. For a soft unload to work, there must be a way to restore the buffer to its current state after being completely unloaded. Because the core sound library provides no way to do this, this function always returns false.

Returns:
Returns false. Override this class to return any other value.

Reimplemented in lss::CSoundBufferEx.

LSVOID LSE_CALL lss::CSoundBuffer::DecRef ( ) const

Decrease our reference count.

LSUINT32 LSE_CALL lss::CSoundBuffer::GetId ( ) const

Get our ID.

Returns:
Returns the unique ID of this buffer.
LSUINT64 LSE_CALL lss::CSoundBuffer::GetLengthInMicros ( ) const

Get the length of this buffer in microseconds.

Returns:
Returns the length of the buffer in microseconds.
LSUINT32 LSE_CALL lss::CSoundBuffer::GetRef ( ) const

Get our reference count.

Returns:
Returns the reference count of this object.
LSVOID LSE_CALL lss::CSoundBuffer::IncRef ( ) const

Increase our reference count.


The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator