Fix for mixer clipping bug that's causing audio to crackle

This commit is contained in:
Charles J. Cliffe 2015-03-01 10:30:02 -05:00
parent 8b6e5c8ef1
commit 4e13b625ca
2 changed files with 18 additions and 9 deletions

View File

@ -40,7 +40,7 @@ void AudioThread::removeThread(AudioThread *other) {
} }
void AudioThread::deviceCleanup() { void AudioThread::deviceCleanup() {
std::map<int,AudioThread *>::iterator i; std::map<int, AudioThread *>::iterator i;
for (i = deviceController.begin(); i != deviceController.end(); i++) { for (i = deviceController.begin(); i != deviceController.end(); i++) {
i->second->terminate(); i->second->terminate();
@ -105,7 +105,7 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
continue; continue;
} }
peak += srcmix->currentInput->peak * srcmix->gain; float mixPeak = srcmix->currentInput->peak * srcmix->gain;
if (srcmix->currentInput->channels == 1) { if (srcmix->currentInput->channels == 1) {
for (int i = 0; i < nBufferFrames; i++) { for (int i = 0; i < nBufferFrames; i++) {
@ -122,6 +122,10 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
continue; continue;
} }
srcmix->audioQueuePtr = 0; srcmix->audioQueuePtr = 0;
float srcPeak = srcmix->currentInput->peak * srcmix->gain;
if (mixPeak < srcPeak) {
mixPeak = srcPeak;
}
} }
if (srcmix->currentInput && srcmix->currentInput->data.size()) { if (srcmix->currentInput && srcmix->currentInput->data.size()) {
float v = srcmix->currentInput->data[srcmix->audioQueuePtr] * srcmix->gain; float v = srcmix->currentInput->data[srcmix->audioQueuePtr] * srcmix->gain;
@ -145,6 +149,10 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
continue; continue;
} }
srcmix->audioQueuePtr = 0; srcmix->audioQueuePtr = 0;
float srcPeak = srcmix->currentInput->peak * srcmix->gain;
if (mixPeak < srcPeak) {
mixPeak = srcPeak;
}
} }
if (srcmix->currentInput && srcmix->currentInput->data.size()) { if (srcmix->currentInput && srcmix->currentInput->data.size()) {
out[i] = out[i] + srcmix->currentInput->data[srcmix->audioQueuePtr] * srcmix->gain; out[i] = out[i] + srcmix->currentInput->data[srcmix->audioQueuePtr] * srcmix->gain;
@ -153,13 +161,14 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
} }
} }
peak += mixPeak;
}
if (peak > 1.0) { if (peak > 1.0) {
for (int i = 0 ; i < nBufferFrames * 2; i ++) { for (int i = 0; i < nBufferFrames * 2; i++) {
out[i] /= peak; out[i] /= peak;
} }
} }
}
return 0; return 0;
} }

View File

@ -191,8 +191,8 @@ void DemodulatorThread::threadMain() {
break; break;
} }
amOutputCeilMA = amOutputCeilMA + (amOutputCeil - amOutputCeilMA) * 0.05; amOutputCeilMA = amOutputCeilMA + (amOutputCeil - amOutputCeilMA) * 0.025;
amOutputCeilMAA = amOutputCeilMAA + (amOutputCeilMA - amOutputCeilMAA) * 0.05; amOutputCeilMAA = amOutputCeilMAA + (amOutputCeilMA - amOutputCeilMAA) * 0.025;
amOutputCeil = 0; amOutputCeil = 0;