Merge pull request #4585 from birarda/no-gpu-link

fix for resampled stereo audio array size
This commit is contained in:
Clément Brisset 2015-04-02 21:31:53 +02:00
commit c7540af787
2 changed files with 8 additions and 8 deletions

View file

@ -59,6 +59,8 @@ qint64 AudioInjectorLocalBuffer::readData(char* data, qint64 maxSize) {
if (!_shouldLoop && bytesRead == bytesToEnd) {
// we hit the end of the buffer, emit a signal
emit bufferEmpty();
} else if (_shouldLoop && _currentOffset == _rawAudioArray.size()) {
_currentOffset = 0;
}
return bytesRead;
@ -80,7 +82,7 @@ qint64 AudioInjectorLocalBuffer::recursiveReadFromFront(char* data, qint64 maxSi
// check if we need to call ourselves again and pull from the front again
if (bytesRead < maxSize) {
return bytesRead + recursiveReadFromFront(data, maxSize);
return bytesRead + recursiveReadFromFront(data + bytesRead, maxSize - bytesRead);
} else {
_currentOffset = bytesRead;
return bytesRead;

View file

@ -77,7 +77,7 @@ void Sound::downloadFinished(QNetworkReply* reply) {
// since it's raw the only way for us to know that is if the file was called .stereo.raw
if (reply->url().fileName().toLower().endsWith("stereo.raw")) {
_isStereo = true;
qDebug() << "Processing sound from" << reply->url() << "as stereo audio file.";
qDebug() << "Processing sound of" << rawAudioByteArray.size() << "bytes from" << reply->url() << "as stereo audio file.";
}
// Process as RAW file
@ -99,15 +99,14 @@ void Sound::downSample(const QByteArray& rawAudioByteArray) {
// we want to convert it to the format that the audio-mixer wants
// which is signed, 16-bit, 24Khz
int numSourceSamples = rawAudioByteArray.size() / sizeof(int16_t);
int numSourceSamples = rawAudioByteArray.size() / sizeof(AudioConstants::AudioSample);
int numDestinationBytes = rawAudioByteArray.size() / 2;
if (_isStereo && numSourceSamples % 4 != 0) {
numDestinationBytes += 1;
int numDestinationBytes = rawAudioByteArray.size() / sizeof(AudioConstants::AudioSample);
if (_isStereo && numSourceSamples % 2 != 0) {
numDestinationBytes += sizeof(AudioConstants::AudioSample);
}
_byteArray.resize(numDestinationBytes);
int16_t* sourceSamples = (int16_t*) rawAudioByteArray.data();
int16_t* destinationSamples = (int16_t*) _byteArray.data();
@ -121,7 +120,6 @@ void Sound::downSample(const QByteArray& rawAudioByteArray) {
destinationSamples[i / 2] = (sourceSamples[i] + sourceSamples[i + 2]) / 2;
destinationSamples[(i / 2) + 1] = (sourceSamples[i + 1] + sourceSamples[i + 3]) / 2;
}
}
} else {
for (int i = 1; i < numSourceSamples; i += 2) {