![]() |
The LARC Game Engine
A Simple Game Engine from the Laboratory for Recreational Computing
|
The Audio Player. More...
#include <Sound.h>
Public Member Functions | |
LSound () | |
Constructor. More... | |
~LSound () | |
Destructor. More... | |
template<class t > | |
void | Initialize (t n) |
Initialize. More... | |
template<class t > | |
void | Load (t, const char *) |
Load sound. More... | |
template<class t > | |
LSoundDesc | play (t, const Vector2 &, float=1, float=0) |
Play sound. More... | |
template<class t > | |
LSoundDesc | play (t, const Vector3 &, float=1, float=0) |
Play sound. More... | |
template<class t > | |
LSoundDesc | play (t, float=1) |
Play sound. More... | |
template<class t > | |
LSoundDesc | loop (t) |
Loop a sound. More... | |
template<class t > | |
LSoundDesc | loop (t, const Vector2 &) |
Loop a sound. More... | |
template<class t > | |
LSoundDesc | loop (t, const Vector3 &) |
Loop a sound. More... | |
template<class t > | |
LSoundDesc | vary (t, float=0.1f, float=1, float=0) |
Play a randomly varied sound. More... | |
template<class t > | |
LSoundDesc | vary (t, const Vector2 &, float=0.1f, float=1, float=0) |
Play a randomly varied sound. More... | |
template<class t > | |
LSoundDesc | vary (t, const Vector3 &, float=0.1f, float=1, float=0) |
Play a randomly varied sound. More... | |
void | BeginFrame () |
Start of frame notification. More... | |
void | mute () |
Mute/unmute the sounds. More... | |
void | stop () |
Stop all sounds. More... | |
template<class t > | |
void | stop (t) |
Stop a sound. More... | |
void | stop (const LSoundDesc &) |
Stop a sound instance. More... | |
void | SetListenerPos (const Vector3 &) |
Set listener position. More... | |
void | SetListenerOrient (const Vector3 &, const Vector3 &) |
Set listener orientation. More... | |
void | SetListener (LBaseCamera *) |
Set listener to camera pos and orientation. | |
void | SetScale (const float) |
Set scale for the sound world. More... | |
![]() | |
void | Load () |
Load game settings. More... | |
Protected Member Functions | |
void | createInstances (size_t, size_t, SOUND_EFFECT_INSTANCE_FLAGS) |
Create sound instances. More... | |
void | LoadByIndex (size_t, const char *) |
Load sound by index. More... | |
size_t | getNextInstance (size_t) |
Get the next instance that is not playing. More... | |
![]() | |
void | SetWinSize (int, int) |
Set window size information. More... | |
Protected Attributes | |
AudioEngine * | m_pAudioEngine = nullptr |
XAudio 2.8 Engine wrapped up in DirectXTK. | |
LPlayableSoundDesc * | 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. | |
Static Private Attributes | |
static bool | m_bSingularityViolation = false |
Enforces that this is a singular class. More... | |
Additional Inherited Members | |
![]() | |
static HWND | m_Hwnd = 0 |
Window handle. | |
static HINSTANCE | m_hInst = 0 |
Instance handle. | |
static bool | m_bExitSizeMove |
User just finished moving/resizing window. | |
![]() | |
static 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 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 LTimer * | m_pTimer = &cTimer |
Pointer to a timer. More... | |
static LRandom * | m_pRandom = &cRandom |
Pointer to a PRNG. More... | |
static LKeyboard * | m_pKeyboard = &cKeyboard |
Pointer to a keyboard handler. More... | |
static LXBoxController * | m_pController = &cController |
Pointer to a XBox controller. More... | |
static LSound * | m_pAudio = &cAudio |
Pointer to an audio player. More... | |
The Audio 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.
LSound::LSound | ( | ) |
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.
LSound::~LSound | ( | ) |
Reclaim all dynamic memory and shut down the audio engine.
void LSound::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. |
void LSound::Initialize | ( | t | e | ) |
Delete old sound descriptors and create the required number of new ones.
t | Sound enumerated type. |
e | Number of sounds. |
void LSound::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. |
LSoundDesc LSound::loop | ( | t | e | ) |
Loop a sound effect in mono.
t | Sound enumerated type. |
e | Type of sound to be looped. |
LSoundDesc LSound::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. |
LSoundDesc LSound::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 LSound::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.
LSoundDesc LSound::play | ( | t | e, |
const Vector2 & | s, | ||
float | vol = 1 , |
||
float | p = 0 |
||
) |
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). |
p | Pitch (defaults to zero). |
LSoundDesc LSound::play | ( | t | e, |
const Vector3 & | s, | ||
float | vol = 1 , |
||
float | p = 0 |
||
) |
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). |
LSoundDesc LSound::play | ( | t | e, |
float | vol = 1 |
||
) |
Play a sound effect in mono.
t | Sound enumerated type. |
e | Type of sound to be played. |
vol | Volume (defaults to 1.0f). |
void LSound::SetListenerOrient | ( | const Vector3 & | vLook, |
const Vector3 & | vUp | ||
) |
Set the listener orientation from a pair of vectors.
vLook | Look-at vector. |
vUp | Up vector. |
void LSound::SetListenerPos | ( | const Vector3 & | pos | ) |
Move the listener to a new position.
pos | New position of listener. |
void LSound::SetScale | ( | const float | scale | ) |
Set the scale factor for converting from render coordinates to sound coordinates.
scale | Scale factor. |
void LSound::stop | ( | ) |
Stop all instances of all sound effects.
void LSound::stop | ( | const LSoundDesc & | d | ) |
Stop an instance of a sound effects.
d | Descriptor for a sound instance. |
void LSound::stop | ( | t | e | ) |
Stop all instances of a sound effect.
t | Sound enumerated type. |
e | Type of sound to be stopped. |
LSoundDesc LSound::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). |
LSoundDesc LSound::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). |
LSoundDesc LSound::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). |
|
staticprivate |
Singularity violation flag.