⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 267453 in webkit


Ignore:
Timestamp:
Sep 22, 2020, 6:49:31 PM (6 years ago)
Author:
Chris Dumez
Message:

Slightly improve AudioBufferSourceNode resampling
https://bugs.webkit.org/show_bug.cgi?id=216859

Reviewed by Eric Carlson.

LayoutTests/imported/w3c:

Rebaseline WPT tests that are now passing.

  • web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/buffer-resampling-expected.txt:
  • web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/sub-sample-buffer-stitching-expected.txt:

Source/WebCore:

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.

This is a merge of the following Blink change by Raymond Toy:

No new tests, rebaselined existing tests.

  • Modules/webaudio/AudioBufferSourceNode.cpp:

(WebCore::AudioBufferSourceNode::renderFromBuffer):

LayoutTests:

  • webaudio/AudioBufferSource/audiobuffersource-detune-modulation-expected.txt:
  • webaudio/AudioBufferSource/audiobuffersource-playbackrate-modulation-expected.txt:
  • webaudio/gain-expected.wav:

Rebaseline tests that have slightly different output.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r267444 r267453  
     12020-09-22  Chris Dumez  <cdumez@apple.com>
     2
     3        Slightly improve AudioBufferSourceNode resampling
     4        https://bugs.webkit.org/show_bug.cgi?id=216859
     5
     6        Reviewed by Eric Carlson.
     7
     8        * webaudio/AudioBufferSource/audiobuffersource-detune-modulation-expected.txt:
     9        * webaudio/AudioBufferSource/audiobuffersource-playbackrate-modulation-expected.txt:
     10        * webaudio/gain-expected.wav:
     11        Rebaseline tests that have slightly different output.
     12
    1132020-09-22  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/LayoutTests/TestExpectations

    r267413 r267453  
    327327imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/k-rate-stereo-panner.html [ Pass Failure ]
    328328
     329# This test is passing but the printed SNR value differs from machine to machine.
     330imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/sub-sample-buffer-stitching.html [ Pass Failure ]
     331
    329332# Values in FAIL lines differ from machine to machine, we should be able to unskip them once they pass.
    330 imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/buffer-resampling.html [ Pass Failure ]
    331 imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/sub-sample-buffer-stitching.html [ Pass Failure ]
    332333webaudio/AudioBufferSource/audiobuffersource-detune-modulation.html [ Pass Failure ]
    333334webaudio/AudioBufferSource/audiobuffersource-playbackrate-modulation.html [ Pass Failure ]
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r267417 r267453  
     12020-09-22  Chris Dumez  <cdumez@apple.com>
     2
     3        Slightly improve AudioBufferSourceNode resampling
     4        https://bugs.webkit.org/show_bug.cgi?id=216859
     5
     6        Reviewed by Eric Carlson.
     7
     8        Rebaseline WPT tests that are now passing.
     9
     10        * web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/buffer-resampling-expected.txt:
     11        * web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/sub-sample-buffer-stitching-expected.txt:
     12
    1132020-09-22  Sam Sneddon  <gsnedders@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/buffer-resampling-expected.txt

    r266627 r267453  
    44PASS Audit report
    55PASS > [interpolate] Interpolation of AudioBuffers to context sample rate
    6 FAIL X Interpolated sine wave does not equal [0,0.057564035058021545,0.1149371787905693,0.17192906141281128,0.22835084795951843,0.2840152382850647,0.3387378752231598,0.39233696460723877,0.4446350038051605,0.4954586327075958,0.5446387529373169,0.5920131206512451,0.6374238133430481,0.6807207465171814,0.7217600345611572,0.7604058980941772...] with an element-wise tolerance of {"absoluteThreshold":0.090348,"relativeThreshold":0}.
    7         Index   Actual                  Expected                AbsError                RelError                Test threshold
    8         [176]   -5.6208336353302002e-1  -6.5342026948928833e-1  9.1336905956268311e-2   1.3978278639512823e-1   9.0347999999999998e-2
    9         [177]   -5.6208336353302002e-1  -6.9591242074966431e-1  1.3382905721664429e-1   1.9230732664963551e-1   9.0347999999999998e-2
    10         [178]   -5.6208336353302002e-1  -7.3609656095504761e-1  1.7401319742202759e-1   2.3639995980453213e-1   9.0347999999999998e-2
    11         [179]   -5.6208336353302002e-1  -7.7383983135223389e-1  2.1175646781921387e-1   2.7364379454231952e-1   9.0347999999999998e-2
    12         Max AbsError of 2.1175646781921387e-1 at index of 179.
    13         Max RelError of 2.7364379454231952e-1 at index of 179.
    14  assert_true: expected true got false
    15 FAIL X SNR (32.76 dB) is not greater than or equal to 37.17. Got 32.76242434165858. assert_true: expected true got false
    16 FAIL < [interpolate] 2 out of 2 assertions were failed. assert_true: expected true got false
    17 FAIL # AUDIT TASK RUNNER FINISHED: 1 out of 1 tasks were failed. assert_true: expected true got false
     6PASS   Interpolated sine wave equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0.090348,"relativeThreshold":0}.
     7PASS   SNR (37.18 dB) is greater than or equal to 37.17.
     8PASS < [interpolate] All assertions passed. (total 2 assertions)
     9PASS # AUDIT TASK RUNNER FINISHED: 1 tasks ran successfully.
    1810
  • trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/sub-sample-buffer-stitching-expected.txt

    r267167 r267453  
    1111PASS > [buffer-stitching-2] Subsample buffer stitching, different rates
    1212PASS   Test 2: context.sampleRate is equal to 44100.
    13 FAIL X Stitched sine-wave buffers at sample rate 43800 does not equal [0,0.06264830380678177,0.12505052983760834,0.1869613528251648,0.2481377273797989,0.308339387178421,0.36732959747314453,0.4248766303062439,0.48075437545776367,0.53474360704422,0.5866317749023438,0.6362154483795166,0.6832994818687439,0.7276992797851562,0.7692402005195618,0.8077590465545654...] with an element-wise tolerance of {"absoluteThreshold":0.0038986,"relativeThreshold":0}.
    14         Index   Actual                  Expected                AbsError                RelError                Test threshold
    15         [30]    9.6648049354553223e-1   9.5236855745315552e-1   1.4111936092376709e-2   1.4817725744868301e-2   3.8985999999999999e-3
    16         [60]    -5.5004155635833740e-1  -5.8084774017333984e-1  3.0806183815002441e-2   5.3036590631839402e-2   3.8985999999999999e-3
    17         [90]    -6.1754375696182251e-1  -5.9811061620712280e-1  1.9433140754699707e-2   3.2490880830595564e-2   3.8985999999999999e-3
    18         [151]   2.0081890746951103e-2   -4.1306052356958389e-2  6.1387943103909492e-2   1.4861730812087184e+0   3.8985999999999999e-3
    19         [181]   -9.5454013347625732e-1  -9.3895959854125977e-1  1.5580534934997559e-2   1.6593402910202976e-2   3.8985999999999999e-3
    20         ...and 1222 more errors.
    21         Max AbsError of 6.3063371824682690e-2 at index of 6615.
    22         [6615]  -6.3076853752136230e-2  -1.3481927453540266e-5  6.3063371824682690e-2   4.6776228430247684e+3   3.8985999999999999e-3
    23         Max RelError of 4.6776228430247684e+3 at index of 6615.
    24         [6615]  -6.3076853752136230e-2  -1.3481927453540266e-5  6.3063371824682690e-2   4.6776228430247684e+3   3.8985999999999999e-3
    25  assert_true: expected true got false
    26 FAIL X SNR (43.58852186686384 dB) is not greater than or equal to 65.737. Got 43.58852186686384. assert_true: expected true got false
    27 FAIL < [buffer-stitching-2] 2 out of 3 assertions were failed. assert_true: expected true got false
    28 FAIL # AUDIT TASK RUNNER FINISHED: 1 out of 2 tasks were failed. assert_true: expected true got false
     13PASS   Stitched sine-wave buffers at sample rate 43800 equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0.0038986,"relativeThreshold":0}.
     14PASS   SNR (65.73793928980352 dB) is greater than or equal to 65.737.
     15PASS < [buffer-stitching-2] All assertions passed. (total 3 assertions)
     16PASS # AUDIT TASK RUNNER FINISHED: 2 tasks ran successfully.
    2917
  • trunk/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-detune-modulation-expected.txt

    r267245 r267453  
    77PASS < [load-reference] All assertions passed. (total 0 assertions)
    88PASS > [generate-verify] 
    9 FAIL X SNR is not greater than or equal to 93.32. Got 90.27890412800858. assert_true: expected true got false
     9FAIL X SNR is not greater than or equal to 93.32. Got 90.27890412768754. assert_true: expected true got false
    1010PASS   : Maximum difference (in ulp units (16-bits)) is less than or equal to 1.0352.
    1111PASS   : Number of differences between results is less than or equal to 0.
  • trunk/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-playbackrate-modulation-expected.txt

    r267245 r267453  
    88PASS < [load-reference] All assertions passed. (total 1 assertions)
    99PASS > [generate-verify] 
    10 FAIL X SNR is not greater than or equal to 93.274. Got 90.24757942295886. assert_true: expected true got false
     10FAIL X SNR is not greater than or equal to 93.274. Got 90.24757942510593. assert_true: expected true got false
    1111PASS   Verify: Maximum difference (in ulp units (16-bits)) is less than or equal to 1.0519.
    1212PASS   Verify: Number of differences between results is less than or equal to 0.
  • trunk/Source/WebCore/ChangeLog

    r267449 r267453  
     12020-09-22  Chris Dumez  <cdumez@apple.com>
     2
     3        Slightly improve AudioBufferSourceNode resampling
     4        https://bugs.webkit.org/show_bug.cgi?id=216859
     5
     6        Reviewed by Eric Carlson.
     7
     8        Slightly improve AudioBufferSourceNode resampling. Use simple linear extrapolation
     9        to resample the data when we reach the end of the buffer. Previously, the last
     10        sample would just be repeated enough times.
     11
     12        This is a merge of the following Blink change by Raymond Toy:
     13        - https://chromium-review.googlesource.com/c/chromium/src/+/1211910/
     14
     15        No new tests, rebaselined existing tests.
     16
     17        * Modules/webaudio/AudioBufferSourceNode.cpp:
     18        (WebCore::AudioBufferSourceNode::renderFromBuffer):
     19
    1202020-09-22  Sam Weinig  <weinig@apple.com>
    221
  • trunk/Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp

    r267443 r267453  
    5353const double MaxRate = 1024;
    5454
     55static float computeSampleUsingLinearInterpolation(const float* source, unsigned readIndex, unsigned readIndex2, float interpolationFactor)
     56{
     57    if (readIndex == readIndex2 && readIndex >= 1) {
     58        // We're at the end of the buffer, so just linearly extrapolate from the last two samples.
     59        float sample1 = source[readIndex - 1];
     60        float sample2 = source[readIndex];
     61        return sample2 + (sample2 - sample1) * interpolationFactor;
     62    }
     63    float sample1 = source[readIndex];
     64    float sample2 = source[readIndex2];
     65    return sample1 + interpolationFactor * (sample2 - sample1);
     66}
     67
    5568ExceptionOr<Ref<AudioBufferSourceNode>> AudioBufferSourceNode::create(BaseAudioContext& context, AudioBufferSourceOptions&& options)
    5669{
     
    340353        while (framesToProcess--) {
    341354            unsigned readIndex = static_cast<unsigned>(floorf(virtualReadIndex));
    342             double interpolationFactor = virtualReadIndex - readIndex;
     355            float interpolationFactor = virtualReadIndex - readIndex;
    343356
    344357            unsigned readIndex2 = readIndex + 1;
    345358            if (readIndex2 >= maxFrame)
    346                 readIndex2 = loop() ? minFrame : maxFrame - 1;
     359                readIndex2 = loop() ? minFrame : readIndex;
    347360
    348361            // Linear interpolation.
     
    351364                const float* source = sourceChannels[i];
    352365
    353                 double sample1 = source[readIndex];
    354                 double sample2 = source[readIndex2];
    355                 double sample = (1.0 - interpolationFactor) * sample1 + interpolationFactor * sample2;
    356 
    357                 destination[writeIndex] = narrowPrecisionToFloat(sample);
     366                destination[writeIndex] = computeSampleUsingLinearInterpolation(source, readIndex, readIndex2, interpolationFactor);
    358367            }
    359368
     
    372381        while (framesToProcess--) {
    373382            unsigned readIndex = static_cast<unsigned>(virtualReadIndex);
    374             double interpolationFactor = virtualReadIndex - readIndex;
     383            float interpolationFactor = virtualReadIndex - readIndex;
    375384
    376385            // For linear interpolation we need the next sample-frame too.
     
    394403                const float* source = sourceChannels[i];
    395404
    396                 double sample1 = source[readIndex];
    397                 double sample2 = source[readIndex2];
    398                 double sample = (1.0 - interpolationFactor) * sample1 + interpolationFactor * sample2;
    399 
    400                 destination[writeIndex] = narrowPrecisionToFloat(sample);
     405                destination[writeIndex] = computeSampleUsingLinearInterpolation(source, readIndex, readIndex2, interpolationFactor);
    401406            }
    402407            writeIndex++;
Note: See TracChangeset for help on using the changeset viewer.