Fix incorrect scaling of S32LE samples; 1<<31 overflows and causes the wrong result.
authorCarl Hetherington <cth@carlh.net>
Tue, 17 May 2016 22:09:15 +0000 (23:09 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 18 May 2016 10:50:29 +0000 (11:50 +0100)
src/lib/ffmpeg_decoder.cc

index e3a42537535621e1f8cfb5e4543696a5a4d1d557..068eba80fa209c1a9d5b5f721aa2dfb85924b7ae 100644 (file)
@@ -228,7 +228,7 @@ FFmpegDecoder::deinterleave_audio (shared_ptr<FFmpegAudioStream> stream) const
                int sample = 0;
                int channel = 0;
                for (int i = 0; i < total_samples; ++i) {
-                       audio->data(channel)[sample] = static_cast<float>(*p++) / (1 << 31);
+                       audio->data(channel)[sample] = static_cast<float>(*p++) / 2147483648;
 
                        ++channel;
                        if (channel == stream->channels()) {
@@ -244,7 +244,7 @@ FFmpegDecoder::deinterleave_audio (shared_ptr<FFmpegAudioStream> stream) const
                int32_t** p = reinterpret_cast<int32_t **> (_frame->data);
                for (int i = 0; i < stream->channels(); ++i) {
                        for (int j = 0; j < frames; ++j) {
-                               audio->data(i)[j] = static_cast<float>(p[i][j]) / (1 << 31);
+                               audio->data(i)[j] = static_cast<float>(p[i][j]) / 2147483648;
                        }
                }
        }