Skylicht Engine
Loading...
Searching...
No Matches
Skylicht::Audio::CAudioEngine Class Reference

The main audio engine singleton for managing audio playback and resources. More...

#include <Engine/CAudioEngine.h>

Inheritance diagram for Skylicht::Audio::CAudioEngine:
Skylicht::System::IThreadCallback

Public Member Functions

void init ()
 Initialize the audio engine, driver, and background thread.
void shutdown ()
 Shutdown the audio engine and release all resources.
void pauseEngine ()
 Suspend the audio engine and driver.
void resumeEngine ()
 Resume the audio engine and driver.
void updateDriver ()
 Manually update the audio driver.
void stopAllSound ()
 Stop all active sounds.
virtual void updateEmitter ()
 Update all active emitters. Called by updateThread or updateSkylichtAudio.
virtual void updateThread ()
 Background thread update loop.
void lockThread ()
 Lock audio thread for safe state modification.
void unLockThread ()
 Unlock audio thread.
ISoundDrivergetSoundDriver ()
 Get the active sound driver.
void registerStreamFactory (IStreamFactory *streamFactory)
 Register a custom stream factory.
void unRegisterStreamFactory (IStreamFactory *streamFactory)
 Unregister a stream factory.
IStreamcreateStreamFromMemory (unsigned char *buffer, int size, bool takeOwnerShip=false)
 Create an audio stream from a memory buffer.
IStreamcreateStreamFromFile (const char *fileName)
 Create an audio stream from a file.
IStreamcreateStreamFromFileAndCache (const char *fileName, bool cache)
 Create an audio stream from a file with optional caching.
IStreamcreateOnlineStream ()
 Create an empty online stream for streaming data over the network.
CAudioEmittercreateAudioEmitter (IStream *stream, IAudioDecoder::EDecoderType decode)
 Create an audio emitter from a stream.
CAudioEmittercreateAudioEmitter (const char *fileName, bool cache)
 Create an audio emitter from a file.
CAudioEmittercreateRawAudioEmitter (IStream *stream)
 Create an audio emitter for raw PCM data.
CAudioReadercreateAudioReader (IStream *stream, IAudioDecoder::EDecoderType decode)
 Create an audio reader for decoding audio data without playback.
CAudioReadercreateAudioReader (const char *fileName)
 Create an audio reader from a file.
void destroyEmitter (CAudioEmitter *emitter)
 Destroy an audio emitter.
void destroyReader (CAudioReader *reader)
 Destroy an audio reader.
void destroyAllEmitter ()
 Destroy all audio emitters.
void destroyAllReader ()
 Destroy all audio readers.
void releaseAllStream ()
 Release all cached streams.
void setListener (float posx, float posy, float posz, float upx, float upy, float upz, float frontx, float fronty, float frontz)
 Set the listener parameters for 3D sound.
const SListenergetListener ()
 Get current listener parameters.
bool isPause ()
 Check if the audio engine is paused.
Public Member Functions inherited from Skylicht::System::IThreadCallback
virtual bool enableThreadLoop ()
virtual void runThread ()

Static Public Member Functions

static CAudioEngine * getSoundEngine ()
 Get the singleton instance of the audio engine.
static void shutdownEngine ()
 Shutdown and release the audio engine instance.

Protected Attributes

IThreadm_thread
IMutexm_mutex
ISoundDriverm_driver
IStreamFactorym_defaultStreamFactory
std::vector< IStreamFactory * > m_streamFactorys
std::vector< CAudioEmitter * > m_emitters
std::vector< CAudioReader * > m_readers
std::map< std::string, IStream * > m_fileToStream
SListener m_listener
bool m_pause

Detailed Description

The main audio engine singleton for managing audio playback and resources.

#include "SkylichtAudio.h"
// Setup audio listener (e.g., from camera)
pos.X, pos.Y, pos.Z,
up.X, up.Y, up.Z,
front.X, front.Y, front.Z
);
// Create an emitter
music->play();
Audio emitter for playing and managing sound sources.
Definition CAudioEmitter.h:70
virtual void play(bool fromBegin=true)
Start or resume playback.
void setListener(float posx, float posy, float posz, float upx, float upy, float upz, float frontx, float fronty, float frontz)
Set the listener parameters for 3D sound.
CAudioEmitter * createAudioEmitter(IStream *stream, IAudioDecoder::EDecoderType decode)
Create an audio emitter from a stream.
static CAudioEngine * getSoundEngine()
Get the singleton instance of the audio engine.

Member Function Documentation

◆ createAudioEmitter() [1/2]

CAudioEmitter * Skylicht::Audio::CAudioEngine::createAudioEmitter ( const char * fileName,
bool cache )

Create an audio emitter from a file.

Parameters
fileNamePath to the audio file
cacheIf true, the file data will be cached in memory
Returns
Pointer to CAudioEmitter

◆ createAudioEmitter() [2/2]

CAudioEmitter * Skylicht::Audio::CAudioEngine::createAudioEmitter ( IStream * stream,
IAudioDecoder::EDecoderType decode )

Create an audio emitter from a stream.

Parameters
streamThe audio stream
decodeThe decoder type
Returns
Pointer to CAudioEmitter

◆ createAudioReader() [1/2]

CAudioReader * Skylicht::Audio::CAudioEngine::createAudioReader ( const char * fileName)

Create an audio reader from a file.

Parameters
fileNamePath to the audio file
Returns
Pointer to CAudioReader

◆ createAudioReader() [2/2]

CAudioReader * Skylicht::Audio::CAudioEngine::createAudioReader ( IStream * stream,
IAudioDecoder::EDecoderType decode )

Create an audio reader for decoding audio data without playback.

Parameters
streamThe audio stream
decodeThe decoder type
Returns
Pointer to CAudioReader

◆ createOnlineStream()

IStream * Skylicht::Audio::CAudioEngine::createOnlineStream ( )

Create an empty online stream for streaming data over the network.

Returns
Pointer to IStream

◆ createRawAudioEmitter()

CAudioEmitter * Skylicht::Audio::CAudioEngine::createRawAudioEmitter ( IStream * stream)

Create an audio emitter for raw PCM data.

Parameters
streamThe PCM data stream
Returns
Pointer to CAudioEmitter

◆ createStreamFromFile()

IStream * Skylicht::Audio::CAudioEngine::createStreamFromFile ( const char * fileName)

Create an audio stream from a file.

Parameters
fileNamePath to the audio file
Returns
Pointer to IStream

◆ createStreamFromFileAndCache()

IStream * Skylicht::Audio::CAudioEngine::createStreamFromFileAndCache ( const char * fileName,
bool cache )

Create an audio stream from a file with optional caching.

Parameters
fileNamePath to the audio file
cacheIf true, the file data will be cached in memory
Returns
Pointer to IStream

◆ createStreamFromMemory()

IStream * Skylicht::Audio::CAudioEngine::createStreamFromMemory ( unsigned char * buffer,
int size,
bool takeOwnerShip = false )

Create an audio stream from a memory buffer.

Parameters
bufferThe memory buffer containing audio data
sizeThe size of the buffer
takeOwnerShipIf true, the stream will delete the buffer upon destruction
Returns
Pointer to IStream

◆ destroyEmitter()

void Skylicht::Audio::CAudioEngine::destroyEmitter ( CAudioEmitter * emitter)

Destroy an audio emitter.

Parameters
emitterThe emitter to destroy

◆ destroyReader()

void Skylicht::Audio::CAudioEngine::destroyReader ( CAudioReader * reader)

Destroy an audio reader.

Parameters
readerThe reader to destroy

◆ getListener()

const SListener & Skylicht::Audio::CAudioEngine::getListener ( )
inline

Get current listener parameters.

Returns
SListener structure

◆ getSoundDriver()

ISoundDriver * Skylicht::Audio::CAudioEngine::getSoundDriver ( )
inline

Get the active sound driver.

Returns
Pointer to ISoundDriver

◆ getSoundEngine()

CAudioEngine * Skylicht::Audio::CAudioEngine::getSoundEngine ( )
static

Get the singleton instance of the audio engine.

Returns
Pointer to CAudioEngine

◆ isPause()

bool Skylicht::Audio::CAudioEngine::isPause ( )
inline

Check if the audio engine is paused.

Returns
True if paused

◆ registerStreamFactory()

void Skylicht::Audio::CAudioEngine::registerStreamFactory ( IStreamFactory * streamFactory)

Register a custom stream factory.

Parameters
streamFactoryThe factory to register

◆ setListener()

void Skylicht::Audio::CAudioEngine::setListener ( float posx,
float posy,
float posz,
float upx,
float upy,
float upz,
float frontx,
float fronty,
float frontz )

Set the listener parameters for 3D sound.

Parameters
posxX coordinate of the listener
posyY coordinate of the listener
poszZ coordinate of the listener
upxX coordinate of the up vector
upyY coordinate of the up vector
upzZ coordinate of the up vector
frontxX coordinate of the forward vector
frontyY coordinate of the forward vector
frontzZ coordinate of the forward vector

◆ unRegisterStreamFactory()

void Skylicht::Audio::CAudioEngine::unRegisterStreamFactory ( IStreamFactory * streamFactory)

Unregister a stream factory.

Parameters
streamFactoryThe factory to unregister

◆ updateThread()

virtual void Skylicht::Audio::CAudioEngine::updateThread ( )
virtual

Background thread update loop.

Implements Skylicht::System::IThreadCallback.


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