1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-23 02:42:39 +01:00

Implement stopMusic method

This commit is contained in:
Timmy Sjöstedt 2016-05-27 14:32:14 +02:00
parent 861dbf0c2a
commit 5294b40c40
4 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -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);

View File

@ -49,6 +49,10 @@ mad_flow MADStream::ms_output(void* user, mad_header const* header, mad_pcm* pcm
MADStream* self = static_cast<MADStream*>(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));
}

View File

@ -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)
{