From cbe1374b032a80bf3d1cf13fd751ea35648c7bea Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Thu, 22 Sep 2022 13:36:03 -0400 Subject: [PATCH] sound set volume --- engine/xe_sound.cpp | 5 ++++- engine/xe_sound.hpp | 1 + src/first_app.cpp | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/engine/xe_sound.cpp b/engine/xe_sound.cpp index 09589fa..07d8e7b 100644 --- a/engine/xe_sound.cpp +++ b/engine/xe_sound.cpp @@ -18,7 +18,6 @@ XeSound::XeSound(const std::string& filename) { alSource3f(source, AL_VELOCITY, 0, 0, 0); alSourcei(source, AL_LOOPING, AL_FALSE); alSourcei(source, AL_BUFFER, buffer); - alSourcef(source, AL_GAIN, 3.f); } @@ -58,4 +57,8 @@ void XeSound::setLooping(bool looping) { alSourcei(source, AL_LOOPING, looping ? 1 : 0); }; +void XeSound::setVolume(float volume) { + alSourcef(source, AL_GAIN, volume); +} + } \ No newline at end of file diff --git a/engine/xe_sound.hpp b/engine/xe_sound.hpp index 334e793..b2a7a14 100644 --- a/engine/xe_sound.hpp +++ b/engine/xe_sound.hpp @@ -27,6 +27,7 @@ class XeSound { void setPosition(glm::vec3 position); void setLooping(bool looping); + void setVolume(float volume); private: ALuint source; diff --git a/src/first_app.cpp b/src/first_app.cpp index 30c639f..423012a 100755 --- a/src/first_app.cpp +++ b/src/first_app.cpp @@ -19,7 +19,7 @@ namespace app { -FirstApp::FirstApp() : xeEngine{WIDTH, HEIGHT, "Hello, Vulkan!"} { +FirstApp::FirstApp() : xeEngine{WIDTH, HEIGHT, "Xenon Vulkan Engine"} { loadGameObjects(); } @@ -33,6 +33,7 @@ void FirstApp::run() { SimpleRenderer renderer{xeEngine, image.get()}; xe::XeSound sound{"res/sound/when_the_world_ends.wav"}; + sound.setLooping(true); sound.play(); auto viewerObject = xe::XeGameObject::createGameObject(); @@ -51,6 +52,7 @@ void FirstApp::run() { renderer.render(gameObjects, xeEngine.getCamera(), image2.get()); xeEngine.endFrame(); } + } xeEngine.close();