![]() |
SAGE
A Simple Academic Game Engine
|
The Sound Player. More...
#include <SageSound.h>


Public Member Functions | |
| CSound () | |
| Constructor. | |
| ~CSound () | |
| Destructor. | |
| template<class t > | |
| void | LoadMT (Sage::CMediaList< t > &) |
| Load sounds multithreaded. | |
| template<class t > | |
| void | Load (Sage::CMediaList< t > &) |
| Load sounds. | |
| const bool | Loaded () const |
| Sound loading completed. | |
| template<class t > | |
| void | Load (t, const char *) |
| Load sound. | |
| template<class t > | |
| CSoundDesc | Play (t, const Vector2 &, float=1.0f, float=0.0f) |
| Play sound. | |
| template<class t > | |
| CSoundDesc | Play (t, const Vector3 &, float=1.0f, float=0.0f) |
| Play sound. | |
| template<class t > | |
| CSoundDesc | Play (t, float=1.0f) |
| Play sound. | |
| template<class t > | |
| CSoundDesc | Play (t, float, float) |
| Play sound. | |
| template<class t > | |
| CSoundDesc | Loop (t) |
| Loop a sound. | |
| template<class t > | |
| CSoundDesc | Loop (t, const Vector2 &) |
| Loop a sound. | |
| template<class t > | |
| CSoundDesc | Loop (t, const Vector3 &) |
| Loop a sound. | |
| template<class t > | |
| CSoundDesc | Vary (t, float=0.1f, float=1, float=0) |
| Play a randomly varied sound. | |
| template<class t > | |
| CSoundDesc | Vary (t, const Vector2 &, float=0.1f, float=1, float=0) |
| Play a randomly varied sound. | |
| template<class t > | |
| CSoundDesc | Vary (t, const Vector3 &, float=0.1f, float=1, float=0) |
| Play a randomly varied sound. | |
| void | BeginFrame () |
| Start of frame notification. | |
| void | Mute () |
| Mute/unmute the sounds. | |
| void | Stop () |
| Stop all sounds. | |
| template<class t > | |
| void | Stop (t) |
| Stop a sound. | |
| void | Stop (const CSoundDesc &) |
| Stop a sound instance. | |
| void | SetPitch (const CSoundDesc &, float) |
| Set pitch. | |
| void | SetListenerPos (const Vector3 &) |
| Set listener position. | |
| void | SetListenerPos (const Vector2 &) |
| Set listener position. | |
| void | SetListenerOrient (const Vector3 &, const Vector3 &) |
| Set listener orientation. | |
| void | SetListener (CCamera *) |
| Set listener to camera pos and orientation. | |
| void | SetScale (const float) |
| Set scale for the sound world. | |
Public Member Functions inherited from Sage::CSettingsManager | |
| void | Load () |
| Load game settings. | |
Protected Member Functions | |
| void | Initialize (size_t) |
| Initialize. | |
| void | CreateInstances (size_t, size_t, SOUND_EFFECT_INSTANCE_FLAGS) |
| Create sound instances. | |
| void | LoadByIndex (size_t, const char *) |
| Load sound by index. | |
| size_t | GetNextInstance (size_t) |
| Get the next instance that is not playing. | |
Protected Member Functions inherited from Sage::CSettingsManager | |
| void | SetWinSize (int, int) |
| Set window size information. | |
Protected Attributes | |
| std::unique_ptr< AudioEngine > | m_pAudioEngine |
| Pointer to an audio engine. | |
| CPlayableSoundDesc * | m_pSound = nullptr |
| Playable sounds. | |
| size_t | m_nCount = 0 |
| Number of sounds. | |
| AudioListener | m_cListener |
| Audio listener. | |
| Vector2 | m_vEmitterPos |
| Position of the emitter (the thing making the sound). | |
| Vector3 | m_vListenerPos |
| Position of the listener. | |
| bool | m_bMuted = false |
| Whether mute is on. | |
| float | m_fScale = 500.0f |
| Coordinate scale factor. | |
Private Attributes | |
| const float | DEPTH = 100.0f |
| Default Z depth for 2D sounds. | |
| bool | m_bLoaded = false |
| Sounds loaded flag. | |
Additional Inherited Members | |
Static Protected Attributes inherited from Sage::CWindowDesc | |
| static HWND | m_Hwnd = 0 |
| Window handle. | |
| static HINSTANCE | m_hInst = 0 |
| Instance handle. | |
| static bool | m_bExitSizeMove = true |
| User just finished moving/resizing window. | |
Static Protected Attributes inherited from Sage::CSettingsManager | |
| static tinyxml2::XMLElement * | m_pXmlSettings = nullptr |
| Pointer to the settings tag in the XML settings file. | |
| static float | m_fAspectRatio = 1.0f |
| Aspect ratio, width/ht. | |
Static Protected Attributes inherited from Sage::CSettings | |
| static char | m_szName [MAX_PATH] |
| Name of this game. | |
| static int | m_nWinWidth = 0 |
| Window width in pixels. | |
| static int | m_nWinHeight = 0 |
| Window height in pixels. | |
| static Vector2 | m_vWinCenter = Vector2::Zero |
| Window center. | |
Static Protected Attributes inherited from Sage::CComponent | |
| static std::unique_ptr< CTimer > | m_pTimer = std::make_unique<CTimer>() |
| Pointer to a timer. | |
| static std::unique_ptr< CRandom > | m_pRandom = std::make_unique<CRandom>() |
| Pointer to a PRNG. | |
| static std::unique_ptr< CSound > | m_pSound = std::make_unique<CSound>() |
| Pointer to sound manager. | |
| static std::unique_ptr< CKeyboard > | m_pKeyboard |
| Pointer to a keyboard handler. | |
| static std::unique_ptr< CMouse > | m_pMouse = std::make_unique<CMouse>() |
| Pointer to a mouse handler. | |
| static std::unique_ptr< CController > | m_pController |
| Pointer to a controller. | |
The Sound Player allows you to play multiple overlapping copies of sounds simultaneously. It reads settings from the XML settings file, including a list of file names to be loaded. It can set the volume, pitch, and position of each sound instance played. Since it implements 3D sound, make sure your sound files are mono, not stereo. If you hear a horrible screeching sound instead of your nice sound sample, it probably means that your sound file is stereo, not mono. Use a sound editor such as Audacity to convert your sound from stereo to mono. Make sure you call BeginFrame once per frame to prevent multiple copies of a sound from playing at the same time, which only makes one sound but LOUDER.
| CSound::CSound | ( | ) |
Set member variables to sensible values and initialize the XAudio Engine using DirectXTK12. If the compiler is in debug mode, then set the XAudio engine in debug mode too.
| CSound::~CSound | ( | ) |
Reclaim all dynamic memory and shut down the audio engine.
| void CSound::BeginFrame | ( | ) |
Get ready for new animation frame by flagging all sounds as unplayed.
|
protected |
Create sound instances.
| index | Index of sound. |
| n | Number of instances of sound wanted. |
| flags | Flags. |

|
protected |
Get the index into the instance array of the next unplayed instance of a sound.
| index | Index of sound in the sound array. |

|
protected |
Delete old sound descriptors and create the required number of new ones.
| n | Number of sounds. |

| void Sage::CSound::Load | ( | Sage::CMediaList< t > & | media | ) |
Load sounds synchronously from a media descriptor.
| t | Sound enumerated type. |
| media | Media list. |

| void Sage::CSound::Load | ( | t | e, |
| const char * | name ) |
Load information about a sound from global variable g_xmlSettings, then load the sound sample as per that information. Abort if something goes wrong. Uses LoadByIndex() to do the actual work.
| t | Sound enumerated type. |
| e | Sound type. |
| name | Sound name in XML file. |

|
protected |
Load information about a sound from global variable g_xmlSettings, then load sounds as per that information. Abort if something goes wrong.
| index | Sprite index. |
| name | Object name in XML file. |


| const bool CSound::Loaded | ( | ) | const |
Reader function for the loaded flag m_bLoaded.
| void Sage::CSound::LoadMT | ( | Sage::CMediaList< t > & | media | ) |
Load sounds asynchronously from a media descriptor, that is, spawn a thread to do the loading. Member variable m_bLoaded will be set to true when loading is finished.
| t | Sound enumerated type. |
| media | Media list. |

| CSoundDesc Sage::CSound::Loop | ( | t | e | ) |
Loop a sound effect in mono.
| t | Sound enumerated type. |
| e | Type of sound to be looped. |


| CSoundDesc Sage::CSound::Loop | ( | t | e, |
| const Vector2 & | s ) |
Loop a sound effect in stereo.
| t | Sound enumerated type. |
| e | Type of sound to be looped. |
| s | Position of emitter in 2D. |

| CSoundDesc Sage::CSound::Loop | ( | t | e, |
| const Vector3 & | s ) |
Loop a sound effect in stereo.
| t | Sound enumerated type. |
| e | Type of sound to be looped. |
| s | Position of emitter in 3D. |

| void CSound::Mute | ( | ) |
If the sound is muted, unmute it. If not, mute it. This means stopping sounds that are currently playing and preventing future sounds from getting started.

| CSoundDesc Sage::CSound::Play | ( | t | e, |
| const Vector2 & | s, | ||
| float | vol = 1.0f, | ||
| float | pitch = 0.0f ) |
Play a sound effect in stereo.
| t | Sound enumerated type. |
| e | Type of sound to be played. |
| s | Position of emitter in 2D. |
| vol | Volume (defaults to 1.0f). |
| pitch | Pitch (defaults to zero). |


| CSoundDesc Sage::CSound::Play | ( | t | e, |
| const Vector3 & | s, | ||
| float | vol = 1.0f, | ||
| float | p = 0.0f ) |
Play a sound effect in stereo.
| t | Sound enumerated type. |
| e | Type of sound to be played. |
| s | Position of emitter in 3D. |
| vol | Volume (defaults to 1.0f). |
| p | Pitch (defaults to zero). |

| CSoundDesc Sage::CSound::Play | ( | t | e, |
| float | vol, | ||
| float | pitch ) |
Play a sound effect in mono.
| t | Sound enumerated type. |
| e | Type of sound to be played. |
| vol | Volume. |
| pitch | Pitch. |

| CSoundDesc Sage::CSound::Play | ( | t | e, |
| float | vol = 1.0f ) |
Play a sound effect in mono.
| t | Sound enumerated type. |
| e | Type of sound to be played. |
| vol | Volume (defaults to 1.0f). |

| void CSound::SetListener | ( | CCamera * | pCamera | ) |
Set listener to camera pos and orientation.
| pCamera | Pointer to the camera. |

| void CSound::SetListenerOrient | ( | const Vector3 & | vLook, |
| const Vector3 & | vUp ) |
Set the listener orientation from a pair of vectors.
| vLook | Look-at vector. |
| vUp | Up vector. |

| void CSound::SetListenerPos | ( | const Vector2 & | pos | ) |
Move the listener to a new position.
| pos | New position of listener. |

| void CSound::SetListenerPos | ( | const Vector3 & | pos | ) |
Move the listener to a new position.
| pos | New position of listener. |

| void CSound::SetPitch | ( | const CSoundDesc & | d, |
| float | pitch ) |
Set the pitch of the first instance of a sound.
| d | Sound descriptor. |
| pitch | New pitch. |
| void CSound::SetScale | ( | const float | scale | ) |
Set the scale factor for converting from render coordinates to sound coordinates.
| scale | Scale factor. |
| void CSound::Stop | ( | ) |
Stop all instances of all sound effects.


| void CSound::Stop | ( | const CSoundDesc & | d | ) |
Stop an instance of a sound effects.
| d | Descriptor for a sound instance. |
| void Sage::CSound::Stop | ( | t | e | ) |
Stop all instances of a sound effect.
| t | Sound enumerated type. |
| e | Type of sound to be stopped. |

| CSoundDesc Sage::CSound::Vary | ( | t | e, |
| const Vector2 & | s, | ||
| float | var = 0.1f, | ||
| float | vol = 1, | ||
| float | p = 0 ) |
Play a sound effect in stereo, but slightly differently each time it is played. The pitch is varied up and down by a random amount scaled by a coefficient of variability that is provided as a parameter.
| t | Sound enumerated type. |
| e | Type of sound to be played. |
| s | Position of emitter in 2D. |
| var | Coefficient of variability (defaults to 0.25). |
| vol | Volume (defaults to 1.0). |
| p | Pitch (defaults to 0). |

| CSoundDesc Sage::CSound::Vary | ( | t | e, |
| const Vector3 & | s, | ||
| float | var = 0.1f, | ||
| float | vol = 1, | ||
| float | p = 0 ) |
Play a sound effect in stereo, but slightly differently each time it is played. The pitch is varied up and down by a random amount scaled by a coefficient of variability that is provided as a parameter.
| t | Sound enumerated type. |
| e | Type of sound to be played. |
| s | Position of emitter in 3D. |
| var | Coefficient of variability (defaults to 0.25). |
| vol | Volume (defaults to 1.0). |
| p | Pitch (defaults to 0). |
| CSoundDesc Sage::CSound::Vary | ( | t | e, |
| float | var = 0.1f, | ||
| float | vol = 1, | ||
| float | p = 0 ) |
Play a sound effect in mono, but slightly differently each time it is played. The pitch is varied up and down by a random amount scaled by a coefficient of variability that is provided as a parameter.
| t | Sound enumerated type. |
| e | Type of sound to be played. |
| var | Coefficient of variability (defaults to 0.25). |
| vol | Volume (defaults to 1.0). |
| p | Pitch (defaults to 0). |
