Bug 865234 - Part 4: Implement ChannelInterpretation's effect when mixing inputs; r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 27 Apr 2013 19:52:21 -0400
changeset 141401 0cece7dfcd6ece872853b466f4fd9139072810a5
parent 141400 1e8d0680c950f78c9483a620947ebd8550bc4136
child 141402 b28a0e8f357ff4aa7515489d592406e02bf9eaa2
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs865234
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 865234 - Part 4: Implement ChannelInterpretation's effect when mixing inputs; r=roc
content/media/AudioNodeStream.cpp
--- a/content/media/AudioNodeStream.cpp
+++ b/content/media/AudioNodeStream.cpp
@@ -283,39 +283,53 @@ AudioNodeStream::ObtainInputBlock(AudioC
   }
 
   if (inputChunkCount == 1 &&
       inputChunks[0]->mChannelData.Length() == outputChannelCount) {
     return inputChunks[0];
   }
 
   AllocateAudioBlock(outputChannelCount, aTmpChunk);
+  float silenceChannel[WEBAUDIO_BLOCK_SIZE] = {0.f};
 
   for (uint32_t i = 0; i < inputChunkCount; ++i) {
     AudioChunk* chunk = inputChunks[i];
     nsAutoTArray<const void*,GUESS_AUDIO_CHANNELS> channels;
     channels.AppendElements(chunk->mChannelData);
     if (channels.Length() < outputChannelCount) {
-      AudioChannelsUpMix(&channels, outputChannelCount, nullptr);
-      NS_ASSERTION(outputChannelCount == channels.Length(),
-                   "We called GetAudioChannelsSuperset to avoid this");
+      if (mMixingMode.mChannelInterpretation == ChannelInterpretation::Speakers) {
+        AudioChannelsUpMix(&channels, outputChannelCount, nullptr);
+        NS_ASSERTION(outputChannelCount == channels.Length(),
+                     "We called GetAudioChannelsSuperset to avoid this");
+      } else {
+        // Fill up the remaining channels by zeros
+        for (uint32_t i = channels.Length(); i < outputChannelCount; ++i) {
+          channels.AppendElement(silenceChannel);
+        }
+      }
     } else if (channels.Length() > outputChannelCount) {
-      nsAutoTArray<float*,GUESS_AUDIO_CHANNELS> outputChannels;
-      outputChannels.SetLength(outputChannelCount);
-      for (uint32_t i = 0; i < outputChannelCount; ++i) {
-        outputChannels[i] =
-          const_cast<float*>(static_cast<const float*>(aTmpChunk->mChannelData[i]));
-      }
+      if (mMixingMode.mChannelInterpretation == ChannelInterpretation::Speakers) {
+        nsAutoTArray<float*,GUESS_AUDIO_CHANNELS> outputChannels;
+        outputChannels.SetLength(outputChannelCount);
+        for (uint32_t i = 0; i < outputChannelCount; ++i) {
+          outputChannels[i] =
+            const_cast<float*>(static_cast<const float*>(aTmpChunk->mChannelData[i]));
+        }
 
-      AudioChannelsDownMix(channels, outputChannels.Elements(),
-                           outputChannelCount, WEBAUDIO_BLOCK_SIZE);
+        AudioChannelsDownMix(channels, outputChannels.Elements(),
+                             outputChannelCount, WEBAUDIO_BLOCK_SIZE);
 
-      channels.SetLength(outputChannelCount);
-      for (uint32_t i = 0; i < channels.Length(); ++i) {
-        channels[i] = outputChannels[i];
+        channels.SetLength(outputChannelCount);
+        for (uint32_t i = 0; i < channels.Length(); ++i) {
+          channels[i] = outputChannels[i];
+        }
+      } else {
+        // Drop the remaining channels
+        channels.RemoveElementsAt(outputChannelCount,
+                                  channels.Length() - outputChannelCount);
       }
     }
 
     for (uint32_t c = 0; c < channels.Length(); ++c) {
       const float* inputData = static_cast<const float*>(channels[c]);
       float* outputData = static_cast<float*>(const_cast<void*>(aTmpChunk->mChannelData[c]));
       if (inputData) {
         if (i == 0) {