mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 10:00:18 +02:00
Merge pull request #6958 from huffman/injector-timing-fixes
Fix injector looping issues when using audio that isn't a multiple of the sample size
This commit is contained in:
commit
f3903022f2
1 changed files with 10 additions and 1 deletions
|
@ -181,6 +181,15 @@ int64_t AudioInjector::injectNextFrame() {
|
||||||
// make sure we actually have samples downloaded to inject
|
// make sure we actually have samples downloaded to inject
|
||||||
if (_audioData.size()) {
|
if (_audioData.size()) {
|
||||||
|
|
||||||
|
int sampleSize = (_options.stereo ? 2 : 1) * sizeof(AudioConstants::AudioSample);
|
||||||
|
auto numSamples = static_cast<int>(_audioData.size() / sampleSize);
|
||||||
|
auto targetSize = numSamples * sampleSize;
|
||||||
|
if (targetSize != _audioData.size()) {
|
||||||
|
qDebug() << "Resizing audio that doesn't end at multiple of sample size, resizing from "
|
||||||
|
<< _audioData.size() << " to " << targetSize;
|
||||||
|
_audioData.resize(targetSize);
|
||||||
|
}
|
||||||
|
|
||||||
_outgoingSequenceNumber = 0;
|
_outgoingSequenceNumber = 0;
|
||||||
_nextFrame = 0;
|
_nextFrame = 0;
|
||||||
|
|
||||||
|
@ -272,7 +281,7 @@ int64_t AudioInjector::injectNextFrame() {
|
||||||
_currentPacket->write(_audioData.data() + _currentSendOffset, bytesToCopy);
|
_currentPacket->write(_audioData.data() + _currentSendOffset, bytesToCopy);
|
||||||
_currentSendOffset += bytesToCopy;
|
_currentSendOffset += bytesToCopy;
|
||||||
totalBytesLeftToCopy -= bytesToCopy;
|
totalBytesLeftToCopy -= bytesToCopy;
|
||||||
if (_currentSendOffset >= _audioData.size()) {
|
if (_options.loop && _currentSendOffset >= _audioData.size()) {
|
||||||
_currentSendOffset = 0;
|
_currentSendOffset = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue