mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-19 07:26:14 +02:00
add downsampling so RAW audio for sound assumed to be 48Khz
This commit is contained in:
parent
5b272bfd6a
commit
a06f18328c
1 changed files with 21 additions and 1 deletions
|
@ -27,5 +27,25 @@ Sound::Sound(const QUrl& sampleURL, QObject* parent) :
|
|||
|
||||
void Sound::replyFinished(QNetworkReply* reply) {
|
||||
// replace our byte array with the downloaded data
|
||||
_byteArray = reply->readAll();
|
||||
QByteArray rawAudioByteArray = reply->readAll();
|
||||
|
||||
// assume that this was a RAW file and is now an array of samples that are
|
||||
// signed, 16-bit, 48Khz, mono
|
||||
|
||||
// we want to convert it to the format that the audio-mixer wants
|
||||
// which is signed, 16-bit, 24Khz, mono
|
||||
|
||||
_byteArray.resize(rawAudioByteArray.size() / 2);
|
||||
|
||||
int numSourceSamples = rawAudioByteArray.size() / sizeof(int16_t);
|
||||
int16_t* sourceSamples = (int16_t*) rawAudioByteArray.data();
|
||||
int16_t* destinationSamples = (int16_t*) _byteArray.data();
|
||||
|
||||
for (int i = 1; i < numSourceSamples; i += 2) {
|
||||
if (i + 1 >= numSourceSamples) {
|
||||
destinationSamples[(i - 1) / 2] = (rawAudioByteArray[i - 1] / 2) + (rawAudioByteArray[i] / 2);
|
||||
} else {
|
||||
destinationSamples[(i - 1) / 2] = (sourceSamples[i - 1] / 4) + (sourceSamples[i] / 2) + (sourceSamples[i + 1] / 4);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue