|
From: Yoda-JM <yo...@us...> - 2010-08-15 14:52:21
|
Module: performous
Branch: joinmenu
Commit: 3e2ae0eeceb114895884c11851f818fead791188
Author: Vincent Le Ligeour <yo...@us...>
Date: Mon Jul 5 16:02:29 2010 +0200
Moved all samples loading to init
---
game/audio.cc | 4 ++--
game/guitargraph.cc | 31 +++++++++++++------------------
game/guitargraph.hh | 2 +-
game/main.cc | 14 ++++++++++++++
game/screen_practice.cc | 20 +++++++-------------
game/screen_practice.hh | 2 +-
libs/libda/include/libda/portaudio.hpp | 4 ++--
7 files changed, 40 insertions(+), 37 deletions(-)
diff --git a/game/audio.cc b/game/audio.cc
index 0d9b7a5..97feaaf 100644
--- a/game/audio.cc
+++ b/game/audio.cc
@@ -167,10 +167,10 @@ struct Device {
portaudio::Stream stream;
std::vector<Analyzer*> mics;
Output* outptr;
-
+
Device(unsigned int in, unsigned int out, double rate, std::string dev):
in(in), out(out), rate(rate), dev(dev),
- stream(*this, in ? portaudio::Params().channelCount(in).device(dev, true) : NULL, out ? portaudio::Params().channelCount(out).device(dev, false) : NULL, rate)
+ stream(*this, in ? portaudio::Params().channelCount(in).device(dev, true) : (const PaStreamParameters*)NULL, (out ? portaudio::Params().channelCount(out).device(dev, false) : (const PaStreamParameters*)NULL), rate)
{
mics.resize(in);
}
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index d9e3383..86b5e32 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -100,25 +100,20 @@ GuitarGraph::GuitarGraph(Audio& audio, Song const& song, bool drums, int number,
// Score calculator (TODO a better one)
m_scoreText.reset(new SvgTxtThemeSimple(getThemePath("sing_score_text.svg"), config["graphic/text_lod"].f()));
m_streakText.reset(new SvgTxtThemeSimple(getThemePath("sing_score_text.svg"), config["graphic/text_lod"].f()));
- // Load fail sounds
if (m_drums) {
- m_samples.push_back(std::make_pair("drum bass", getPath("sounds/drum_bass.ogg")));
- m_samples.push_back(std::make_pair("drum snare", getPath("sounds/drum_snare.ogg")));
- m_samples.push_back(std::make_pair("drum hi-hat", getPath("sounds/drum_hi-hat.ogg")));
- m_samples.push_back(std::make_pair("drum tom1", getPath("sounds/drum_tom1.ogg")));
- m_samples.push_back(std::make_pair("drum cymbal", getPath("sounds/drum_cymbal.ogg")));
- //m_samples.push_back(std::make_pair("drum tom2", getPath("sounds/drum_tom2.ogg")));
+ m_samples.push_back("drum bass");
+ m_samples.push_back("drum snare");
+ m_samples.push_back("drum hi-hat");
+ m_samples.push_back("drum tom1");
+ m_samples.push_back("drum cymbal");
+ //m_samples.push_back("drum tom2");
} else {
- m_samples.push_back(std::make_pair("guitar fail1", getPath("sounds/guitar_fail1.ogg")));
- m_samples.push_back(std::make_pair("guitar fail2", getPath("sounds/guitar_fail2.ogg")));
- m_samples.push_back(std::make_pair("guitar fail3", getPath("sounds/guitar_fail3.ogg")));
- m_samples.push_back(std::make_pair("guitar fail4", getPath("sounds/guitar_fail4.ogg")));
- m_samples.push_back(std::make_pair("guitar fail5", getPath("sounds/guitar_fail5.ogg")));
- m_samples.push_back(std::make_pair("guitar fail6", getPath("sounds/guitar_fail6.ogg")));
- }
- // Warning the sample are shared between Guitargraphs, do not unload them
- for(unsigned int i = 0 ; i < m_samples.size() ; i++) {
- m_audio.loadSample(m_samples[i].first, m_samples[i].second);
+ m_samples.push_back("guitar fail1");
+ m_samples.push_back("guitar fail2");
+ m_samples.push_back("guitar fail3");
+ m_samples.push_back("guitar fail4");
+ m_samples.push_back("guitar fail5");
+ m_samples.push_back("guitar fail6");
}
for (int i = 0; i < 6; ++i) m_pressed_anim[i].setRate(5.0);
for (int i = 0; i < 5; ++i) m_holds[i] = 0;
@@ -409,7 +404,7 @@ void GuitarGraph::fail(double time, int fret) {
// Reduce points and play fail sample only when GodMode is deactivated
m_events.push_back(Event(time, 0, fret));
if (fret < 0) fret = std::rand();
- m_audio.playSample(m_samples[unsigned(fret) % m_samples.size()].first);
+ m_audio.playSample(m_samples[unsigned(fret) % m_samples.size()]);
// remove equivalent of 1 perfect hit for every note
// kids tend to play a lot of extra notes just for the fun of it.
// need to make sure they don't end up with a score of zero
diff --git a/game/guitargraph.hh b/game/guitargraph.hh
index 9e53408..0a41db2 100644
--- a/game/guitargraph.hh
+++ b/game/guitargraph.hh
@@ -88,7 +88,7 @@ class GuitarGraph: public InstrumentGraph {
glutil::Color m_neckglowColor;
Object3d m_fretObj; /// 3d object for regular note
Object3d m_tappableObj; /// 3d object for the HOPO note cap
- std::vector<std::pair<std::string, std::string> > m_samples; /// sound effects
+ std::vector<std::string> m_samples; /// sound effects
boost::scoped_ptr<Texture> m_neck; /// necks
boost::scoped_ptr<SvgTxtThemeSimple> m_scoreText;
boost::scoped_ptr<SvgTxtThemeSimple> m_streakText;
diff --git a/game/main.cc b/game/main.cc
index fcc41ec..f466381 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -117,6 +117,20 @@ void mainLoop(std::string const& songlist) {
boost::scoped_ptr<input::MidiDrums> midiDrums;
// TODO: Proper error handling...
try { midiDrums.reset(new input::MidiDrums); } catch (std::runtime_error&) {}
+ // Load audio samples
+ audio.loadSample("drum bass", getPath("sounds/drum_bass.ogg"));
+ audio.loadSample("drum snare", getPath("sounds/drum_snare.ogg"));
+ audio.loadSample("drum hi-hat", getPath("sounds/drum_hi-hat.ogg"));
+ audio.loadSample("drum tom1", getPath("sounds/drum_tom1.ogg"));
+ audio.loadSample("drum cymbal", getPath("sounds/drum_cymbal.ogg"));
+ //audio.loadSample("drum tom2", getPath("sounds/drum_tom2.ogg"));
+ audio.loadSample("guitar fail1", getPath("sounds/guitar_fail1.ogg"));
+ audio.loadSample("guitar fail2", getPath("sounds/guitar_fail2.ogg"));
+ audio.loadSample("guitar fail3", getPath("sounds/guitar_fail3.ogg"));
+ audio.loadSample("guitar fail4", getPath("sounds/guitar_fail4.ogg"));
+ audio.loadSample("guitar fail5", getPath("sounds/guitar_fail5.ogg"));
+ audio.loadSample("guitar fail6", getPath("sounds/guitar_fail6.ogg"));
+ // Load screens
sm.addScreen(new ScreenIntro("Intro", audio));
sm.addScreen(new ScreenSongs("Songs", audio, songs, database));
sm.addScreen(new ScreenSing("Sing", audio, database, backgrounds));
diff --git a/game/screen_practice.cc b/game/screen_practice.cc
index d0b2896..d48afd1 100644
--- a/game/screen_practice.cc
+++ b/game/screen_practice.cc
@@ -18,21 +18,15 @@ void ScreenPractice::enter() {
m_vumeters.push_back(b = new ProgressBar(getThemePath("vumeter_bg.svg"), getThemePath("vumeter_fg.svg"), ProgressBar::VERTICAL, 0.136, 0.023));
b->dimensions.screenBottom().left(-0.4 + i * 0.2).fixedWidth(0.04);
}
- m_samples.push_back(std::make_pair("drum bass", getPath("sounds/drum_bass.ogg")));
- m_samples.push_back(std::make_pair("drum snare", getPath("sounds/drum_snare.ogg")));
- m_samples.push_back(std::make_pair("drum hi-hat", getPath("sounds/drum_hi-hat.ogg")));
- m_samples.push_back(std::make_pair("drum tom1", getPath("sounds/drum_tom1.ogg")));
- m_samples.push_back(std::make_pair("drum cymbal", getPath("sounds/drum_cymbal.ogg")));
- //m_samples.push_back(std::make_pair("drum tom2", getPath("sounds/drum_tom2.ogg")));
- for(unsigned int i = 0 ; i < m_samples.size() ; i++) {
- m_audio.loadSample(m_samples[i].first, m_samples[i].second);
- }
+ m_samples.push_back("drum bass");
+ m_samples.push_back("drum snare");
+ m_samples.push_back("drum hi-hat");
+ m_samples.push_back("drum tom1");
+ m_samples.push_back("drum cymbal");
+ //m_samples.push_back("drum tom2");
}
void ScreenPractice::exit() {
- for(unsigned int i = 0 ; i < m_samples.size() ; i++) {
- m_audio.unloadSample(m_samples[i].first);
- }
m_vumeters.clear();
m_samples.clear();
theme.reset();
@@ -47,7 +41,7 @@ void ScreenPractice::manageEvent(SDL_Event event) {
else if (event.type == SDL_JOYBUTTONDOWN // Play drum sounds here
&& input::detail::devices[event.jbutton.which].type_match(input::DRUMS)) {
int b = input::buttonFromSDL(input::detail::devices[event.jbutton.which].type(), event.jbutton.button);
- if (b != -1) m_audio.playSample(m_samples[unsigned(b) % m_samples.size()].first);
+ if (b != -1) m_audio.playSample(m_samples[unsigned(b) % m_samples.size()]);
}
}
diff --git a/game/screen_practice.hh b/game/screen_practice.hh
index 2d472d2..f8156f5 100644
--- a/game/screen_practice.hh
+++ b/game/screen_practice.hh
@@ -23,7 +23,7 @@ class ScreenPractice : public Screen {
private:
Audio& m_audio;
- std::vector<std::pair<std::string, std::string> > m_samples;
+ std::vector<std::string> m_samples;
boost::ptr_vector<ProgressBar> m_vumeters;
boost::scoped_ptr<ThemePractice> theme;
};
diff --git a/libs/libda/include/libda/portaudio.hpp b/libs/libda/include/libda/portaudio.hpp
index a7987b9..8add471 100644
--- a/libs/libda/include/libda/portaudio.hpp
+++ b/libs/libda/include/libda/portaudio.hpp
@@ -19,7 +19,7 @@ namespace portaudio {
PaError m_code;
char const* m_func;
};
-
+
namespace internal {
void check(PaError code, char const* func) { if (code != paNoError) throw Error(code, func); }
}
@@ -70,7 +70,7 @@ namespace portaudio {
Params& hostApiSpecificStreamInfo(void* val) { params.hostApiSpecificStreamInfo = val; return *this; }
operator PaStreamParameters const*() const { return ¶ms; }
};
-
+
template <typename Functor> int functorCallback(void const* input, void* output, unsigned long frameCount, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void* userData) {
return (*static_cast<Functor*>(userData))(input, output, frameCount, timeInfo, statusFlags);
}
|