From 5294b40c40ce428b0cd3a55336d3b12318f4ea07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timmy=20Sj=C3=B6stedt?= Date: Fri, 27 May 2016 14:32:14 +0200 Subject: [PATCH] Implement stopMusic method --- rwengine/include/audio/MADStream.hpp | 3 +++ rwengine/include/audio/SoundManager.hpp | 1 + rwengine/src/audio/MADStream.cpp | 10 ++++++++++ rwengine/src/audio/SoundManager.cpp | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/rwengine/include/audio/MADStream.hpp b/rwengine/include/audio/MADStream.hpp index cef1cacb..11d412f7 100644 --- a/rwengine/include/audio/MADStream.hpp +++ b/rwengine/include/audio/MADStream.hpp @@ -33,6 +33,8 @@ class MADStream : public sf::SoundStream size_t currentBuffer = 0; ALuint alSource; + bool stopped = false; + static inline signed int scale(mad_fixed_t sample); static mad_flow ms_header(void* user, mad_header const* header); static mad_flow ms_input(void* user, mad_stream* stream); @@ -50,6 +52,7 @@ public: bool openFromFile(const std::string& loc); void play(); + void stop(); }; #endif diff --git a/rwengine/include/audio/SoundManager.hpp b/rwengine/include/audio/SoundManager.hpp index 3639d2b2..1953bfab 100644 --- a/rwengine/include/audio/SoundManager.hpp +++ b/rwengine/include/audio/SoundManager.hpp @@ -26,6 +26,7 @@ public: bool loadMusic(const std::string& name, const std::string& fileName); void playMusic(const std::string& name); + void stopMusic(const std::string& name); void pause(bool p); diff --git a/rwengine/src/audio/MADStream.cpp b/rwengine/src/audio/MADStream.cpp index f88b20fa..8a9700e9 100644 --- a/rwengine/src/audio/MADStream.cpp +++ b/rwengine/src/audio/MADStream.cpp @@ -49,6 +49,10 @@ mad_flow MADStream::ms_output(void* user, mad_header const* header, mad_pcm* pcm MADStream* self = static_cast(user); + if (self->stopped) { + return MAD_FLOW_STOP; + } + int nsamples = pcm->length; mad_fixed_t const *left, *right; @@ -153,3 +157,9 @@ void MADStream::play() { alCheck(alSourcePlay(alSource)); } + +void MADStream::stop() +{ + stopped = true; + alCheck(alSourcePlay(alSource)); +} diff --git a/rwengine/src/audio/SoundManager.cpp b/rwengine/src/audio/SoundManager.cpp index ca465321..68ee3dc7 100644 --- a/rwengine/src/audio/SoundManager.cpp +++ b/rwengine/src/audio/SoundManager.cpp @@ -136,6 +136,10 @@ void SoundManager::playMusic(const std::string& name) { musics[name].play(); } +void SoundManager::stopMusic(const std::string& name) +{ + musics[name].stop(); +} void SoundManager::pause(bool p) {