You.i Engine
CYIAudioEngine Class Referenceabstract

Detailed Description

Object responsible for processing audio streams and output to the platform.

The global instance is accessible through CYIFramework::GetAudioEngine. Used to register audio streams to be processed.

Warning
The CYIAudioEngine does not take ownership of the CYIAudioStream being passed in or registered. The user is responsible for holding on to a reference to the std::shared_ptr of the CYIAudioStream.

#include <audio/YiAudioEngine.h>

Inheritance diagram for CYIAudioEngine:

Public Member Functions

virtual ~CYIAudioEngine ()
 
virtual uint32_t GetSampleRate () const =0
 
virtual uint32_t GetChannelCount () const =0
 
virtual void RegisterStream (const std::shared_ptr< CYIAudioStream > &pStreamToAdd)
 
virtual void UnregisterStream (const std::shared_ptr< CYIAudioStream > &pStreamToRemove)
 
virtual void PlaySound (const CYIString &name, float volume=1.0f)
 
virtual void PlaySound (const std::shared_ptr< CYIAssetSound > &pAsset, float volume=1.0f)
 
virtual std::shared_ptr< CYISoundInstanceCreateSoundInstance (const CYIString &name)
 
virtual std::shared_ptr< CYISoundInstanceCreateSoundInstance (const std::shared_ptr< CYIAssetSound > &pAsset)
 
virtual void ClearCache ()
 
void Enable ()
 
void Disable ()
 
bool IsEnabled () const
 
- Public Member Functions inherited from CYISignalHandler
 CYISignalHandler ()
 
 CYISignalHandler (const CYISignalHandler &rSignalHandler)
 
virtual ~CYISignalHandler ()
 
CYISignalHandleroperator= (const CYISignalHandler &rSignalHandler)
 
void MoveToThread (CYIThread *pThread)
 This function allows the user to override the default thread affinity to any CYIThread that may or may not be running. More...
 
CYIThreadHandle GetThreadAffinity () const
 
void SetThreadAffinity (const CYIThreadHandle &rThreadAffinity)
 
virtual bool IsConnected () const
 
virtual bool IsConnected (const CYISignalBase &rSignal) const
 
void Disconnect (CYISignalBase &rSignal)
 
void DisconnectFromAllSignals ()
 
- Public Member Functions inherited from CYIThread::Listener
 Listener ()
 
virtual ~Listener ()
 
virtual void OnThreadStarted (CYIThread *)
 
virtual void OnThreadTerminated (CYIThread *)
 
virtual void OnThreadFinished (CYIThread *)
 

Static Public Member Functions

static std::unique_ptr< CYIAudioEngineCreate ()
 

Protected Member Functions

 CYIAudioEngine ()
 
virtual void Process (float *pData, uint32_t frameCount)
 

Constructor & Destructor Documentation

◆ ~CYIAudioEngine()

virtual CYIAudioEngine::~CYIAudioEngine ( )
virtual

◆ CYIAudioEngine()

CYIAudioEngine::CYIAudioEngine ( )
protected

Member Function Documentation

◆ ClearCache()

virtual void CYIAudioEngine::ClearCache ( )
virtual

Clears the cache used by PlaySound(). All currently playing sound instances triggered by PlaySound() will be stopped immediately. This can be called if the application receives a memory warning.

◆ Create()

static std::unique_ptr<CYIAudioEngine> CYIAudioEngine::Create ( )
static

Creates a new audio engine instance. A global instance can be accessed through CYIFramework::GetAudioEngine.

◆ CreateSoundInstance() [1/2]

virtual std::shared_ptr<CYISoundInstance> CYIAudioEngine::CreateSoundInstance ( const CYIString name)
virtual

Creates a sound instance that is not cached or reused by the audio engine.

◆ CreateSoundInstance() [2/2]

virtual std::shared_ptr<CYISoundInstance> CYIAudioEngine::CreateSoundInstance ( const std::shared_ptr< CYIAssetSound > &  pAsset)
virtual

Creates a sound instance that is not cached or reused by the audio engine.

◆ Disable()

void CYIAudioEngine::Disable ( )

Disable the Audio Engine. Audio output will be muted, new sounds or CYIAudioStream won't start playing and all currently playing sounds will be stopped.

Note
Disabling the audio engine this way doesn't stop the thread or OS callbacks. To completely disable the Audio Engine, it has to be set from CYIFrameworkConfiguration at the application launch.

◆ Enable()

void CYIAudioEngine::Enable ( )

Enable the Audio Engine. It is enabled by default.

◆ GetChannelCount()

virtual uint32_t CYIAudioEngine::GetChannelCount ( ) const
pure virtual

Returns the channel count used by the audio engine. This is platform dependent and will not always be consistent with each run, but will remain constant for the life of the engine. Common channel counts are: mono (1), stereo (2), surround (8).

◆ GetSampleRate()

virtual uint32_t CYIAudioEngine::GetSampleRate ( ) const
pure virtual

Returns the sample rate at which the audio engine is running. This is platform dependent and will not always be consistent with each run, but will remain constant for the life of the engine. Common sample rates are: 22050, 44100, 48000.

◆ IsEnabled()

bool CYIAudioEngine::IsEnabled ( ) const

Returns whether the audio engine is currently enabled or disabled.

◆ PlaySound() [1/2]

virtual void CYIAudioEngine::PlaySound ( const CYIString name,
float  volume = 1.0f 
)
virtual

Utility method to play a sound. It will cache the CYIAssetSound that matches the name. The sound will play at full volume by default, but a volume can be passed in the range [0, 1]. A volume value higher than 1 can be set, but sound output might be clipped.

◆ PlaySound() [2/2]

virtual void CYIAudioEngine::PlaySound ( const std::shared_ptr< CYIAssetSound > &  pAsset,
float  volume = 1.0f 
)
virtual

Utility method to play a sound. The pAsset will be played and sound instances reused. The sound will play at full volume by default, but a volume can be passed in the range [0, 1] A volume value higher than 1 can be set, but sound output might be clipped.

◆ Process()

virtual void CYIAudioEngine::Process ( float *  pData,
uint32_t  frameCount 
)
protectedvirtual

Processes an audio buffer. pData is an array of size frameCount * CYIAudioEngine::GetChannelCount(). Each sample in pData is ranged from -1 to 1.

New samples processes by this callback should be added to pData, not overriden. It is cummulative for all active CYIAudioStream instances. To start processing, a stream needs to be registered to the CYIAudioEngine. Unregister to stop processing.

Note
This is called from the audio thread.

◆ RegisterStream()

virtual void CYIAudioEngine::RegisterStream ( const std::shared_ptr< CYIAudioStream > &  pStreamToAdd)
virtual

Registers a CYIAudioStream for playback. pStream will start receiving CYIAudioStream::Process callback immediately.

Warning
The CYIAudioEngine will not take ownership of the stream being passed in and will only internally hold a CYIWeakPointer to the stream being registered. It is up to the user to hold on to a reference of the std::shared_ptr of the CYIAudioStream being passed in.

◆ UnregisterStream()

virtual void CYIAudioEngine::UnregisterStream ( const std::shared_ptr< CYIAudioStream > &  pStreamToRemove)
virtual

Stops processing a CYIAudioStream. pStream will stop receiving CYIAudioStream::Process callback immediately.

Warning
This will only remove the CYIWeakPointer of the CYIAudioStream the CYIAudioEngine holds.

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