Slippers Engine
 
Loading...
Searching...
No Matches
Sound

Examples for Sound Use. More...

Namespaces

namespace  Materials
 Collection of Materials stored as Floats.
 

Classes

class  Listener
 Responsible for Listener Object. Go To Scene for proper use. More...
 
class  OccludableObj
 Responsible for Occlusion Object functions. More...
 
class  OccludableSnd
 Responsible for Occlusion Sound functions. More...
 
class  Reverbable
 Responsible for Reverb functions. More...
 
class  ReverbSpace
 Responsible for Reverb Space functions. Go to Scene for Creation and Destruction. More...
 
class  SoundSourceBase
 Responsible for Base of Sound Sources. Go To Scene for creation and destruction. More...
 
class  SoundSourceListener
 Responsible for Sound Sources that always play at the Listener's position. Go To Scene for creation and destruction. More...
 
class  SoundSourceWorld
 Responsible for Sound Sources that can be placed in world space. Go To Scene for creation and destruction. More...
 

Detailed Description

Examples for Sound Use.

SoundDemo.h

#include "GameObject.h"
class SoundSource;
class SoundDemo : public GameObject {
public:
SoundDemo();
SoundDemo(const SoundTester&) = default;
SoundDemo& operator=(const SoundDemo&) = default;
~SoundDemo();
virtual void Update();
virtual void Draw();
virtual void KeyPress(AZUL_KEY k);
void Controls();
void SetPositions(float f);
private:
enum class MoveState { STILL, FORWARD, SIDE };
enum class RevPos { NONE, EDGE, FULL };
enum class RevType { ROOM, CATHEDRAL, CAVE };
Panel* pan;
SoundSourceWorld* sound;
ReverbSpace* room;
ReverbSpace* cathedral;
ReverbSpace* cave;
RevType currType = RevType::ROOM;
RevPos currPos = RevPos::NONE;
GraphicsObject_TextureFlat* speaker;
MoveState myState = MoveState::STILL;
bool registerRev = false;
bool atWorld = false;
bool registerOcc = false;
float volume = 1;
float x = 0;
float z = 0;
};
virtual void Draw()
Fill this with code that occurs during the Draw phase.
Definition Drawable.h:53
Responsible for GameObject centralization.
Definition GameObject.h:182
virtual void KeyPress(AZUL_KEY k)
Fill this with code that occurs on a key press.
Definition Inputable.h:69
Responsible for Reverb Space functions. Go to Scene for Creation and Destruction.
Definition ReverbSpace.h:24
virtual void Update()
Fill this with code that occurs during the Update phase.
Definition Updatable.h:54

SoundDemo.cpp

#include "SoundDemo.h"
#include "SoundManager.h"
#include "ReverbManager.h"
#include "ReverbSpace.h"
#include "ModelManager.h"
#include "ShaderManager.h"
#include "TextureManager.h"
#include "Panel.h"
SoundDemo::SoundDemo() {
Matrix world = Matrix(SCALE, 10, 10, 10);
speaker->SetWorld(world);
MathTools::SetPos(speaker->getWorld(), 0, 200, 150);
sound->SetPos(speaker->getWorld().get(ROW_3));
room->SetScale(100);
cathedral->SetScale(100);
cave->SetScale(100);
//Play
//Swap Sound
//Enable Reverb
//Change Reverb
//Change Reverb Pos
//Pause/Stop
//Mute/Unmute
//Loop
//Move Sound
//Occlusion
}
SoundDemo::~SoundDemo() {
delete speaker;
}
void SoundDemo::Update() {
float t = TimeManager::GetTime(); // Or however you get total elapsed time
float speed = .5f;
float minZ = 50.0f;
float maxZ = 1500.0f;
float midZ = (minZ + maxZ) / 2.0f;
float ampZ = (maxZ - minZ) / 2.0f;
z = midZ + ampZ * sinf(t * 3.14159f * speed); // Oscillates between 100 and 200
float minX = -200.0f;
float maxX = 200.0f;
float midX = (minX + maxX) / 2.0f;
float ampX = (maxX - minX) / 2.0f;
x = midX + ampX * sinf(t * 3.14159f * speed * .25f);
if (atWorld == false) {
SetPositions(200);
}
else {
SetPositions(20);
}
}
void SoundDemo::SetPositions(float f) {
switch (myState) {
case MoveState::STILL:
MathTools::SetPos(speaker->getWorld(), 0, f, 500);
break;
case MoveState::FORWARD:
MathTools::SetPos(speaker->getWorld(), 0, f, z);
break;
case MoveState::SIDE:
MathTools::SetPos(speaker->getWorld(), x, f, 500);
break;
}
sound->SetPos(speaker->getWorld().get(ROW_3));
if (registerRev) {
switch (currPos) {
case RevPos::NONE:
switch (currType) {
case RevType::ROOM:
room->SetPos(0, f, 300);
cathedral->SetPos(0, f, -1000);
cave->SetPos(0, f, -1000);
break;
case RevType::CATHEDRAL:
cathedral->SetPos(0, f, 300);
room->SetPos(0, f, -1000);
cave->SetPos(0, f, -1000);
break;
case RevType::CAVE:
cave->SetPos(0, f, 300);
cathedral->SetPos(0, f, -1000);
room->SetPos(0, f, -1000);
break;
}
break;
case RevPos::EDGE:
switch (currType) {
case RevType::ROOM:
room->SetPos(0, f, 95);
cathedral->SetPos(0, f, -1000);
cave->SetPos(0, f, -1000);
break;
case RevType::CATHEDRAL:
cathedral->SetPos(0, f, 95);
room->SetPos(0, f, -1000);
cave->SetPos(0, f, -1000);
break;
case RevType::CAVE:
cave->SetPos(0, f, 95);
cathedral->SetPos(0, f, -1000);
room->SetPos(0, f, -1000);
break;
}
break;
case RevPos::FULL:
switch (currType) {
case RevType::ROOM:
room->SetPos(0, f, 0);
cathedral->SetPos(0, f, -1000);
cave->SetPos(0, f, -1000);
break;
case RevType::CATHEDRAL:
cathedral->SetPos(0, f, 0);
room->SetPos(0, f, -1000);
cave->SetPos(0, f, -1000);
break;
case RevType::CAVE:
cave->SetPos(0, f, 0);
cathedral->SetPos(0, f, -1000);
room->SetPos(0, f, -1000);
break;
}
break;
}
}
else {
room->SetPos(0, f, -1000);
cathedral->SetPos(0, f, -1000);
cave->SetPos(0, f, -1000);
}
}
void SoundDemo::Controls() {
ScreenLog::Add("PLAYING");
ScreenLog::Add("SPACE : Play");
ScreenLog::Add("O : Stop");
ScreenLog::Add("P : Pause");
ScreenLog::Add("VOLUME %.2f", volume);
ScreenLog::Add("M : Volume Up");
ScreenLog::Add("N : Volume Down");
ScreenLog::Add("LOOPING");
ScreenLog::Add("L : Loop");
ScreenLog::Add("K : Unloop");
ScreenLog::Add("CHANGING SOUND");
ScreenLog::Add("1 : Set Sound Beep");
ScreenLog::Add("2 : Set Sound Slip");
ScreenLog::Add("3 : Set Sound Bohemian");
ScreenLog::Add("MOVING");
ScreenLog::Add("Z : Move Source Center");
ScreenLog::Add("X : Move Source Forward/Backward");
ScreenLog::Add("C : Move Source Left/Right");
ScreenLog::Add("ENABLING REVERB");
ScreenLog::Add("R : Enable Reverb");
ScreenLog::Add("T : Disable Reverb");
ScreenLog::Add("CHANGING REVERB SPACE");
ScreenLog::Add("Q : Set Reverb Space Room");
ScreenLog::Add("W : Set Reverb Space Cathedral");
ScreenLog::Add("E : Set Reverb Space Cave");
ScreenLog::Add("CHANGING REVERB POSITION");
ScreenLog::Add("A : Set Reverb Space Outside");
ScreenLog::Add("S : Set Reverb Space Edge");
ScreenLog::Add("D : Set Reverb Space Inside");
pan->Add("");
pan->Add("");
pan->Add("ENABLING OCCLUSION");
pan->Add("9 : Enable Occlusion");
pan->Add("0 : Disable Occlusion");
pan->Add("");
pan->Add("CHANGING OCCLUDABLE MATERIAL");
pan->Add("5 : Terrain Dirt");
pan->Add("6 : Brick");
pan->Add("7 : Wool");
pan->Add("8 : Wood");
}
void SoundDemo::Draw() {
Controls();
speaker->Render(SceneManager::GetCurrScene()->GetCurrCam());
room->Visualize();
cathedral->Visualize();
cave->Visualize();
}
void SoundDemo::KeyPress(AZUL_KEY k) {
switch (k) {
case AZUL_KEY::KEY_SPACE:
sound->Play();
break;
case AZUL_KEY::KEY_1:
sound->SetSound(SoundManager::GetSoundMono("Beep"));
break;
case AZUL_KEY::KEY_2:
sound->SetSound(SoundManager::GetSoundMono("Slip"));
break;
case AZUL_KEY::KEY_3:
sound->SetSound(SoundManager::GetSoundMono("BohemianMono"));
break;
case AZUL_KEY::KEY_R:
if (registerRev == false) {
sound->Reverbable::SubmitRegistration();
registerRev = true;
}
break;
case AZUL_KEY::KEY_T:
if (registerRev == true) {
sound->Reverbable::SubmitDeregistration();
registerRev = false;
}
break;
case AZUL_KEY::KEY_Q:
currType = RevType::ROOM;
break;
case AZUL_KEY::KEY_W:
currType = RevType::CATHEDRAL;
break;
case AZUL_KEY::KEY_E:
currType = RevType::CAVE;
break;
case AZUL_KEY::KEY_A:
currPos = RevPos::NONE;
break;
case AZUL_KEY::KEY_S:
currPos = RevPos::EDGE;
break;
case AZUL_KEY::KEY_D:
currPos = RevPos::FULL;
break;
case AZUL_KEY::KEY_P:
sound->Pause();
break;
case AZUL_KEY::KEY_O:
sound->Stop();
break;
case AZUL_KEY::KEY_M:
//You can go above 10, but wanted a cap
volume = MathTools::Clamp(volume + .25f, 0.0f, 10.0f);
sound->SetGain(volume);
break;
case AZUL_KEY::KEY_N:
volume = MathTools::Clamp(volume - .25f, 0.0f, 10.0f);
sound->SetGain(volume);
break;
case AZUL_KEY::KEY_L:
sound->SetLooping(true);
break;
case AZUL_KEY::KEY_K:
sound->SetLooping(false);
break;
case AZUL_KEY::KEY_Z:
myState = MoveState::STILL;
break;
case AZUL_KEY::KEY_X:
myState = MoveState::FORWARD;
break;
case AZUL_KEY::KEY_C:
myState = MoveState::SIDE;
break;
case AZUL_KEY::KEY_9:
atWorld = false;
registerOcc = true;
sound->OccludableSnd::SubmitRegistration();
SceneManager::GetCurrScene()->MoveCam(Vect(0, 1, 0), Vect(0, 200, 1, 0), Vect(0, 200, 0, 0));
SceneManager::GetCurrScene()->SetListenerOrientation(Vect(0, 200, 1, 0), Vect(0, 1, 0));
break;
case AZUL_KEY::KEY_0:
atWorld = false;
registerOcc = false;
sound->OccludableSnd::SubmitDeregistration();
SceneManager::GetCurrScene()->MoveCam(Vect(0, 1, 0), Vect(0, 200, 1, 0), Vect(0, 200, 0, 0));
SceneManager::GetCurrScene()->SetListenerOrientation(Vect(0, 200, 1, 0), Vect(0, 1, 0));
break;
case AZUL_KEY::KEY_5:
if (registerOcc == true) {
atWorld = true;
SceneManager::GetCurrScene()->MoveCam(Vect(0, 1, 0), Vect(0, 20, 1, 0), Vect(0, 20, 0, 0));
SceneManager::GetCurrScene()->SetListenerOrientation(Vect(0, 20, 1, 0), Vect(0, 1, 0));
}
break;
case AZUL_KEY::KEY_6:
atWorld = false;
SceneManager::GetCurrScene()->MoveCam(Vect(0, 1, 0), Vect(0, 200, 1, 0), Vect(0, 200, 0, 0));
SceneManager::GetCurrScene()->SetListenerOrientation(Vect(0, 200, 1, 0), Vect(0, 1, 0));
break;
case AZUL_KEY::KEY_7:
atWorld = false;
SceneManager::GetCurrScene()->MoveCam(Vect(0, 1, 0), Vect(0, 200, 1, 0), Vect(0, 200, 0, 0));
SceneManager::GetCurrScene()->SetListenerOrientation(Vect(0, 200, 1, 0), Vect(0, 1, 0));
break;
case AZUL_KEY::KEY_8:
atWorld = false;
SceneManager::GetCurrScene()->MoveCam(Vect(0, 1, 0), Vect(0, 200, 1, 0), Vect(0, 200, 0, 0));
SceneManager::GetCurrScene()->SetListenerOrientation(Vect(0, 200, 1, 0), Vect(0, 1, 0));
break;
}
}
@ KEY_PRESS
Definition KeyStateCommon.h:6
void SubmitRegistration()
Called when wanting to show graphics objects on screen.
Definition Drawable.cpp:37
static int GetHeight()
Returns window's height in pixels.
Definition Game.h:174
void SubmitRegistration(AZUL_KEY k, EVENT_TYPE e)
Called when wanting to check for a specific key.
Definition Inputable.cpp:49
static Model * GetModel(const MapKey &key)
Load Shader with KEY and AZUL's PREMADEMODELS.
Definition ModelManager.h:98
@ UNITBOX
Definition ModelManager.h:21
static const ALuint & GetReverb(DefaultReverbs key)
Returns Reverb from DEFAULT REVERBS.
Definition ReverbManager.h:85
@ CAVE
Definition ReverbManager.h:21
@ SMALLROOM
Definition ReverbManager.h:21
@ CATHEDRAL
Definition ReverbManager.h:21
void SetScale(float s)
Sets scale of Reverb Space. If generated with dynamic reverb, then recalculates.
Definition ReverbSpace.cpp:101
void SetListenerOrientation(Vect lookAt, Vect up)
Gets Listener Position. For more information go to Listener.
Definition Scene.cpp:153
void MoveCam(Vect up, Vect lookAt, Vect pos)
Moves Current Camera. For more information go to CameraManager.
Definition Scene.cpp:129
void ReturnReverbSpace(ReverbSpace *s)
Used to return a ReverbSpace to a scene.
Definition Scene.cpp:193
ReverbSpace * CreateReverbSpace(const ALuint &reverb)
Used to create a ReverbSpace with a reverb from ReverbManager.
Definition Scene.cpp:185
void UpdateCam()
Updates Current Camera. For more information go to CameraManager.
Definition Scene.cpp:133
void SetListenerPos(Vect p)
Sets Listener Position. For more information go to Listener.
Definition Scene.cpp:141
SoundSourceWorld * CreateSourceWorld()
Used to create a SoundSourceWorld.
Definition Scene.cpp:165
void ReturnSoundSource(SoundSourceWorld *w)
Used to return a sound to a scene.
Definition Scene.cpp:173
static Scene * GetCurrScene()
Returns pointer to current scene.
Definition SceneManager.h:51
static Panel * CreatePanel(int x, int y, Vect bkgColor=Vect(0, 0, 0, 0), Vect borderColor=Vect(0, 0, 0, 0))
Creates a panel for extra screen logging tools.
Definition ScreenLog.h:102
static void Add(char *A,...)
Adds a new line to the top left Screen Logger.
Definition ScreenLog.cpp:49
static ShaderObject * GetShader(const MapKey &key)
Returns shader object pointer with given KEY.
Definition ShaderManager.h:71
@ TEXTUREFLAT
Definition ShaderManager.h:20
static Sound GetSoundMono(const MapKey &key)
Returns Mono Sound with given KEY.
Definition SoundManager.h:93
virtual void SetSound(SoundManager::Sound s) override
Sets sound to be played.
Definition SoundSourceWorld.cpp:19
static Texture * GetTexture(const MapKey &key)
Returns texture pointer with given KEY.
Definition TextureManager.h:134
@ BLACK
Definition TextureManager.h:52
static float GetTime()
Returns Current Time.
Definition TimeManager.h:60
void SubmitRegistration()
Called when wanting to make changes every frame.
Definition Updatable.cpp:37
static float Clamp(const float &f, const float &min, const float &max)
Clamps a float between two other floats.
Definition MathTools.cpp:594
static void SetPos(Matrix &world, float x, float y, float z)
Sets world position to exact XYZ coordinates.
Definition MathTools.cpp:299

OccludableDemo.h

#include "GameObject.h"
#include "AzulCore.h"
class OccludableDemo : public GameObject {
public:
enum class Mat { BRICK, WOOL, WOOD };
OccludableTest(Mat type);
OccludableTest(const OccludableTest&) = default;
OccludableTest& operator=(const OccludableTest&) = default;
~OccludableTest();
void SetPos(float x, float y, float z);
private:
Mat myType;
bool enabled = false;
GraphicsObject_TextureLight* pGObj_OccludableTest;
virtual void Draw();
virtual void KeyPress(AZUL_KEY k);
};

OccludableDemo.cpp

#include "OccludableDemo.h"
#include "ModelManager.h"
#include "ShaderManager.h"
#include "TextureManager.h"
#include "SceneManager.h"
#include "Scene.h"
#include "SceneSwapTest.h"
OccludableDemo::OccludableDemo(Mat type) {
myType = type;
Vect LightColor(1.50f, 1.50f, 1.50f, 1.0f);
Vect LightPos(1.0f, 1.0f, 1.0f, 1.0f);
switch (myType)
{
case OccludableDemo::Mat::BRICK:
pGObj_OccludableTest = new GraphicsObject_TextureLight(ModelManager::GetModel(ModelManager::DefaultModels::UNITBOX),
, LightColor, LightPos);
break;
case OccludableDemo::Mat::WOOL:
pGObj_OccludableTest = new GraphicsObject_TextureLight(ModelManager::GetModel(ModelManager::DefaultModels::UNITBOX),
, LightColor, LightPos);
break;
case OccludableDemo::Mat::WOOD:
pGObj_OccludableTest = new GraphicsObject_TextureLight(ModelManager::GetModel(ModelManager::DefaultModels::UNITBOX),
, LightColor, LightPos);
break;
}
Matrix world = Matrix(SCALE, 15, 15, 15);
pGObj_OccludableTest->SetWorld(world);
}
OccludableDemo::~OccludableDemo() {
delete pGObj_OccludableTest;
}
void OccludableDemo::SetPos(float x, float y, float z) {
MathTools::SetPos(pGObj_OccludableTest->getWorld(), x, y, z);
OccludableObj::UpdateOcclusionData(pGObj_OccludableTest->getWorld());
}
void OccludableDemo::KeyPress(AZUL_KEY k) {
switch (k)
{
case AZUL_KEY::KEY_5:
SetPos(0, 200, -100);
break;
case AZUL_KEY::KEY_6:
if (myType == Mat::BRICK) {
SetPos(0, 200, 100);
}
else {
SetPos(0, 200, -100);
}
break;
case AZUL_KEY::KEY_7:
if (myType == Mat::WOOL) {
SetPos(0, 200, 100);
}
else {
SetPos(0, 200, -100);
}
break;
case AZUL_KEY::KEY_8:
if (myType == Mat::WOOD) {
SetPos(0, 200, 100);
}
else {
SetPos(0, 200, -100);
}
break;
case AZUL_KEY::KEY_9:
enabled = true;
if (myType == Mat::BRICK) {
SetPos(0, 200, 100);
}
else {
SetPos(0, 200, -100);
}
break;
case AZUL_KEY::KEY_0:
enabled = false;
break;
}
if (enabled == false) {
SetPos(0, 200, -100);
}
}
void OccludableDemo::Draw() {
pGObj_OccludableTest->Render(SceneManager::GetCurrScene()->GetCurrCam());
}
void SetOcclusionModel(Model *mod)
Stores an Objects Occlusion Model for calculating collisions.
Definition OccludableObj.cpp:69
virtual void SubmitRegistration(float mat)
Called when wanting to make an object block sounds.
Definition OccludableObj.cpp:49
void UpdateOcclusionData(const Matrix &mat)
Updates Objects Occlusion Model for proper scaling and positioning.
Definition OccludableObj.cpp:73
@ TEXTURELIGHT
Definition ShaderManager.h:20
static const float Curtains
Definition MaterialsCommon.h:20
static const float Wood
Definition MaterialsCommon.h:18
static const float Brick
Definition MaterialsCommon.h:15