From e4be73051a68b552c44280bbe9836dd4f02972d8 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 29 Nov 2024 20:35:17 +0100 Subject: audio system kinda working --- src/crepe/facade/SoundContext.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/crepe/facade/SoundContext.cpp') diff --git a/src/crepe/facade/SoundContext.cpp b/src/crepe/facade/SoundContext.cpp index b65dfb2..3e9a3d1 100644 --- a/src/crepe/facade/SoundContext.cpp +++ b/src/crepe/facade/SoundContext.cpp @@ -6,10 +6,37 @@ using namespace crepe; SoundContext::SoundContext() { dbg_trace(); - engine.init(); + this->engine.init(); + this->engine.setMaxActiveVoiceCount(this->config.audio.voices); } SoundContext::~SoundContext() { dbg_trace(); - engine.deinit(); + this->engine.deinit(); } + +Sound::Handle SoundContext::play(Sound & resource) { + return { + .handle = this->engine.play(resource.sample, this->default_volume), + }; +} + +void SoundContext::stop(Sound::Handle & handle) { + this->engine.stop(handle.handle); +} + +void SoundContext::set_volume(Sound & resource, Sound::Handle & handle, float volume) { + this->engine.setVolume(handle.handle, volume); + this->default_volume = volume; +} + +void SoundContext::set_loop(Sound & resource, Sound::Handle & handle, bool loop) { + this->engine.setLooping(handle.handle, loop); +} + +bool SoundContext::get_playing(Sound::Handle & handle) { + // See Soloud::stopVoice_internal in soloud/src/core/soloud_core_voiceops.cpp for why this is + // the correct method to use here (samples are currently never paused) + return this->engine.isValidVoiceHandle(handle.handle); +} + -- cgit v1.2.3