Permalink
Browse files

audio: slowing algorithm improvements

  • Loading branch information...
fzurita committed Feb 27, 2016
1 parent 35d665d commit 8716fda0ebbceccea21b9853959ad1df5cbb8a36
Showing with 16 additions and 25 deletions.
  1. +16 −25 jni/mupen64plus-audio-sles/main.cpp
@@ -787,7 +787,7 @@ void* audioConsumer(void* param)
int prevQueueSize = thread_queue_length(&audioConsumerQueue);
int currQueueSize = prevQueueSize;
- int maxQueueSize = TargetSecondaryBuffers + 10;
+ int maxQueueSize = TargetSecondaryBuffers + 5;
int minQueueSize = TargetSecondaryBuffers;
int desiredGameSpeed = 100;
@@ -799,8 +799,9 @@ void* audioConsumer(void* param)
//adjustment used when a device running too slow
double slowAdjustment = 0;
double currAdjustment = 0;
- const double minSlowAdjustment = 0.05;
+ const double minSlowAdjustment = 0.02;
const double minSlowValue = 0.2;
+ const double catchUpOffset = 0.05;
queueData* currQueueData = NULL;
struct timespec currTime;
struct timespec prevTime;
@@ -851,38 +852,28 @@ void* audioConsumer(void* param)
feedTimesSet = true;
}
+ float temp = averageGameTime/averageFeedTime;
+
//Game is running too fast speed up audio
if(queueLength > maxQueueSize)
{
- float temp = averageGameTime/averageFeedTime;
-
- if(temp > 1.0)
- {
- currAdjustment = temp;
- }
+ currAdjustment = temp + catchUpOffset;
}
//Device can't keep up with the game or we have too much in the queue after slowing it down
- else if(ranDry || queueLength > maxQueueSize)
+ else if(ranDry)
{
- float temp = averageGameTime/averageFeedTime;
-
- if(temp < 1.0)
- {
- currAdjustment = temp;
- }
+ currAdjustment = temp - catchUpOffset;
}
- //Device has caught up
- else
+ else if(!ranDry && queueLength < maxQueueSize)
{
- currAdjustment = 1.0;
+ 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) ))
- || currAdjustment == 1.0 )
+ (fabs(currAdjustment - 1.0) < fabs(slowAdjustment - 1.0) && fabs(currAdjustment) > minSlowAdjustment) )))
{
slowAdjustment = currAdjustment;
soundTouch.setTempo(slowAdjustment);
@@ -894,11 +885,11 @@ void* audioConsumer(void* param)
free(currQueueData);
//Useful logging
- /*if(queueLength == 0)
- {
- DebugMessage(M64MSG_ERROR, "target=%d, length = %d, speed = %d, dry=%d, slow_adj=%f, curr_adj=%f, feed_time=%f, game_time=%f",
- TargetSecondaryBuffers, queueLength, desiredGameSpeed, ranDry, slowAdjustment, currAdjustment, averageFeedTime, averageGameTime);
- }*/
+ //if(queueLength == 0)
+ //{
+ // DebugMessage(M64MSG_ERROR, "target=%d, length = %d, speed = %d, dry=%d, slow_adj=%f, curr_adj=%f, feed_time=%f, game_time=%f",
+ // TargetSecondaryBuffers, queueLength, desiredGameSpeed, ranDry, slowAdjustment, currAdjustment, averageFeedTime, averageGameTime);
+ //}
}
}

0 comments on commit 8716fda

Please sign in to comment.