|
From: Lasse Kärkkäi. <tr...@us...> - 2010-08-12 22:44:57
|
Module: performous
Branch: master
Commit: 65b738ec82f831d249d043f18a9783b4b5f5440e
Author: Lasse Karkkainen <tro...@tr...>
Date: Sat Jun 19 04:07:46 2010 +0300
Audio cleanup, fix freezing and implement pause.
---
game/audio.cc | 13 ++++++++++---
game/audio.hh | 16 ++++------------
2 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/game/audio.cc b/game/audio.cc
index bc45462..bcffa80 100644
--- a/game/audio.cc
+++ b/game/audio.cc
@@ -74,7 +74,8 @@ struct Audio::Impl {
boost::ptr_vector<Music> playing, disposing;
portaudio::Init init;
boost::ptr_vector<portaudio::Stream> streams;
- Impl() {
+ volatile bool paused;
+ Impl(): paused(false) {
std::string dev;
streams.push_back(new portaudio::Stream(*this, portaudio::Params().channelCount(2).device(dev, true), portaudio::Params().channelCount(2).device(dev, false), 48000));
PaError err = Pa_StartStream(streams[0]);
@@ -92,6 +93,7 @@ struct Audio::Impl {
void callbackInput(float const* begin, float const* end) {}
void callbackOutput(float* begin, float* end) {
std::fill(begin, end, 0.0f);
+ if (paused) return;
for (size_t i = 0; i < playing.size();) {
bool keep = playing[i](begin, end);
// Disposing hack
@@ -139,9 +141,13 @@ void Audio::playMusic(std::string const& filename, bool preview, double fadeTime
}
void Audio::stopMusic() {
+ std::map<std::string,std::string> m;
+ playMusic(m, false, 0.0);
}
void Audio::fadeout(double fadeTime) {
+ std::map<std::string,std::string> m;
+ playMusic(m, false, fadeTime);
}
double Audio::getPosition() const {
@@ -176,10 +182,11 @@ void Audio::seekPos(double pos) {
}
void Audio::pause(bool state) {
- boost::mutex::scoped_lock l(self->mutex);
- pause(state);
+ self->paused = state;
}
+bool Audio::isPaused() const { return self->paused; }
+
void Audio::streamFade(std::string stream_id, double level) {
}
diff --git a/game/audio.hh b/game/audio.hh
index 8455836..bbe5045 100644
--- a/game/audio.hh
+++ b/game/audio.hh
@@ -38,8 +38,6 @@ public:
void playMusic(std::map<std::string,std::string> const& filenames, bool preview = false, double fadeTime = 0.5, double startPos = -0.2);
/// plays a sample
void play(Sample const& s, std::string const& volumeSetting);
- /// get pause status
- bool isPaused() { return m_paused; }
/// stops music
void stopMusic();
/// fades music out
@@ -58,17 +56,11 @@ public:
bool isPlaying() const;
/** Get the current position. If not known or nothing is playing, NaN is returned. **/
double getPosition() const;
- void operator()(); ///< Thread runs here, don't call directly
- /// pauses and unpauses playback
- void togglePause() { pause(!m_paused); }
+ void togglePause() { pause(!isPaused()); }
void pause(bool state = true);
- /// toggles synth playback (F4)
- void toggleSynth(Notes const& notes) { m_notes = (m_notes ? NULL : ¬es); }
+ bool isPaused() const;
+ void toggleSynth(Notes const& notes) { /*m_notes = (m_notes ? NULL : ¬es); */} ///< toggles synth playback
void streamFade(std::string stream_id, double level);
- unsigned int getSR() const { return 0; }
-private:
- bool m_paused;
- Notes const* volatile m_notes;
- std::string m_volumeSetting;
+ unsigned int getSR() const { return 48000.0; }
};
|