Permalink
Browse files

audio: slowing algorithm tweaks

  • Loading branch information...
fzurita committed Mar 4, 2016
1 parent 2aacb16 commit a4fee6ae4bf5cda665ea9fdfa885c41e33da1659
Showing with 24 additions and 8 deletions.
  1. +24 −8 jni/mupen64plus-audio-sles/main.cpp
@@ -814,8 +814,11 @@ void* audioConsumer(void* param)
//adjustment used when a device running too slow
double slowAdjustment = 0;
double currAdjustment = 0;
- const double minSlowAdjustment = 0.02;
+
+ //how quickly to return to original speed
+ const double returnSpeed = 0.10;
const double minSlowValue = 0.2;
+ const double maxSlowValue = 3.0;
const double catchUpOffset = 0.05;
queueData* currQueueData = NULL;
struct timespec currTime;
@@ -827,7 +830,8 @@ void* audioConsumer(void* param)
waitTime.tv_nsec = 0;
//use the smallest of the two
- int feedTimeWindowSize = TargetSecondaryBuffers >= 10 ? 10 : TargetSecondaryBuffers;
+ const int maxWindowSize = 4;
+ int feedTimeWindowSize = TargetSecondaryBuffers >= maxWindowSize ? maxWindowSize : TargetSecondaryBuffers;
int feedTimeIndex = 0;
bool feedTimesSet = false;
float timePerBuffer = 1.0*SecondaryBufferSize/GameFreq;
@@ -887,13 +891,25 @@ void* audioConsumer(void* param)
currAdjustment = temp;
}
- //Allow the tempo to differentiate quickly with no minimum value change, but restore original tempo more slowly
- //by making sure that it must change by at least the minimum value
- if( (currAdjustment > minSlowValue &&
- ( (fabs(currAdjustment - 1.0) > fabs(slowAdjustment - 1.0) ) ||
- (fabs(currAdjustment - 1.0) < fabs(slowAdjustment - 1.0) && fabs(currAdjustment) > minSlowAdjustment) )))
+ //Allow the tempo to slow quickly with no minimum value change, but restore original tempo more slowly.
+ if( currAdjustment > minSlowValue && currAdjustment < maxSlowValue)
{
- slowAdjustment = currAdjustment;
+ if(fabs(currAdjustment - 1.0) < fabs(slowAdjustment - 1.0))
+ {
+ if(currAdjustment - slowAdjustment > returnSpeed)
+ {
+ slowAdjustment += returnSpeed;
+ }
+ else
+ {
+ slowAdjustment = currAdjustment;
+ }
+ }
+ else
+ {
+ slowAdjustment = currAdjustment;
+ }
+
soundTouch.setTempo(slowAdjustment);
}

0 comments on commit a4fee6a

Please sign in to comment.