Bug 1349658 - Use WAV float audio encoding when appropriate r?jwwang draft
authorCosine <judahiii@gmail.com>
Thu, 31 Aug 2017 16:32:19 -0400
changeset 656893 066ad78e1e2b6684b3c6150ec5f2e09acd3eae52
parent 656493 5b30f38210e155ef046b55ef22e19d771c13540e
child 656902 5a2a7b8470ac96ecc3297c472beac84552500812
child 656904 32a9b040e727d12e735d13aa7919a0aaedbb83bb
push id77364
push userbmo:judahiii@gmail.com
push dateThu, 31 Aug 2017 20:33:19 +0000
reviewersjwwang
bugs1349658
milestone57.0a1
Bug 1349658 - Use WAV float audio encoding when appropriate r?jwwang WAV files can store data in floats in the range [-1,1]. In this case, a specific bit is set in the header. This patch recognizes this bit and decodes it by reading the float into an internal AudioSample. MozReview-Commit-ID: AwGr5DcwHGj
dom/media/platforms/agnostic/WAVDecoder.cpp
--- a/dom/media/platforms/agnostic/WAVDecoder.cpp
+++ b/dom/media/platforms/agnostic/WAVDecoder.cpp
@@ -2,16 +2,17 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AudioSampleFormat.h"
 #include "WAVDecoder.h"
 #include "mozilla/SyncRunnable.h"
+#include "mozilla/Casting.h"
 #include "VideoUtils.h"
 
 using mp4_demuxer::ByteReader;
 
 namespace mozilla {
 
 int16_t
 DecodeALawSample(uint8_t aValue)
@@ -85,17 +86,22 @@ WaveDataDecoder::ProcessDecode(MediaRawD
 
   AlignedAudioBuffer buffer(frames * mInfo.mChannels);
   if (!buffer) {
     return DecodePromise::CreateAndReject(
       MediaResult(NS_ERROR_OUT_OF_MEMORY, __func__), __func__);
   }
   for (int i = 0; i < frames; ++i) {
     for (unsigned int j = 0; j < mInfo.mChannels; ++j) {
-      if (mInfo.mProfile == 6) {                              //ALAW Data
+      if (mInfo.mProfile == 3) {                              //IEEE float Data
+        uint32_t v = aReader.ReadU32();
+        float decoded = BitwiseCast<float>(v);
+        buffer[i * mInfo.mChannels + j] =
+            FloatToAudioSample<AudioDataValue>(decoded);
+      } else if (mInfo.mProfile == 6) {                       //ALAW Data
         uint8_t v = aReader.ReadU8();
         int16_t decoded = DecodeALawSample(v);
         buffer[i * mInfo.mChannels + j] =
             IntegerToAudioSample<AudioDataValue>(decoded);
       } else if (mInfo.mProfile == 7) {                       //ULAW Data
         uint8_t v = aReader.ReadU8();
         int16_t decoded = DecodeULawSample(v);
         buffer[i * mInfo.mChannels + j] =
@@ -145,15 +151,16 @@ WaveDataDecoder::Flush()
 /* static */
 bool
 WaveDataDecoder::IsWave(const nsACString& aMimeType)
 {
   // Some WebAudio uses "audio/x-wav",
   // WAVdemuxer uses "audio/wave; codecs=aNum".
   return aMimeType.EqualsLiteral("audio/x-wav") ||
          aMimeType.EqualsLiteral("audio/wave; codecs=1") ||
+         aMimeType.EqualsLiteral("audio/wave; codecs=3") ||
          aMimeType.EqualsLiteral("audio/wave; codecs=6") ||
          aMimeType.EqualsLiteral("audio/wave; codecs=7") ||
          aMimeType.EqualsLiteral("audio/wave; codecs=65534");
 }
 
 } // namespace mozilla
 #undef LOG