fix for scratchy audio on windows

This commit is contained in:
Andrew Meadows 2015-02-20 08:26:11 -08:00
parent 7183400e43
commit 599ef68df8
3 changed files with 22 additions and 15 deletions

View file

@ -75,4 +75,4 @@ private:
};
#endif // hifi_AudioScope_h
#endif // hifi_AudioScope_h

View file

@ -85,16 +85,9 @@ AudioClient::AudioClient() :
_isStereoInput(false),
_outputStarveDetectionStartTimeMsec(0),
_outputStarveDetectionCount(0),
_outputBufferSizeFrames("audioOutputBufferSize",
DEFAULT_MAX_FRAMES_OVER_DESIRED),
#ifdef Q_OS_ANDROID
_outputStarveDetectionEnabled("audioOutputStarveDetectionEnabled",
false),
#else
_outputBufferSizeFrames("audioOutputBufferSize", DEFAULT_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES),
_outputStarveDetectionEnabled("audioOutputStarveDetectionEnabled",
DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_ENABLED),
#endif
_outputStarveDetectionPeriodMsec("audioOutputStarveDetectionPeriod",
DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_PERIOD),
_outputStarveDetectionThreshold("audioOutputStarveDetectionThreshold",
@ -1089,12 +1082,16 @@ void AudioClient::outputNotify() {
} else {
_outputStarveDetectionCount += recentUnfulfilled;
if (_outputStarveDetectionCount > _outputStarveDetectionThreshold.get()) {
int newOutputBufferSizeFrames = _outputBufferSizeFrames.get() + 1;
qDebug() << "Starve detection threshold met, increasing buffer size to " << newOutputBufferSizeFrames;
setOutputBufferSize(newOutputBufferSizeFrames);
_outputStarveDetectionStartTimeMsec = now;
_outputStarveDetectionCount = 0;
int oldOutputBufferSizeFrames = _outputBufferSizeFrames.get();
int newOutputBufferSizeFrames = oldOutputBufferSizeFrames + 1;
setOutputBufferSize(newOutputBufferSizeFrames);
newOutputBufferSizeFrames = _outputBufferSizeFrames.get();
if (newOutputBufferSizeFrames > oldOutputBufferSizeFrames) {
qDebug() << "Starve detection threshold met, increasing buffer size to " << newOutputBufferSizeFrames;
}
}
}
}

View file

@ -56,8 +56,18 @@ static const int NUM_AUDIO_CHANNELS = 2;
static const int DEFAULT_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 3;
static const int MIN_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 1;
static const int MAX_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 20;
static const int DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_ENABLED = true;
#ifdef _WIN32
// WORKAROUND: Some sound devices on Windows (at least 8.1) will get scratchy if their output
// buffer is set too high so we have to limit the number of frames in the buffer.
static const int MAX_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 5;
#else
static const int MAX_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 20;
#endif
#ifdef Q_OS_ANDROID
static const int DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_ENABLED = false;
#else
static const int DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_ENABLED = true;
#endif
static const int DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_THRESHOLD = 3;
static const quint64 DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_PERIOD = 10 * 1000; // 10 Seconds