Permalink
Browse files

audio: Audio stretching algorithm tweaks

  • Loading branch information...
fzurita committed Feb 26, 2016
1 parent f30a8da commit 290a622e5069034f9528980452a3c74e66cb5a82
Showing with 18 additions and 11 deletions.
  1. +18 −11 jni/mupen64plus-audio-sles/main.cpp
@@ -667,7 +667,7 @@ bool isSpeedLimiterEnabled(void)
EXPORT void CALL AiLenChanged(void)
{
- static const bool sleepPerfFixEnabled = true;
+ static const bool sleepPerfFixEnabled = false;
static const double minSleepNeeded = -0.1;
static const double maxSleepNeeded = 0.1;
if (critical_failure == 1)
@@ -738,8 +738,6 @@ EXPORT void CALL AiLenChanged(void)
currTime = static_cast<double>(time.tv_sec) +
static_cast<double>(time.tv_nsec)/1.0e9;
}
-
-
}
else
{
@@ -789,7 +787,7 @@ void* audioConsumer(void* param)
int prevQueueSize = thread_queue_length(&audioConsumerQueue);
int currQueueSize = prevQueueSize;
int maxQueueSize = 50;
- int minQueueSize = 10;
+ int minQueueSize = 25;
int desiredGameSpeed = 100;
static const int fullSpeed = 100;
@@ -816,7 +814,7 @@ void* audioConsumer(void* param)
waitTime.tv_sec = 1;
waitTime.tv_nsec = 0;
- const int feedTimeWindowSize = 100;
+ const int feedTimeWindowSize = 10;
int feedTimeIndex = 0;
bool feedTimesSet = false;
float timePerBuffer = 1.0*SecondaryBufferSize/GameFreq;
@@ -849,6 +847,7 @@ void* audioConsumer(void* param)
gameTimes[feedTimeIndex] = currQueueData->lenght/SLES_SAMPLE_BYTES*1.0/GameFreq;
averageGameTime = GetAverageTime(gameTimes, feedTimesSet ? feedTimeWindowSize : (feedTimeIndex+1));
+ ++feedTimeIndex;
if(feedTimeIndex == feedTimeWindowSize)
{
feedTimeIndex = 0;
@@ -888,7 +887,12 @@ void* audioConsumer(void* param)
//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)
{
- currAdjustment = averageGameTime/averageFeedTime;
+ float temp = averageGameTime/averageFeedTime;
+
+ if(temp < 1.0)
+ {
+ currAdjustment = temp;
+ }
}
//Device has caught up
else
@@ -914,10 +918,10 @@ void* audioConsumer(void* param)
}
}
- //Allow the tempo to slow down quickly, but restore original speed more slowly
+ //Allow the tempo to differentiate quickly, but restore original speed more slowly
if( (currAdjustment > minSlowValue &&
- ( ((slowAdjustment - currAdjustment) > minSlowAdjustment) ||
- ((currAdjustment - slowAdjustment) < minSlowAdjustment*5)))
+ ( (fabs(currAdjustment - 1.0) > fabs(slowAdjustment - 1.0) && fabs(currAdjustment) > minSlowAdjustment) ||
+ (fabs(currAdjustment - 1.0) < fabs(slowAdjustment - 1.0) && fabs(currAdjustment) > minSlowAdjustment*5) ))
|| currAdjustment == 1.0 )
{
slowAdjustment = currAdjustment;
@@ -930,8 +934,11 @@ void* audioConsumer(void* param)
free(currQueueData);
//Useful logging
- //DebugMessage(M64MSG_ERROR, "length = %d, speed = %d, dry=%d, slow_adj=%f, curr_adj=%f, feed_time=%f, game_time=%f",
- // queueLength, desiredGameSpeed, ranDry, slowAdjustment, currAdjustment, averageFeedTime, averageGameTime);
+ /*if(queueLength == 0)
+ {
+ DebugMessage(M64MSG_ERROR, "length = %d, speed = %d, dry=%d, slow_adj=%f, curr_adj=%f, feed_time=%f, game_time=%f",
+ queueLength, desiredGameSpeed, ranDry, slowAdjustment, currAdjustment, averageFeedTime, averageGameTime);
+ }*/
}
}

0 comments on commit 290a622

Please sign in to comment.