Bug 217322 - [Cocoa] Vectorize linear to decibels conversion in RealtimeAnalyser
Summary: [Cocoa] Vectorize linear to decibels conversion in RealtimeAnalyser
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Audio (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks: 212611
  Show dependency treegraph
 
Reported: 2020-10-05 10:47 PDT by Chris Dumez
Modified: 2020-10-05 15:04 PDT (History)
11 users (show)

See Also:


Attachments
Patch (14.08 KB, patch)
2020-10-05 10:50 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (14.80 KB, patch)
2020-10-05 11:56 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (56.89 KB, patch)
2020-10-05 14:10 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (57.15 KB, patch)
2020-10-05 14:17 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2020-10-05 10:47:38 PDT
Vectorize linear to decibels conversion in RealtimeAnalyser.
Comment 1 Chris Dumez 2020-10-05 10:50:29 PDT
Created attachment 410530 [details]
Patch
Comment 2 Chris Dumez 2020-10-05 11:56:07 PDT
Created attachment 410536 [details]
Patch
Comment 3 Darin Adler 2020-10-05 13:43:22 PDT
Comment on attachment 410536 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=410536&action=review

> Source/WebCore/Modules/webaudio/RealtimeAnalyser.cpp:190
> +    if (length > 0)

Is this if statement an important optimization? I would have done all of this in one line.

> Source/WebCore/platform/audio/VectorMath.cpp:755
> +    int n = framesToProcess;

Not OK to just put a size_t into an int, especially when there is no reason to.

Also not sure why the loop is written this way. Could use a for loop instead, I guess?

> Source/WebCore/platform/audio/VectorMath.h:56
> +void linearToDecibels(const float* sourceP, int sourceStride, float* destP, int destStride, size_t framesToProcess);

Can we do better on these argument names? Not sure sourceP is better than inputVector, for example. Looking at vDSP_vdbcon they seem to refer to these as input and output vector. Also they use the terminology "number of elements to process". I don’t think the argument should be named "frames to process" since it’s not frames, it’s a number.

Do we need to pass the stride values in? I understand that the underlying vector function takes a stride algorithm, but I am not sure we need that flexibility in our vector math wrapper interface.
Comment 4 Chris Dumez 2020-10-05 13:46:16 PDT
Comment on attachment 410536 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=410536&action=review

>> Source/WebCore/platform/audio/VectorMath.cpp:755
>> +    int n = framesToProcess;
> 
> Not OK to just put a size_t into an int, especially when there is no reason to.
> 
> Also not sure why the loop is written this way. Could use a for loop instead, I guess?

Ok. I was merely following the pattern in this file. I will fix all of them.

>> Source/WebCore/platform/audio/VectorMath.h:56
>> +void linearToDecibels(const float* sourceP, int sourceStride, float* destP, int destStride, size_t framesToProcess);
> 
> Can we do better on these argument names? Not sure sourceP is better than inputVector, for example. Looking at vDSP_vdbcon they seem to refer to these as input and output vector. Also they use the terminology "number of elements to process". I don’t think the argument should be named "frames to process" since it’s not frames, it’s a number.
> 
> Do we need to pass the stride values in? I understand that the underlying vector function takes a stride algorithm, but I am not sure we need that flexibility in our vector math wrapper interface.

Ok. I will look into improving our VectorMath API in a follow-up since your comments apply to all functions, not just the one I am adding.
Comment 5 Chris Dumez 2020-10-05 14:10:42 PDT
Created attachment 410556 [details]
Patch
Comment 6 Chris Dumez 2020-10-05 14:17:50 PDT
Created attachment 410558 [details]
Patch
Comment 7 EWS 2020-10-05 15:03:07 PDT
Committed r268006: <https://trac.webkit.org/changeset/268006>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 410558 [details].
Comment 8 Radar WebKit Bug Importer 2020-10-05 15:04:21 PDT
<rdar://problem/69972790>