|
From: Yoda-JM <yo...@us...> - 2009-07-18 12:23:43
|
Module: performous
Branch: master
Commit: 793433e92d6cb80bcc32bd7706040473a3191410
Author: Vincent Le Ligeour <yo...@us...>
Date: Sat Jul 18 14:23:03 2009 +0200
Added some code that sometimes works for audio sync
---
game/audio.cc | 15 +++++++++++++--
game/audio.hh | 10 ++++++++++
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/game/audio.cc b/game/audio.cc
index 3ce352d..b49e06f 100644
--- a/game/audio.cc
+++ b/game/audio.cc
@@ -43,8 +43,19 @@ void Audio::operator()(da::pcm_data& areas, da::settings const&) {
double tmp = it->mpeg.position();
if( tmp > position ) position = tmp;
}
- for (Streams::iterator it = m_streams.begin(); it != m_streams.end(); ++it) {
- it->mpeg.seek(position);
+ unsigned int i = 0;
+ for (Streams::iterator it = m_streams.begin(); it != m_streams.end(); ++it,++i) {
+ if( it->fadingout() ) continue;
+ double shift = position - it->mpeg.position();
+ if( shift != 0 ) {
+ std::cout << "Moving stream " << i << " " << shift << "s forward";
+ if( it->consume(shift) ) {
+ std::cout << " SUCCESS" << std::endl;
+ } else {
+ // here we should say that this stream still need to be synched with one of the sucess one
+ std::cout << " FAIL (not enough data)" << std::endl;
+ }
+ }
}
*/
m_need_resync = false;
diff --git a/game/audio.hh b/game/audio.hh
index ca9a3b6..876ca3c 100644
--- a/game/audio.hh
+++ b/game/audio.hh
@@ -87,6 +87,16 @@ struct Stream {
void fadeout(double time) { fadeSpeed = - 1.0 / (time * srate); }
/// is the stream fading out
bool fadingout() {return fadeSpeed < 0;}
+ bool consume(double duration) {
+ std::vector<int16_t> buf;
+ unsigned int samples = srate * duration;
+ mpeg.audioQueue.tryPop(buf, samples);
+ if( buf.size() == samples ) {
+ return true;
+ } else {
+ return false;
+ }
+ }
/// crossfades songs
template <typename RndIt> void playmix(RndIt outbuf, unsigned int maxSamples) {
if (prebuffering && mpeg.audioQueue.percentage() > 0.9) prebuffering = false;
|