Title: [267346] trunk
Revision
267346
Author
cdu...@apple.com
Date
2020-09-21 08:34:01 -0700 (Mon, 21 Sep 2020)

Log Message

AnalyserNode should downmix input audio to mono
https://bugs.webkit.org/show_bug.cgi?id=216736

Reviewed by Sam Weinig.

Source/WebCore:

AnalyserNode should downmix input audio to mono:
- https://www.w3.org/TR/webaudio/#current-time-domain-data

This patch is based on the following Blink change:
- https://codereview.chromium.org/1803233002

No new tests, rebaselined existing test.

* Modules/webaudio/RealtimeAnalyser.cpp:
(WebCore::RealtimeAnalyser::RealtimeAnalyser):
(WebCore::RealtimeAnalyser::writeInput):
* Modules/webaudio/RealtimeAnalyser.h:

LayoutTests:

Rebaseline test now that more checks are passing.

* webaudio/Analyser/realtimeanalyser-downmix-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (267345 => 267346)


--- trunk/LayoutTests/ChangeLog	2020-09-21 15:11:43 UTC (rev 267345)
+++ trunk/LayoutTests/ChangeLog	2020-09-21 15:34:01 UTC (rev 267346)
@@ -1,3 +1,14 @@
+2020-09-21  Chris Dumez  <cdu...@apple.com>
+
+        AnalyserNode should downmix input audio to mono
+        https://bugs.webkit.org/show_bug.cgi?id=216736
+
+        Reviewed by Sam Weinig.
+
+        Rebaseline test now that more checks are passing.
+
+        * webaudio/Analyser/realtimeanalyser-downmix-expected.txt:
+
 2020-09-21  Wenson Hsieh  <wenson_hs...@apple.com>
 
         REGRESSION (r257839): Can't add a memo when transferring funds in First Tech Credit Union App

Modified: trunk/LayoutTests/webaudio/Analyser/realtimeanalyser-downmix-expected.txt (267345 => 267346)


--- trunk/LayoutTests/webaudio/Analyser/realtimeanalyser-downmix-expected.txt	2020-09-21 15:11:43 UTC (rev 267345)
+++ trunk/LayoutTests/webaudio/Analyser/realtimeanalyser-downmix-expected.txt	2020-09-21 15:34:01 UTC (rev 267346)
@@ -40,38 +40,26 @@
  assert_true: expected true got false
 FAIL < [quad] 1 out of 2 assertions were failed. assert_true: expected true got false
 PASS > [5.1]  
-FAIL X Analyser downmix 5.1 to mono time data expected to be equal to the array [43.0355339050293,43.0355339050293,43.0355339050293,43.0355339050293,43.0355339050293,43.0355339050293,43.0355339050293,43.0355339050293,43.0355339050293,43.0355339050293,43.0355339050293,43.0355339050293,43.0355339050293,43.0355339050293,43.0355339050293,43.0355339050293...] but differs in 256 places:
-	Index	Actual			Expected
-	[0]	1.5166666984558105e+1	4.3035533905029297e+1
-	[1]	1.5166666984558105e+1	4.3035533905029297e+1
-	[2]	1.5166666984558105e+1	4.3035533905029297e+1
-	[3]	1.5166666984558105e+1	4.3035533905029297e+1
-	...and 252 more errors. assert_true: expected true got false
+PASS   Analyser downmix 5.1 to mono time data is identical to the array [expected array]. 
 FAIL X Analyser downmix 5.1 to mono freq data does not equal [25.141529083251953,20.635343551635742,4.717743873596191,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":2.0215e-7}.
 	Index	Actual			Expected		AbsError		RelError		Test threshold
-	[0]	2.2103387832641602e+1	2.5141529083251953e+1	3.0381412506103516e+0	1.2084154629378574e-1	5.0823601041793820e-6
-	[1]	1.7597202301025391e+1	2.0635343551635742e+1	3.0381412506103516e+0	1.4722998156090894e-1	4.1714346989631653e-6
-	[2]	1.6796028614044189e+0	4.7177438735961914e+0	3.0381410121917725e+0	6.4398176195942802e-1	9.5369192404747006e-7
-	Max AbsError of 3.0381412506103516e+0 at index of 0.
-	Max RelError of 6.4398176195942802e-1 at index of 2.
+	[0]	3.1162130355834961e+1	2.5141529083251953e+1	6.0206012725830078e+0	2.3946838128447945e-1	5.0823601041793820e-6
+	[1]	2.6655942916870117e+1	2.0635343551635742e+1	6.0205993652343750e+0	2.9176152799051064e-1	4.1714346989631653e-6
+	[2]	1.0738344192504883e+1	4.7177438735961914e+0	6.0206003189086914e+0	1.2761609108549110e+0	9.5369192404747006e-7
+	Max AbsError of 6.0206012725830078e+0 at index of 0.
+	Max RelError of 1.2761609108549110e+0 at index of 2.
  assert_true: expected true got false
-FAIL < [5.1] 2 out of 2 assertions were failed. assert_true: expected true got false
+FAIL < [5.1] 1 out of 2 assertions were failed. assert_true: expected true got false
 PASS > [3-channel]  
-FAIL X Analyser downmix 3-channel to mono time data expected to be equal to the array [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1...] but differs in 256 places:
-	Index	Actual			Expected
-	[0]	4.6666669845581055e+0	1.0000000000000000e+0
-	[1]	4.6666669845581055e+0	1.0000000000000000e+0
-	[2]	4.6666669845581055e+0	1.0000000000000000e+0
-	[3]	4.6666669845581055e+0	1.0000000000000000e+0
-	...and 252 more errors. assert_true: expected true got false
+PASS   Analyser downmix 3-channel to mono time data is identical to the array [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1...]. 
 FAIL X Analyser downmix 3-channel to mono freq data does not equal [-7.535013675689697,-12.041200637817383,-27.95880126953125,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":6.3283e-8}.
 	Index	Actual			Expected		AbsError		RelError		Test threshold
-	[0]	1.1865721702575684e+1	-7.5350136756896973e+0	1.9400735378265381e+1	2.5747445476918243e+0	4.7683827043867111e-7
-	[1]	7.3595361709594727e+0	-1.2041200637817383e+1	1.9400736808776855e+1	1.6111962081128048e+0	7.6200329996299745e-7
-	[2]	-8.5580644607543945e+0	-2.7958801269531250e+1	1.9400736808776855e+1	6.9390445683804247e-1	1.7693168207397460e-6
-	Max AbsError of 1.9400736808776855e+1 at index of 1.
-	Max RelError of 2.5747445476918243e+0 at index of 0.
+	[0]	-1.5144139528274536e+0	-7.5350136756896973e+0	6.0205997228622437e+0	7.9901642943085494e-1	4.7683827043867111e-7
+	[1]	-6.0206003189086914e+0	-1.2041200637817383e+1	6.0206003189086914e+0	5.0000000000000000e-1	7.6200329996299745e-7
+	[2]	-2.1938199996948242e+1	-2.7958801269531250e+1	6.0206012725830078e+0	2.1533831921270877e-1	1.7693168207397460e-6
+	Max AbsError of 6.0206012725830078e+0 at index of 2.
+	Max RelError of 7.9901642943085494e-1 at index of 0.
  assert_true: expected true got false
-FAIL < [3-channel] 2 out of 2 assertions were failed. assert_true: expected true got false
+FAIL < [3-channel] 1 out of 2 assertions were failed. assert_true: expected true got false
 FAIL # AUDIT TASK RUNNER FINISHED: 5 out of 5 tasks were failed. assert_true: expected true got false
 

Modified: trunk/Source/WebCore/ChangeLog (267345 => 267346)


--- trunk/Source/WebCore/ChangeLog	2020-09-21 15:11:43 UTC (rev 267345)
+++ trunk/Source/WebCore/ChangeLog	2020-09-21 15:34:01 UTC (rev 267346)
@@ -1,3 +1,23 @@
+2020-09-21  Chris Dumez  <cdu...@apple.com>
+
+        AnalyserNode should downmix input audio to mono
+        https://bugs.webkit.org/show_bug.cgi?id=216736
+
+        Reviewed by Sam Weinig.
+
+        AnalyserNode should downmix input audio to mono:
+        - https://www.w3.org/TR/webaudio/#current-time-domain-data
+
+        This patch is based on the following Blink change:
+        - https://codereview.chromium.org/1803233002
+
+        No new tests, rebaselined existing test.
+
+        * Modules/webaudio/RealtimeAnalyser.cpp:
+        (WebCore::RealtimeAnalyser::RealtimeAnalyser):
+        (WebCore::RealtimeAnalyser::writeInput):
+        * Modules/webaudio/RealtimeAnalyser.h:
+
 2020-09-21  Wenson Hsieh  <wenson_hs...@apple.com>
 
         REGRESSION (r257839): Can't add a memo when transferring funds in First Tech Credit Union App

Modified: trunk/Source/WebCore/Modules/webaudio/RealtimeAnalyser.cpp (267345 => 267346)


--- trunk/Source/WebCore/Modules/webaudio/RealtimeAnalyser.cpp	2020-09-21 15:11:43 UTC (rev 267345)
+++ trunk/Source/WebCore/Modules/webaudio/RealtimeAnalyser.cpp	2020-09-21 15:34:01 UTC (rev 267346)
@@ -29,6 +29,7 @@
 #include "RealtimeAnalyser.h"
 
 #include "AudioBus.h"
+#include "AudioNode.h"
 #include "AudioUtilities.h"
 #include "FFTFrame.h"
 #include "VectorMath.h"
@@ -54,6 +55,7 @@
 RealtimeAnalyser::RealtimeAnalyser()
     : m_inputBuffer(InputBufferSize)
     , m_writeIndex(0)
+    , m_downmixBus(AudioBus::create(1, AudioNode::ProcessingSizeInFrames))
     , m_fftSize(DefaultFFTSize)
     , m_magnitudeBuffer(DefaultFFTSize / 2)
     , m_smoothingTimeConstant(DefaultSmoothingTimeConstant)
@@ -107,23 +109,14 @@
         return;    
     
     // Perform real-time analysis
-    const float* source = bus->channel(0)->data();
     float* dest = m_inputBuffer.data() + m_writeIndex;
 
-    // The source has already been sanity checked with isBusGood above.
-    memcpy(dest, source, sizeof(float) * framesToProcess);
+    // Clear the bus and downmix the input according to the down mixing rules.
+    // Then save the result in the m_inputBuffer at the appropriate place.
+    m_downmixBus->zero();
+    m_downmixBus->sumFrom(*bus);
+    memcpy(dest, m_downmixBus->channel(0)->data(), sizeof(float) * framesToProcess);
 
-    // Sum all channels in one if numberOfChannels > 1.
-    unsigned numberOfChannels = bus->numberOfChannels();
-    if (numberOfChannels > 1) {
-        for (unsigned i = 1; i < numberOfChannels; i++) {
-            source = bus->channel(i)->data();
-            VectorMath::vadd(dest, 1, source, 1, dest, 1, framesToProcess);
-        }
-        const float scale =  1.0 / numberOfChannels;
-        VectorMath::vsmul(dest, 1, &scale, dest, 1, framesToProcess);
-    }
-
     m_writeIndex += framesToProcess;
     if (m_writeIndex >= InputBufferSize)
         m_writeIndex = 0;

Modified: trunk/Source/WebCore/Modules/webaudio/RealtimeAnalyser.h (267345 => 267346)


--- trunk/Source/WebCore/Modules/webaudio/RealtimeAnalyser.h	2020-09-21 15:11:43 UTC (rev 267345)
+++ trunk/Source/WebCore/Modules/webaudio/RealtimeAnalyser.h	2020-09-21 15:34:01 UTC (rev 267346)
@@ -80,6 +80,9 @@
     // The audio thread writes the input audio here.
     AudioFloatArray m_inputBuffer;
     unsigned m_writeIndex;
+
+    // AudioBus used for downmixing input audio before copying it to m_inputBuffer.
+    RefPtr<AudioBus> m_downmixBus;
     
     size_t m_fftSize;
     std::unique_ptr<FFTFrame> m_analysisFrame;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to