Bug 216859

Summary: Slightly improve AudioBufferSourceNode resampling
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: Web AudioAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, eric.carlson, ews-watchlist, ggaren, glenn, jer.noble, philipj, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 212611    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch none

Description Chris Dumez 2020-09-22 16:54:10 PDT
Slightly improve AudioBufferSourceNode resampling. Use simple linear extrapolation to resample the data when we reach the end of the buffer. Previously, the last sample would just be repeated enough times.
Comment 1 Chris Dumez 2020-09-22 16:58:56 PDT
Created attachment 409423 [details]
Patch
Comment 2 Chris Dumez 2020-09-22 17:01:44 PDT
Created attachment 409424 [details]
Patch
Comment 3 Eric Carlson 2020-09-22 17:03:35 PDT
Comment on attachment 409424 [details]
Patch

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

> Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp:416
> +                float sample;
> +                if (readIndex == readIndex2 && readIndex >= 1) {
> +                    // We're at the end of the buffer, so just linearly extrapolate from the last two samples.
> +                    float sample1 = source[readIndex - 1];
> +                    float sample2 = source[readIndex];
> +                    sample = sample2 + (sample2 - sample1) * interpolationFactor;
> +                } else {
> +                    float sample1 = source[readIndex];
> +                    float sample2 = source[readIndex2];
> +                    sample = sample1 + interpolationFactor * (sample2 - sample1);
> +                }
>  
> -                destination[writeIndex] = narrowPrecisionToFloat(sample);
> +                destination[writeIndex] = sample;

It looks like this is an identical copy of the code above. Can it be moved to a shared function?
Comment 4 Chris Dumez 2020-09-22 17:13:26 PDT
Created attachment 409428 [details]
Patch
Comment 5 Chris Dumez 2020-09-22 17:56:57 PDT
Created attachment 409432 [details]
Patch
Comment 6 EWS 2020-09-22 18:49:36 PDT
Committed r267453: <https://trac.webkit.org/changeset/267453>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 409432 [details].
Comment 7 Radar WebKit Bug Importer 2020-09-22 18:50:21 PDT
<rdar://problem/69406153>