Skip to content

Commit 63f718b

Browse files
committed
Values returned by FFTFrame::doFFT() are twice as large as they should be
https://bugs.webkit.org/show_bug.cgi?id=216781 Reviewed by Darin Adler. Source/WebCore: To provide the best possible execution speeds, the vDSP library's functions don't always adhere strictly to textbook formulas for Fourier transforms, and must be scaled accordingly [1]. In the case of a Real forward Transform like in FFTFrame::doFFT(): RFimp = RFmath * 2 so we need to divide the output by 2 to get the correct value. We were failing to do this scaling and this was causing AnalyserNode tests to fail. [1] See https://developer.apple.com/library/archive/documentation/Performance/Conceptual/vDSP_Programming_Guide/UsingFourierTransforms/UsingFourierTransforms.html#//apple_ref/doc/uid/TP40005147-CH3-SW5 No new tests, rebaselined existing tests. * Modules/webaudio/PeriodicWave.cpp: (WebCore::PeriodicWave::createBandLimitedTables): Update normalization factor now that FFTFrame::doInverseFFT() has been fixed. The new normalization factor matches the value used by blink at: - https://github.com/chromium/chromium/blob/master/third_party/blink/renderer/modules/webaudio/periodic_wave.cc * platform/audio/FFTFrame.cpp: (WebCore::FFTFrame::multiply): We were applying a 0.5 scaling factor to the output of vDSP_zvmul(). However, the documentation for vDSP_zvmul() does not indicate that its output is twice as large as expected. Odds are that this was done because we used to have a bug in FFTFrame::doFFT() that was returning values twice as large as expected. SInce this function relies on VectorMath, there is no need for its implementation to be platform-specific. * platform/audio/FFTFrameStub.cpp: * platform/audio/gstreamer/FFTFrameGStreamer.cpp: (WebCore::FFTFrame::doFFT): (WebCore::FFTFrame::doInverseFFT): Drop 2 factor in the GStreamer implementation that was added to try and be consistent with the incorrect Mac implementation. * platform/audio/mac/FFTFrameMac.cpp: (WebCore::FFTFrame::doFFT): Fix issue where the values returned by doFFT() were twice as large as expected due to the odd behavior of vDSP_fft_zrip(). (WebCore::FFTFrame::doInverseFFT): Drop 2 factor in doInverseFFT that was added because the output of doFFT() was twice as large as expected and we wanted x == InverseFFT(FFT(x)). LayoutTests: * webaudio/Analyser/realtimeanalyser-downmix-expected.txt: * webaudio/Analyser/realtimeanalyser-freq-data-expected.txt: * webaudio/Analyser/realtimeanalyser-freq-data-smoothing-expected.txt: * webaudio/Analyser/realtimeanalyser-multiple-calls-expected.txt: Rebaseline tests that are passing now that the bug has been fixed. * webaudio/realtimeanalyser-fft-scaling-expected.txt: Removed. * webaudio/realtimeanalyser-fft-scaling.html: Removed. Drop outdated test. This test was imported into WPT and now resides at: - imported/w3c/web-platform-tests/webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-fft-scaling.html Canonical link: https://commits.webkit.org/229597@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@267383 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent b8faeec commit 63f718b

16 files changed

Lines changed: 158 additions & 616 deletions

LayoutTests/ChangeLog

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2020-09-21 Chris Dumez <cdumez@apple.com>
2+
3+
Values returned by FFTFrame::doFFT() are twice as large as they should be
4+
https://bugs.webkit.org/show_bug.cgi?id=216781
5+
6+
Reviewed by Darin Adler.
7+
8+
* webaudio/Analyser/realtimeanalyser-downmix-expected.txt:
9+
* webaudio/Analyser/realtimeanalyser-freq-data-expected.txt:
10+
* webaudio/Analyser/realtimeanalyser-freq-data-smoothing-expected.txt:
11+
* webaudio/Analyser/realtimeanalyser-multiple-calls-expected.txt:
12+
Rebaseline tests that are passing now that the bug has been fixed.
13+
14+
* webaudio/realtimeanalyser-fft-scaling-expected.txt: Removed.
15+
* webaudio/realtimeanalyser-fft-scaling.html: Removed.
16+
Drop outdated test. This test was imported into WPT and now resides at:
17+
- imported/w3c/web-platform-tests/webaudio/the-audio-api/the-analysernode-interface/realtimeanalyser-fft-scaling.html
18+
119
2020-09-21 Chris Dumez <cdumez@apple.com>
220

321
Properly handle AudioParam.setTargetAtTime() followed by a ramp

LayoutTests/TestExpectations

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,6 @@ imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/
330330
imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/buffer-resampling.html [ Pass Failure ]
331331
imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/sub-sample-buffer-stitching.html [ Pass Failure ]
332332
webaudio/Analyser/handle-silent-inputs.html [ Pass Failure ]
333-
webaudio/Analyser/realtimeanalyser-fftsize-reset.html [ Pass Failure ]
334-
webaudio/Analyser/realtimeanalyser-freq-data-smoothing.html [ Pass Failure ]
335-
webaudio/Analyser/realtimeanalyser-freq-data.html [ Pass Failure ]
336-
webaudio/Analyser/realtimeanalyser-multiple-calls.html [ Pass Failure ]
337333
webaudio/AudioBufferSource/audiobuffersource-detune-modulation.html [ Pass Failure ]
338334
webaudio/AudioBufferSource/audiobuffersource-playbackrate-modulation.html [ Pass Failure ]
339335

LayoutTests/platform/mac/TestExpectations

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,6 @@ webkit.org/b/136627 media/track/track-cue-rendering-vertical.html [ Failure ]
16161616

16171617
# <rdar://problem/47088939>
16181618
imported/w3c/web-platform-tests/webaudio/the-audio-api/the-mediaelementaudiosourcenode-interface/mediaElementAudioSourceToScriptProcessorTest.html [ Failure ]
1619-
webaudio/realtimeanalyser-fft-scaling.html [ Pass Failure ]
16201619
webaudio/oscillator-sine.html [ Skip ]
16211620

16221621
webkit.org/b/199013 [ Debug ] imported/w3c/web-platform-tests/websockets/Create-Secure-verify-url-set-non-default-port.any.html [ Pass Failure ]

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

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,23 @@ PASS Executing "3-channel"
88
PASS Audit report
99
PASS > [mono]
1010
PASS Analyser downmix mono 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...].
11-
FAIL X Analyser downmix mono 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}.
12-
Index Actual Expected AbsError RelError Test threshold
13-
[0] -1.5144139528274536e+0 -7.5350136756896973e+0 6.0205997228622437e+0 7.9901642943085494e-1 4.7683827043867111e-7
14-
[1] -6.0206003189086914e+0 -1.2041200637817383e+1 6.0206003189086914e+0 5.0000000000000000e-1 7.6200329996299745e-7
15-
[2] -2.1938199996948242e+1 -2.7958801269531250e+1 6.0206012725830078e+0 2.1533831921270877e-1 1.7693168207397460e-6
16-
Max AbsError of 6.0206012725830078e+0 at index of 2.
17-
Max RelError of 7.9901642943085494e-1 at index of 0.
18-
assert_true: expected true got false
19-
FAIL < [mono] 1 out of 2 assertions were failed. assert_true: expected true got false
11+
PASS Analyser downmix mono to mono freq data equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":6.3283e-8}.
12+
PASS < [mono] All assertions passed. (total 2 assertions)
2013
PASS > [stereo]
2114
PASS Analyser downmix stereo to mono time data is identical to the array [2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5,2.5...].
22-
FAIL X Analyser downmix stereo to mono freq data does not equal [0.42378559708595276,-4.082399845123291,-20,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":1.1681e-7}.
23-
Index Actual Expected AbsError RelError Test threshold
24-
[0] 6.4443855285644531e+0 4.2378559708595276e-1 6.0205999314785004e+0 1.4206712009274337e+1 4.9502395595610142e-8
25-
[1] 1.9382002353668213e+0 -4.0823998451232910e+0 6.0206000804901123e+0 1.4747698189539507e+0 4.7686512590885159e-7
26-
[2] -1.3979400634765625e+1 -2.0000000000000000e+1 6.0205993652343750e+0 3.0102996826171874e-1 2.3361999999999998e-6
27-
Max AbsError of 6.0206000804901123e+0 at index of 1.
28-
Max RelError of 1.4206712009274337e+1 at index of 0.
29-
assert_true: expected true got false
30-
FAIL < [stereo] 1 out of 2 assertions were failed. assert_true: expected true got false
15+
PASS Analyser downmix stereo to mono freq data equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":1.1681e-7}.
16+
PASS < [stereo] All assertions passed. (total 2 assertions)
3117
PASS > [quad]
3218
PASS Analyser downmix quad to mono time data is identical to the array [7.5,7.5,7.5,7.5,7.5,7.5,7.5,7.5,7.5,7.5,7.5,7.5,7.5,7.5,7.5,7.5...].
33-
FAIL X Analyser downmix quad to mono freq data does not equal [9.966211318969727,5.460024833679199,-10.457574844360352,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":4.9793e-7}.
34-
Index Actual Expected AbsError RelError Test threshold
35-
[0] 1.5986810684204102e+1 9.9662113189697266e+0 6.0205993652343750e+0 6.0410111451025950e-1 4.9624756020545961e-6
36-
[1] 1.1480626106262207e+1 5.4600248336791992e+0 6.0206012725830078e+0 1.1026692104852696e+0 2.7187101654338836e-6
37-
[2] -4.4369745254516602e+0 -1.0457574844360352e+1 6.0206003189086914e+0 5.7571668465328085e-1 5.2071402422523503e-6
38-
Max AbsError of 6.0206012725830078e+0 at index of 1.
39-
Max RelError of 1.1026692104852696e+0 at index of 1.
40-
assert_true: expected true got false
41-
FAIL < [quad] 1 out of 2 assertions were failed. assert_true: expected true got false
19+
PASS Analyser downmix quad to mono freq data equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":4.9793e-7}.
20+
PASS < [quad] All assertions passed. (total 2 assertions)
4221
PASS > [5.1]
4322
PASS Analyser downmix 5.1 to mono time data is identical to the array [expected array].
44-
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}.
45-
Index Actual Expected AbsError RelError Test threshold
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.
51-
assert_true: expected true got false
52-
FAIL < [5.1] 1 out of 2 assertions were failed. assert_true: expected true got false
23+
PASS Analyser downmix 5.1 to mono freq data equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":2.0215e-7}.
24+
PASS < [5.1] All assertions passed. (total 2 assertions)
5325
PASS > [3-channel]
5426
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...].
55-
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}.
56-
Index Actual Expected AbsError RelError Test threshold
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.
62-
assert_true: expected true got false
63-
FAIL < [3-channel] 1 out of 2 assertions were failed. assert_true: expected true got false
64-
FAIL # AUDIT TASK RUNNER FINISHED: 5 out of 5 tasks were failed. assert_true: expected true got false
27+
PASS Analyser downmix 3-channel to mono freq data equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":6.3283e-8}.
28+
PASS < [3-channel] All assertions passed. (total 2 assertions)
29+
PASS # AUDIT TASK RUNNER FINISHED: 5 tasks ran successfully.
6530

0 commit comments

Comments
 (0)