Skip to content

Commit 9792b5a

Browse files
committed
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: Canonical link: https://commits.webkit.org/229565@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@267346 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent ebe8186 commit 9792b5a

5 files changed

Lines changed: 55 additions & 40 deletions

File tree

LayoutTests/ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2020-09-21 Chris Dumez <cdumez@apple.com>
2+
3+
AnalyserNode should downmix input audio to mono
4+
https://bugs.webkit.org/show_bug.cgi?id=216736
5+
6+
Reviewed by Sam Weinig.
7+
8+
Rebaseline test now that more checks are passing.
9+
10+
* webaudio/Analyser/realtimeanalyser-downmix-expected.txt:
11+
112
2020-09-21 Wenson Hsieh <wenson_hsieh@apple.com>
213

314
REGRESSION (r257839): Can't add a memo when transferring funds in First Tech Credit Union App

LayoutTests/webaudio/Analyser/realtimeanalyser-downmix-expected.txt

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,26 @@ FAIL X Analyser downmix quad to mono freq data does not equal [9.966211318969727
4040
assert_true: expected true got false
4141
FAIL < [quad] 1 out of 2 assertions were failed. assert_true: expected true got false
4242
PASS > [5.1]
43-
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:
44-
Index Actual Expected
45-
[0] 1.5166666984558105e+1 4.3035533905029297e+1
46-
[1] 1.5166666984558105e+1 4.3035533905029297e+1
47-
[2] 1.5166666984558105e+1 4.3035533905029297e+1
48-
[3] 1.5166666984558105e+1 4.3035533905029297e+1
49-
...and 252 more errors. assert_true: expected true got false
43+
PASS Analyser downmix 5.1 to mono time data is identical to the array [expected array].
5044
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}.
5145
Index Actual Expected AbsError RelError Test threshold
52-
[0] 2.2103387832641602e+1 2.5141529083251953e+1 3.0381412506103516e+0 1.2084154629378574e-1 5.0823601041793820e-6
53-
[1] 1.7597202301025391e+1 2.0635343551635742e+1 3.0381412506103516e+0 1.4722998156090894e-1 4.1714346989631653e-6
54-
[2] 1.6796028614044189e+0 4.7177438735961914e+0 3.0381410121917725e+0 6.4398176195942802e-1 9.5369192404747006e-7
55-
Max AbsError of 3.0381412506103516e+0 at index of 0.
56-
Max RelError of 6.4398176195942802e-1 at index of 2.
46+
[0] 3.1162130355834961e+1 2.5141529083251953e+1 6.0206012725830078e+0 2.3946838128447945e-1 5.0823601041793820e-6
47+
[1] 2.6655942916870117e+1 2.0635343551635742e+1 6.0205993652343750e+0 2.9176152799051064e-1 4.1714346989631653e-6
48+
[2] 1.0738344192504883e+1 4.7177438735961914e+0 6.0206003189086914e+0 1.2761609108549110e+0 9.5369192404747006e-7
49+
Max AbsError of 6.0206012725830078e+0 at index of 0.
50+
Max RelError of 1.2761609108549110e+0 at index of 2.
5751
assert_true: expected true got false
58-
FAIL < [5.1] 2 out of 2 assertions were failed. assert_true: expected true got false
52+
FAIL < [5.1] 1 out of 2 assertions were failed. assert_true: expected true got false
5953
PASS > [3-channel]
60-
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:
61-
Index Actual Expected
62-
[0] 4.6666669845581055e+0 1.0000000000000000e+0
63-
[1] 4.6666669845581055e+0 1.0000000000000000e+0
64-
[2] 4.6666669845581055e+0 1.0000000000000000e+0
65-
[3] 4.6666669845581055e+0 1.0000000000000000e+0
66-
...and 252 more errors. assert_true: expected true got false
54+
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...].
6755
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}.
6856
Index Actual Expected AbsError RelError Test threshold
69-
[0] 1.1865721702575684e+1 -7.5350136756896973e+0 1.9400735378265381e+1 2.5747445476918243e+0 4.7683827043867111e-7
70-
[1] 7.3595361709594727e+0 -1.2041200637817383e+1 1.9400736808776855e+1 1.6111962081128048e+0 7.6200329996299745e-7
71-
[2] -8.5580644607543945e+0 -2.7958801269531250e+1 1.9400736808776855e+1 6.9390445683804247e-1 1.7693168207397460e-6
72-
Max AbsError of 1.9400736808776855e+1 at index of 1.
73-
Max RelError of 2.5747445476918243e+0 at index of 0.
57+
[0] -1.5144139528274536e+0 -7.5350136756896973e+0 6.0205997228622437e+0 7.9901642943085494e-1 4.7683827043867111e-7
58+
[1] -6.0206003189086914e+0 -1.2041200637817383e+1 6.0206003189086914e+0 5.0000000000000000e-1 7.6200329996299745e-7
59+
[2] -2.1938199996948242e+1 -2.7958801269531250e+1 6.0206012725830078e+0 2.1533831921270877e-1 1.7693168207397460e-6
60+
Max AbsError of 6.0206012725830078e+0 at index of 2.
61+
Max RelError of 7.9901642943085494e-1 at index of 0.
7462
assert_true: expected true got false
75-
FAIL < [3-channel] 2 out of 2 assertions were failed. assert_true: expected true got false
63+
FAIL < [3-channel] 1 out of 2 assertions were failed. assert_true: expected true got false
7664
FAIL # AUDIT TASK RUNNER FINISHED: 5 out of 5 tasks were failed. assert_true: expected true got false
7765

Source/WebCore/ChangeLog

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
2020-09-21 Chris Dumez <cdumez@apple.com>
2+
3+
AnalyserNode should downmix input audio to mono
4+
https://bugs.webkit.org/show_bug.cgi?id=216736
5+
6+
Reviewed by Sam Weinig.
7+
8+
AnalyserNode should downmix input audio to mono:
9+
- https://www.w3.org/TR/webaudio/#current-time-domain-data
10+
11+
This patch is based on the following Blink change:
12+
- https://codereview.chromium.org/1803233002
13+
14+
No new tests, rebaselined existing test.
15+
16+
* Modules/webaudio/RealtimeAnalyser.cpp:
17+
(WebCore::RealtimeAnalyser::RealtimeAnalyser):
18+
(WebCore::RealtimeAnalyser::writeInput):
19+
* Modules/webaudio/RealtimeAnalyser.h:
20+
121
2020-09-21 Wenson Hsieh <wenson_hsieh@apple.com>
222

323
REGRESSION (r257839): Can't add a memo when transferring funds in First Tech Credit Union App

Source/WebCore/Modules/webaudio/RealtimeAnalyser.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "RealtimeAnalyser.h"
3030

3131
#include "AudioBus.h"
32+
#include "AudioNode.h"
3233
#include "AudioUtilities.h"
3334
#include "FFTFrame.h"
3435
#include "VectorMath.h"
@@ -54,6 +55,7 @@ const unsigned RealtimeAnalyser::InputBufferSize = RealtimeAnalyser::MaxFFTSize
5455
RealtimeAnalyser::RealtimeAnalyser()
5556
: m_inputBuffer(InputBufferSize)
5657
, m_writeIndex(0)
58+
, m_downmixBus(AudioBus::create(1, AudioNode::ProcessingSizeInFrames))
5759
, m_fftSize(DefaultFFTSize)
5860
, m_magnitudeBuffer(DefaultFFTSize / 2)
5961
, m_smoothingTimeConstant(DefaultSmoothingTimeConstant)
@@ -107,22 +109,13 @@ void RealtimeAnalyser::writeInput(AudioBus* bus, size_t framesToProcess)
107109
return;
108110

109111
// Perform real-time analysis
110-
const float* source = bus->channel(0)->data();
111112
float* dest = m_inputBuffer.data() + m_writeIndex;
112113

113-
// The source has already been sanity checked with isBusGood above.
114-
memcpy(dest, source, sizeof(float) * framesToProcess);
115-
116-
// Sum all channels in one if numberOfChannels > 1.
117-
unsigned numberOfChannels = bus->numberOfChannels();
118-
if (numberOfChannels > 1) {
119-
for (unsigned i = 1; i < numberOfChannels; i++) {
120-
source = bus->channel(i)->data();
121-
VectorMath::vadd(dest, 1, source, 1, dest, 1, framesToProcess);
122-
}
123-
const float scale = 1.0 / numberOfChannels;
124-
VectorMath::vsmul(dest, 1, &scale, dest, 1, framesToProcess);
125-
}
114+
// Clear the bus and downmix the input according to the down mixing rules.
115+
// Then save the result in the m_inputBuffer at the appropriate place.
116+
m_downmixBus->zero();
117+
m_downmixBus->sumFrom(*bus);
118+
memcpy(dest, m_downmixBus->channel(0)->data(), sizeof(float) * framesToProcess);
126119

127120
m_writeIndex += framesToProcess;
128121
if (m_writeIndex >= InputBufferSize)

Source/WebCore/Modules/webaudio/RealtimeAnalyser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class RealtimeAnalyser {
8080
// The audio thread writes the input audio here.
8181
AudioFloatArray m_inputBuffer;
8282
unsigned m_writeIndex;
83+
84+
// AudioBus used for downmixing input audio before copying it to m_inputBuffer.
85+
RefPtr<AudioBus> m_downmixBus;
8386

8487
size_t m_fftSize;
8588
std::unique_ptr<FFTFrame> m_analysisFrame;

0 commit comments

Comments
 (0)