[Webkit-unassigned] [Bug 74592] Optimize AudioBufferSourceNode process by avoiding interpolation when pitchRate==1

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Dec 19 16:21:14 PST 2011


https://bugs.webkit.org/show_bug.cgi?id=74592





--- Comment #6 from Chris Rogers <crogers at google.com>  2011-12-19 16:21:14 PST ---
(From update of attachment 119391)
View in context: https://bugs.webkit.org/attachment.cgi?id=119391&action=review

Hi James, it'll be good to get this optimization.  I'm sure we'll hit this case quite a bit (maybe majority of the time).

> Source/WebCore/webaudio/AudioBufferSourceNode.cpp:254
> +    bool needInterpolation = (pitchRate != 1);

The entire codeblock within "if (!needInterpolation) {" can be significantly simplified I believe.

In the current patch, there are 4 separate memcpy() sections (line 261, 266, 278, 286).  It should be possible to reduce this down to a single memcpy() section with the appropriate use of a "while()" loop, and by getting rid of the "for()" loop:

                unsigned rounds = framesToProcess / deltaFrames;
                for (unsigned k = 0; k < rounds; ++k) {

For example, you could use a "framesRemaining" variable which is initialized to "framesToProcess":

int framesRemaining = framesToProcess;
while (framesRemaining > ) {
    int framesThisTime = ....;
    memcpy() stuff...
    framesRemaining -= framesThisTime;
}

You'll have to add appropriate checking for end of buffer and looping, but I'm quite sure the whole codeblock can be a lot simpler than it currently is...

>>> Source/WebCore/webaudio/AudioBufferSourceNode.cpp:255
>>> +    if (!needInterpolation) {
>> 
>> needInterpolation isn't used anywhere else, so remove it, and change to if (pitchRate == 1).
> 
> got it. thanks.

We can't *just* check (pitchRate == 1).  We also need to check that virtualReadIndex is an integer.  I think in the normal case where this optimization will be used, we're talking about simply loading up a buffer at the default playback rate (of 1) and playing it with noteOn().  In this case virtualReadIndex will be an integer.  But, if we're in the middle of fiddling with the playbackRate (tweaking it with a slider to change pitch), then we could hit a case where playback rate is (temporarily) 1, but the virtualReadIndex is at a sub-sample position.  We don't want to do a simple memcpy then.

So please check both that (pitchRate == 1 ) and that virtualReadIndex is an integer (has no fractional portion).

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list