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
--- 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