mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-26 21:58:37 -05:00
Fix for mixer clipping bug that's causing audio to crackle
This commit is contained in:
parent
8b6e5c8ef1
commit
4e13b625ca
@ -40,7 +40,7 @@ void AudioThread::removeThread(AudioThread *other) {
|
||||
}
|
||||
|
||||
void AudioThread::deviceCleanup() {
|
||||
std::map<int,AudioThread *>::iterator i;
|
||||
std::map<int, AudioThread *>::iterator i;
|
||||
|
||||
for (i = deviceController.begin(); i != deviceController.end(); i++) {
|
||||
i->second->terminate();
|
||||
@ -105,7 +105,7 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
||||
continue;
|
||||
}
|
||||
|
||||
peak += srcmix->currentInput->peak * srcmix->gain;
|
||||
float mixPeak = srcmix->currentInput->peak * srcmix->gain;
|
||||
|
||||
if (srcmix->currentInput->channels == 1) {
|
||||
for (int i = 0; i < nBufferFrames; i++) {
|
||||
@ -122,6 +122,10 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
||||
continue;
|
||||
}
|
||||
srcmix->audioQueuePtr = 0;
|
||||
float srcPeak = srcmix->currentInput->peak * srcmix->gain;
|
||||
if (mixPeak < srcPeak) {
|
||||
mixPeak = srcPeak;
|
||||
}
|
||||
}
|
||||
if (srcmix->currentInput && srcmix->currentInput->data.size()) {
|
||||
float v = srcmix->currentInput->data[srcmix->audioQueuePtr] * srcmix->gain;
|
||||
@ -145,6 +149,10 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
|
||||
continue;
|
||||
}
|
||||
srcmix->audioQueuePtr = 0;
|
||||
float srcPeak = srcmix->currentInput->peak * srcmix->gain;
|
||||
if (mixPeak < srcPeak) {
|
||||
mixPeak = srcPeak;
|
||||
}
|
||||
}
|
||||
if (srcmix->currentInput && srcmix->currentInput->data.size()) {
|
||||
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) {
|
||||
for (int i = 0 ; i < nBufferFrames * 2; i ++) {
|
||||
for (int i = 0; i < nBufferFrames * 2; i++) {
|
||||
out[i] /= peak;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -191,8 +191,8 @@ void DemodulatorThread::threadMain() {
|
||||
break;
|
||||
}
|
||||
|
||||
amOutputCeilMA = amOutputCeilMA + (amOutputCeil - amOutputCeilMA) * 0.05;
|
||||
amOutputCeilMAA = amOutputCeilMAA + (amOutputCeilMA - amOutputCeilMAA) * 0.05;
|
||||
amOutputCeilMA = amOutputCeilMA + (amOutputCeil - amOutputCeilMA) * 0.025;
|
||||
amOutputCeilMAA = amOutputCeilMAA + (amOutputCeilMA - amOutputCeilMAA) * 0.025;
|
||||
|
||||
amOutputCeil = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user