Bug 1265399 - Replace 0.7071 with sqrt(0.5) in downmixing equations; r?padenot draft
authorDan Minor <dminor@mozilla.com>
Mon, 18 Apr 2016 15:44:03 -0400
changeset 353671 0acec3042cd6c1ff4f0bcded45169768bd440565
parent 352736 d53b301a14e1dfa05324072a7159796a4f5e24c7
child 518841 05b1aaf0b8eb5ca604e6fb66bb03857cc920fe90
push id15901
push userdminor@mozilla.com
push dateTue, 19 Apr 2016 11:25:04 +0000
reviewerspadenot
bugs1265399
milestone48.0a1
Bug 1265399 - Replace 0.7071 with sqrt(0.5) in downmixing equations; r?padenot MozReview-Commit-ID: 8hiiqJ0yIxm
dom/media/AudioChannelFormat.h
--- a/dom/media/AudioChannelFormat.h
+++ b/dom/media/AudioChannelFormat.h
@@ -60,16 +60,18 @@ GetAudioChannelsSuperset(uint32_t aChann
 
 /**
  * DownMixMatrix represents a conversion matrix efficiently by exploiting the
  * fact that each input channel contributes to at most one output channel,
  * except possibly for the C input channel in layouts that have one. Also,
  * every input channel is multiplied by the same coefficient for every output
  * channel it contributes to.
  */
+const float SQRT_ONE_HALF = sqrt(0.5);
+
 struct DownMixMatrix {
   // Every input channel c is copied to output channel mInputDestination[c]
   // after multiplying by mInputCoefficient[c].
   uint8_t mInputDestination[CUSTOM_CHANNEL_LAYOUTS];
   // If not IGNORE, then the C channel is copied to this output channel after
   // multiplying by its coefficient.
   uint8_t mCExtraDestination;
   float mInputCoefficient[CUSTOM_CHANNEL_LAYOUTS];
@@ -78,29 +80,29 @@ struct DownMixMatrix {
 static const DownMixMatrix
 gDownMixMatrices[CUSTOM_CHANNEL_LAYOUTS*(CUSTOM_CHANNEL_LAYOUTS - 1)/2] =
 {
   // Downmixes to mono
   { { 0, 0 }, IGNORE, { 0.5f, 0.5f } },
   { { 0, IGNORE, IGNORE }, IGNORE, { 1.0f, IGNORE_F, IGNORE_F } },
   { { 0, 0, 0, 0 }, IGNORE, { 0.25f, 0.25f, 0.25f, 0.25f } },
   { { 0, IGNORE, IGNORE, IGNORE, IGNORE }, IGNORE, { 1.0f, IGNORE_F, IGNORE_F, IGNORE_F, IGNORE_F } },
-  { { 0, 0, 0, IGNORE, 0, 0 }, IGNORE, { 0.7071f, 0.7071f, 1.0f, IGNORE_F, 0.5f, 0.5f } },
+  { { 0, 0, 0, IGNORE, 0, 0 }, IGNORE, { SQRT_ONE_HALF, SQRT_ONE_HALF, 1.0f, IGNORE_F, 0.5f, 0.5f } },
   // Downmixes to stereo
   { { 0, 1, IGNORE }, IGNORE, { 1.0f, 1.0f, IGNORE_F } },
   { { 0, 1, 0, 1 }, IGNORE, { 0.5f, 0.5f, 0.5f, 0.5f } },
   { { 0, 1, IGNORE, IGNORE, IGNORE }, IGNORE, { 1.0f, 1.0f, IGNORE_F, IGNORE_F, IGNORE_F } },
-  { { 0, 1, 0, IGNORE, 0, 1 }, 1, { 1.0f, 1.0f, 0.7071f, IGNORE_F, 0.7071f, 0.7071f } },
+  { { 0, 1, 0, IGNORE, 0, 1 }, 1, { 1.0f, 1.0f, SQRT_ONE_HALF, IGNORE_F, SQRT_ONE_HALF, SQRT_ONE_HALF } },
   // Downmixes to 3-channel
   { { 0, 1, 2, IGNORE }, IGNORE, { 1.0f, 1.0f, 1.0f, IGNORE_F } },
   { { 0, 1, 2, IGNORE, IGNORE }, IGNORE, { 1.0f, 1.0f, 1.0f, IGNORE_F, IGNORE_F } },
   { { 0, 1, 2, IGNORE, IGNORE, IGNORE }, IGNORE, { 1.0f, 1.0f, 1.0f, IGNORE_F, IGNORE_F, IGNORE_F } },
   // Downmixes to quad
   { { 0, 1, 2, 3, IGNORE }, IGNORE, { 1.0f, 1.0f, 1.0f, 1.0f, IGNORE_F } },
-  { { 0, 1, 0, IGNORE, 2, 3 }, 1, { 1.0f, 1.0f, 0.7071f, IGNORE_F, 1.0f, 1.0f } },
+  { { 0, 1, 0, IGNORE, 2, 3 }, 1, { 1.0f, 1.0f, SQRT_ONE_HALF, IGNORE_F, 1.0f, 1.0f } },
   // Downmixes to 5-channel
   { { 0, 1, 2, 3, 4, IGNORE }, IGNORE, { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, IGNORE_F } }
 };
 
 /**
  * Given an array of input channels, downmix to aOutputChannelCount, and copy
  * the results to the channel buffers in aOutputChannels.  Don't call this with
  * input count <= output count.