Skip to content

Commit cdb9769

Browse files
committed
[Cocoa] Vectorize linear to decibels conversion in RealtimeAnalyser
https://bugs.webkit.org/show_bug.cgi?id=217322 Reviewed by Darin Adler. Source/WebCore: Vectorize linear to decibels conversion in RealtimeAnalyser on Cocoa ports for performance. No new tests, no web-facing behavior change. * Modules/webaudio/RealtimeAnalyser.cpp: (WebCore::RealtimeAnalyser::getFloatFrequencyData): * platform/audio/VectorMath.cpp: (WebCore::VectorMath::linearToDecibels): * platform/audio/VectorMath.h: LayoutTests: Slightly increase the error threshold in a few WebAudio tests because the vectorization output for linear to decibels conversion is not quite identical to our previous output (although very close). * webaudio/Analyser/realtimeanalyser-downmix-expected.txt: * webaudio/Analyser/realtimeanalyser-downmix.html: * webaudio/Analyser/realtimeanalyser-fftsize-reset-expected.txt: * webaudio/Analyser/realtimeanalyser-fftsize-reset.html: * webaudio/Analyser/realtimeanalyser-freq-data-expected.txt: * webaudio/Analyser/realtimeanalyser-freq-data.html: Canonical link: https://commits.webkit.org/230109@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@268006 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 11d29c4 commit cdb9769

11 files changed

Lines changed: 352 additions & 308 deletions

LayoutTests/ChangeLog

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2020-10-05 Chris Dumez <cdumez@apple.com>
2+
3+
[Cocoa] Vectorize linear to decibels conversion in RealtimeAnalyser
4+
https://bugs.webkit.org/show_bug.cgi?id=217322
5+
6+
Reviewed by Darin Adler.
7+
8+
Slightly increase the error threshold in a few WebAudio tests because the vectorization
9+
output for linear to decibels conversion is not quite identical to our previous output
10+
(although very close).
11+
12+
* webaudio/Analyser/realtimeanalyser-downmix-expected.txt:
13+
* webaudio/Analyser/realtimeanalyser-downmix.html:
14+
* webaudio/Analyser/realtimeanalyser-fftsize-reset-expected.txt:
15+
* webaudio/Analyser/realtimeanalyser-fftsize-reset.html:
16+
* webaudio/Analyser/realtimeanalyser-freq-data-expected.txt:
17+
* webaudio/Analyser/realtimeanalyser-freq-data.html:
18+
119
2020-10-05 Peng Liu <peng.liu6@apple.com>
220

321
Update TestExpectations for layout tests related to GPU process features

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ 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-
PASS Analyser downmix mono to mono freq data equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":6.3283e-8}.
11+
PASS Analyser downmix mono to mono freq data equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":1.2657e-7}.
1212
PASS < [mono] All assertions passed. (total 2 assertions)
1313
PASS > [stereo]
1414
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...].
@@ -24,7 +24,7 @@ PASS Analyser downmix 5.1 to mono freq data equals [expected array] with an el
2424
PASS < [5.1] All assertions passed. (total 2 assertions)
2525
PASS > [3-channel]
2626
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...].
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}.
27+
PASS Analyser downmix 3-channel to mono freq data equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":1.2657e-7}.
2828
PASS < [3-channel] All assertions passed. (total 2 assertions)
2929
PASS # AUDIT TASK RUNNER FINISHED: 5 tasks ran successfully.
3030

LayoutTests/webaudio/Analyser/realtimeanalyser-downmix.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
let audit = Audit.createTaskRunner();
2020

2121
let testConfigs = [
22-
{channelCount: 1, message: 'mono', floatRelError: 6.3283e-8},
22+
{channelCount: 1, message: 'mono', floatRelError: 1.2657e-7},
2323
{channelCount: 2, message: 'stereo', floatRelError: 1.1681e-7},
2424
{channelCount: 4, message: 'quad', floatRelError: 4.9793e-7},
2525
{channelCount: 6, message: '5.1', floatRelError: 2.0215e-7},
26-
{channelCount: 3, message: '3-channel', floatRelError: 6.3283e-8}
26+
{channelCount: 3, message: '3-channel', floatRelError: 1.2657e-7}
2727
];
2828

2929
// Create tasks for each entry in testConfigs

LayoutTests/webaudio/Analyser/realtimeanalyser-fftsize-reset-expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ PASS Executing "512->256"
55
PASS Audit report
66
PASS > [128->1024]
77
PASS Time data equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
8-
PASS Linear FFT data after setting fftSize = 1024 equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0.0000019455}.
8+
PASS Linear FFT data after setting fftSize = 1024 equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0.0000036296}.
99
PASS < [128->1024] All assertions passed. (total 2 assertions)
1010
PASS > [512->256]
1111
PASS Time data equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
12-
PASS Linear FFT data after setting fftSize = 256 equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0.0000018592}.
12+
PASS Linear FFT data after setting fftSize = 256 equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0.0000018614}.
1313
PASS < [512->256] All assertions passed. (total 2 assertions)
1414
PASS # AUDIT TASK RUNNER FINISHED: 2 tasks ran successfully.
1515

LayoutTests/webaudio/Analyser/realtimeanalyser-fftsize-reset.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
testFFTSize(should, {
2424
initialFFTSize: 128,
2525
finalFFTSize: 1024,
26-
errorThreshold: {relativeThreshold: 1.9455e-6}
26+
errorThreshold: {relativeThreshold: 3.6296e-6}
2727
}).then(() => task.done());
2828
});
2929

3030
audit.define('512->256', (task, should) => {
3131
testFFTSize(should, {
3232
initialFFTSize: 512,
3333
finalFFTSize: 256,
34-
errorThreshold: {relativeThreshold: 1.8592e-6}
34+
errorThreshold: {relativeThreshold: 1.8614e-6}
3535
}).then(() => task.done());
3636
});
3737

LayoutTests/webaudio/Analyser/realtimeanalyser-freq-data-expected.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@ PASS Order: 12: Max FFT value is greater than or equal to -30.
6262
PASS 4096-point byte FFT equals [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
6363
PASS < [12-order FFT] All assertions passed. (total 4 assertions)
6464
PASS > [13-order FFT]
65-
PASS 8192-point float FFT equals [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":3.2106e-7}.
65+
PASS 8192-point float FFT equals [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":3.4196e-7}.
6666
PASS Order: 13: Min FFT value is less than or equal to -100.
6767
PASS Order: 13: Max FFT value is greater than or equal to -30.
6868
PASS 8192-point byte FFT equals [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
6969
PASS < [13-order FFT] All assertions passed. (total 4 assertions)
7070
PASS > [14-order FFT]
71-
PASS 16384-point float FFT equals [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":1.1756e-7}.
71+
PASS 16384-point float FFT equals [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":1.6257e-7}.
7272
PASS Order: 14: Min FFT value is less than or equal to -100.
7373
PASS Order: 14: Max FFT value is greater than or equal to -30.
7474
PASS 16384-point byte FFT equals [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
7575
PASS < [14-order FFT] All assertions passed. (total 4 assertions)
7676
PASS > [15-order FFT]
77-
PASS 32768-point float FFT equals [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":1.1756e-7}.
77+
PASS 32768-point float FFT equals [-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":2.0876e-7}.
7878
PASS Order: 15: Min FFT value is less than or equal to -100.
7979
PASS Order: 15: Max FFT value is greater than or equal to -30.
8080
PASS 32768-point byte FFT equals [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.

LayoutTests/webaudio/Analyser/realtimeanalyser-freq-data.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
{order: 10, floatRelError: 2.9771e-5, byteThreshold: 1},
5151
{order: 11, floatRelError: 1.3456e-5},
5252
{order: 12, floatRelError: 4.6116e-7},
53-
{order: 13, floatRelError: 3.2106e-7},
54-
{order: 14, floatRelError: 1.1756e-7},
55-
{order: 15, floatRelError: 1.1756e-7}
53+
{order: 13, floatRelError: 3.4196e-7},
54+
{order: 14, floatRelError: 1.6257e-7},
55+
{order: 15, floatRelError: 2.0876e-7}
5656
];
5757

5858
// True if all of the basic tests passed.

Source/WebCore/ChangeLog

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2020-10-05 Chris Dumez <cdumez@apple.com>
2+
3+
[Cocoa] Vectorize linear to decibels conversion in RealtimeAnalyser
4+
https://bugs.webkit.org/show_bug.cgi?id=217322
5+
6+
Reviewed by Darin Adler.
7+
8+
Vectorize linear to decibels conversion in RealtimeAnalyser on Cocoa ports for
9+
performance.
10+
11+
No new tests, no web-facing behavior change.
12+
13+
* Modules/webaudio/RealtimeAnalyser.cpp:
14+
(WebCore::RealtimeAnalyser::getFloatFrequencyData):
15+
* platform/audio/VectorMath.cpp:
16+
(WebCore::VectorMath::linearToDecibels):
17+
* platform/audio/VectorMath.h:
18+
119
2020-10-05 David Kilzer <ddkilzer@apple.com>
220

321
Make NetscapePlugInStreamLoaderClient a weak pointer on NetscapePlugInStreamLoader

Source/WebCore/Modules/webaudio/RealtimeAnalyser.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,8 @@ void RealtimeAnalyser::getFloatFrequencyData(Float32Array& destinationArray)
185185
doFFTAnalysisIfNecessary();
186186

187187
// Convert from linear magnitude to floating-point decibels.
188-
unsigned sourceLength = magnitudeBuffer().size();
189-
size_t length = std::min(sourceLength, destinationArray.length());
190-
if (length > 0) {
191-
auto* source = magnitudeBuffer().data();
192-
auto* destination = destinationArray.data();
193-
194-
for (size_t i = 0; i < length; ++i)
195-
destination[i] = AudioUtilities::linearToDecibels(source[i]);
196-
}
188+
size_t length = std::min<size_t>(magnitudeBuffer().size(), destinationArray.length());
189+
VectorMath::linearToDecibels(magnitudeBuffer().data(), 1, destinationArray.data(), 1, length);
197190
}
198191

199192
void RealtimeAnalyser::getByteFrequencyData(Uint8Array& destinationArray)

0 commit comments

Comments
 (0)