Commit 63f718b
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-d52691b4dbfc1 parent b8faeec commit 63f718b
16 files changed
Lines changed: 158 additions & 616 deletions
File tree
- LayoutTests
- platform/mac
- webaudio
- Analyser
- webrtc
- Source/WebCore
- Modules/webaudio
- platform/audio
- gstreamer
- mac
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
1 | 19 | | |
2 | 20 | | |
3 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | 333 | | |
338 | 334 | | |
339 | 335 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1616 | 1616 | | |
1617 | 1617 | | |
1618 | 1618 | | |
1619 | | - | |
1620 | 1619 | | |
1621 | 1620 | | |
1622 | 1621 | | |
| |||
Lines changed: 11 additions & 46 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 11 | + | |
| 12 | + | |
20 | 13 | | |
21 | 14 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 15 | + | |
| 16 | + | |
31 | 17 | | |
32 | 18 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 19 | + | |
| 20 | + | |
42 | 21 | | |
43 | 22 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 23 | + | |
| 24 | + | |
53 | 25 | | |
54 | 26 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
65 | 30 | | |
0 commit comments