mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 11:17:34 +02:00
Fix the loud audio pops at startup, due to SOXR returning less than desired output samples because of internal buffering.
This commit is contained in:
parent
4d6d882f52
commit
6afb6c80d0
1 changed files with 18 additions and 2 deletions
|
@ -418,9 +418,17 @@ soxr_error_t possibleResampling(soxr_t resampler,
|
||||||
numSourceSamples,
|
numSourceSamples,
|
||||||
sourceAudioFormat, destinationAudioFormat);
|
sourceAudioFormat, destinationAudioFormat);
|
||||||
|
|
||||||
|
unsigned int odone = 0;
|
||||||
resampleError = soxr_process(resampler,
|
resampleError = soxr_process(resampler,
|
||||||
channelConversionSamples, numChannelCoversionSamples, NULL,
|
channelConversionSamples, numChannelCoversionSamples, NULL,
|
||||||
destinationSamples, numDestinationSamples, NULL);
|
destinationSamples, numDestinationSamples, &odone);
|
||||||
|
|
||||||
|
// return silence instead of playing garbage samples
|
||||||
|
if (odone < numDestinationSamples) {
|
||||||
|
unsigned int nBytes = (numDestinationSamples - odone) * destinationAudioFormat.channelCount() * sizeof(int16_t);
|
||||||
|
memset(&destinationSamples[odone * destinationAudioFormat.channelCount()], 0, nBytes);
|
||||||
|
qCDebug(audioclient) << "SOXR: padded with" << nBytes << "bytes of silence";
|
||||||
|
}
|
||||||
|
|
||||||
delete[] channelConversionSamples;
|
delete[] channelConversionSamples;
|
||||||
} else {
|
} else {
|
||||||
|
@ -433,9 +441,17 @@ soxr_error_t possibleResampling(soxr_t resampler,
|
||||||
numAdjustedDestinationSamples /= 2;
|
numAdjustedDestinationSamples /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int odone = 0;
|
||||||
resampleError = soxr_process(resampler,
|
resampleError = soxr_process(resampler,
|
||||||
sourceSamples, numAdjustedSourceSamples, NULL,
|
sourceSamples, numAdjustedSourceSamples, NULL,
|
||||||
destinationSamples, numAdjustedDestinationSamples, NULL);
|
destinationSamples, numAdjustedDestinationSamples, &odone);
|
||||||
|
|
||||||
|
// return silence instead of playing garbage samples
|
||||||
|
if (odone < numAdjustedDestinationSamples) {
|
||||||
|
unsigned int nBytes = (numAdjustedDestinationSamples - odone) * destinationAudioFormat.channelCount() * sizeof(int16_t);
|
||||||
|
memset(&destinationSamples[odone * destinationAudioFormat.channelCount()], 0, nBytes);
|
||||||
|
qCDebug(audioclient) << "SOXR: padded with" << nBytes << "bytes of silence";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return resampleError;
|
return resampleError;
|
||||||
|
|
Loading…
Reference in a new issue