|
From: Felix B. <fbe...@us...> - 2010-07-07 05:22:41
|
Module: performous
Branch: slowdown
Commit: 3fb16fc8c6c0605f89b9ba5c242742ac8f1a5f39
Author: Felix Bertram <fl...@be...>
Date: Mon Jul 5 22:47:14 2010 -0700
bugfix- fatal error for non-ogg files
---
game/audio.cc | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/game/audio.cc b/game/audio.cc
index 18824d8..31b9534 100644
--- a/game/audio.cc
+++ b/game/audio.cc
@@ -82,17 +82,20 @@ void Audio::playMusic(std::map<std::string,std::string> const& filenames, bool p
fadeout(fadeTime);
boost::shared_ptr<da::chain> ch(new da::chain());
for(std::map<std::string,std::string>::const_iterator it = filenames.begin() ; it != filenames.end() ; ++it ) {
- std::string f;
+ std::string f = it->second;
try {
- f = it->second;
if (speed != 100) {
// instead of real-time time-stretching we use previously created files
// best effects have been achieved with SBSMS library
// as used by Audacity's Sliding Time Scale/ Pitch Shift plugin
- std::string f2 = "-" + boost::lexical_cast<std::string>(speed) + ".ogg";
- f.replace(f.find(".ogg"), 4, f2);
- // std::cout << "loading time-stretched audio (" << f << ")" << std::endl;
+ size_t i = f.find_last_of(".");
+ if ((i == std::string::npos) || (f.length() - i > 5)) throw std::runtime_error("no file extension in \"" + f + "\"");
+ // for 75% speed a typical filename would be "song-75.ogg"
+ std::string f2 = "-" + boost::lexical_cast<std::string>(speed) + ".";
+ f.replace(i, 1, f2);
+
+ std::cout << "loading time-stretched audio (" << f << ")" << std::endl;
if (!boost::filesystem::exists(f)) throw std::runtime_error("time-stretched file \"" + f +"\" not found");
}
|