From ebffda717b1b633baba7a313267505614f89f26e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 13 Apr 2013 11:44:16 +0200 Subject: Implemented AudioChange (partially) There is some issues due to #173 Issue #172 --- src/sound/oalsound/alsound.cpp | 48 ++++++++++++++++-------------------------- src/sound/oalsound/alsound.h | 2 +- 2 files changed, 19 insertions(+), 31 deletions(-) (limited to 'src/sound/oalsound') diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 3ce975b..48fcc15 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -539,44 +539,32 @@ void ALSound::SetListener(Math::Vector eye, Math::Vector lookat) } } - bool ALSound::PlayMusic(int rank, bool bRepeat) +{ + std::stringstream filename; + filename << "music" << std::setfill('0') << std::setw(3) << rank << ".ogg"; + return PlayMusic(filename.str(), bRepeat); +} + +bool ALSound::PlayMusic(std::string filename, bool bRepeat) { if (!mEnabled) { return false; } - - if (static_cast(mCurrentMusic->GetSoundType()) != rank) { - // check if we have music in cache - for (auto music : mMusicCache) { - if (static_cast(music->GetSoundType()) == rank) { - GetLogger()->Debug("Music loaded from cache\n"); - mCurrentMusic->SetBuffer(music); - - mCurrentMusic->SetVolume(mMusicVolume); - mCurrentMusic->SetLoop(bRepeat); - mCurrentMusic->Play(); - return true; - } - } - - // we cache only 3 music files - if (mMusicCache.size() == 3) { - mCurrentMusic->FreeBuffer(); - mMusicCache.pop_back(); - } - if (mMusic.find(rank) == mMusic.end()) { - GetLogger()->Info("Requested music %d was not found.\n", rank); - return false; - } + std::stringstream file; + file << m_soundPath << "/" << filename; - Buffer *buffer = new Buffer(); - mMusicCache.push_front(buffer); - buffer->LoadFromFile(mMusic.at(rank), static_cast(rank)); - mCurrentMusic->SetBuffer(buffer); - mMusicCache[rank] = buffer; + if (!boost::filesystem::exists(file.str())) { + GetLogger()->Warn("Requested music %s was not found.\n", filename.c_str()); + return false; } + + // TODO: Cache + + Buffer *buffer = new Buffer(); + buffer->LoadFromFile(file.str(), static_cast(-1)); + mCurrentMusic->SetBuffer(buffer); mCurrentMusic->SetVolume(mMusicVolume); mCurrentMusic->SetLoop(bRepeat); diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index 5701997..7e0503a 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -66,6 +66,7 @@ class ALSound : public CSoundInterface bool MuteAll(bool bMute); bool PlayMusic(int rank, bool bRepeat); + bool PlayMusic(std::string filename, bool bRepeat); bool RestartMusic(); void SuspendMusic(); void StopMusic(); @@ -91,7 +92,6 @@ class ALSound : public CSoundInterface ALCcontext* mContext; std::map mSounds; std::map mChannels; - std::deque mMusicCache; Channel *mCurrentMusic; Math::Vector mEye; Math::Vector mLookat; -- cgit v1.2.3-1-g7c22