Yet another fwd/rev animation curve

This commit is contained in:
Matthias Neeracher 2011-09-11 20:17:02 +02:00
parent 22180008d2
commit 72c4ac4d2b

View File

@ -288,18 +288,24 @@ void VLAUSoundOut::SetPlayRate(float rate)
MusicPlayerSetPlayRateScalar(fPlayer, fPlayRate); MusicPlayerSetPlayRateScalar(fPlayer, fPlayRate);
} }
static MusicTimeStamp sLastSkip = 0.0; const MusicTimeStamp kInitialSkip= 0.15;
const MusicTimeStamp kMaxSkip = 1.0;
const MusicTimeStamp kSkipFactor = 0.5;
static MusicTimeStamp sSkipSign = 0;
static int sSkipSteps = 0;
static VLResetTimer * sSkipResetTimer; static VLResetTimer * sSkipResetTimer;
void VLAUSoundOut::SkipTimeInterval() void VLAUSoundOut::SkipTimeInterval()
{ {
MusicTimeStamp time; MusicTimeStamp time;
MusicPlayerGetTime(fPlayer, &time); MusicPlayerGetTime(fPlayer, &time);
time += sLastSkip; ++sSkipSteps;
sLastSkip *= 1.1; MusicTimeStamp delta = kInitialSkip+(kMaxSkip-kInitialSkip)
*sSkipSign*(1.0-exp(-sSkipSteps*kSkipFactor));
time += delta;
if (!sSkipResetTimer) if (!sSkipResetTimer)
sSkipResetTimer = new VLResetTimer(500*NSEC_PER_MSEC, ^{ sSkipResetTimer = new VLResetTimer(500*NSEC_PER_MSEC, ^{
sLastSkip = 0.0; sSkipSteps = 0;
}); });
sSkipResetTimer->Prime(); sSkipResetTimer->Prime();
MusicPlayerSetTime(fPlayer, time); MusicPlayerSetTime(fPlayer, time);
@ -307,15 +313,19 @@ void VLAUSoundOut::SkipTimeInterval()
void VLAUSoundOut::Fwd() void VLAUSoundOut::Fwd()
{ {
if (sLastSkip <= 0.0) if (sSkipSign <= 0.0) {
sLastSkip = 0.1; sSkipSign = 1.0;
sSkipSteps = 0;
}
SkipTimeInterval(); SkipTimeInterval();
} }
void VLAUSoundOut::Bck() void VLAUSoundOut::Bck()
{ {
if (sLastSkip >= 0.0) if (sSkipSign >= 0.0) {
sLastSkip = -0.1; sSkipSign = -1.0;
sSkipSteps = 0;
}
SkipTimeInterval(); SkipTimeInterval();
} }