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

Changeset 287854 in webkit


Ignore:
Timestamp:
Jan 10, 2022, 1:45:01 PM (5 years ago)
Author:
Chris Dumez
Message:

https://brianpeiris.github.io/spatial-audio-test/?ramped stops playing after a few seconds
https://bugs.webkit.org/show_bug.cgi?id=234979

Reviewed by Eric Carlson.

Source/WebCore:

In ConeEffect::gain(), due to precision issues and with certain panner node parameters, it was possible for
sourceToListener.dot(sourceOrientation) to return a value that is very slightly outside the [-1.0, 1.0]
range. We would then call acos() on the dot product and it would thus return NaN.

To addresss this, we now make sure the clamp the dot product to the expected range before calling acos().

I also made the following stylistic changes:

  • Drop unnecessary normalizedSourceOrientation local variable since the sourceOrientation paramter is not const
  • Add missing curly brackets in if conditions with more than one lines (due to comments)
  • Call rad2deg() for readability instead of duplicating its logic here

Test: webaudio/Panner/panner-cone-gain-nan.html

  • platform/audio/Cone.cpp:

(WebCore::ConeEffect::gain const):

LayoutTests:

Add layout test coverage.

  • webaudio/Panner/panner-cone-gain-nan-expected.txt: Added.
  • webaudio/Panner/panner-cone-gain-nan.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r287847 r287854  
     12022-01-10  Chris Dumez  <cdumez@apple.com>
     2
     3        https://brianpeiris.github.io/spatial-audio-test/?ramped stops playing after a few seconds
     4        https://bugs.webkit.org/show_bug.cgi?id=234979
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add layout test coverage.
     9
     10        * webaudio/Panner/panner-cone-gain-nan-expected.txt: Added.
     11        * webaudio/Panner/panner-cone-gain-nan.html: Added.
     12
    1132022-01-10  Cathie Chen  <cathiechen@igalia.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r287849 r287854  
     12022-01-10  Chris Dumez  <cdumez@apple.com>
     2
     3        https://brianpeiris.github.io/spatial-audio-test/?ramped stops playing after a few seconds
     4        https://bugs.webkit.org/show_bug.cgi?id=234979
     5
     6        Reviewed by Eric Carlson.
     7
     8        In ConeEffect::gain(), due to precision issues and with certain panner node parameters, it was possible for
     9        `sourceToListener.dot(sourceOrientation)` to return a value that is very slightly outside the [-1.0, 1.0]
     10        range. We would then call `acos()` on the dot product and it would thus return NaN.
     11
     12        To addresss this, we now make sure the clamp the dot product to the expected range before calling acos().
     13
     14        I also made the following stylistic changes:
     15        - Drop unnecessary normalizedSourceOrientation local variable since the sourceOrientation paramter is not const
     16        - Add missing curly brackets in if conditions with more than one lines (due to comments)
     17        - Call rad2deg() for readability instead of duplicating its logic here
     18
     19        Test: webaudio/Panner/panner-cone-gain-nan.html
     20
     21        * platform/audio/Cone.cpp:
     22        (WebCore::ConeEffect::gain const):
     23
    1242022-01-10  Wenson Hsieh  <wenson_hsieh@apple.com>
    225
  • trunk/Source/WebCore/platform/audio/Cone.cpp

    r283740 r287854  
    4747    sourceToListener.normalize();
    4848
    49     FloatPoint3D normalizedSourceOrientation = sourceOrientation;
    50     normalizedSourceOrientation.normalize();
     49    sourceOrientation.normalize();
     50
     51    // Due to precision issues, the dot product may be very slightly outside the range [-1.0, 1.0], which would
     52    // acos() to return NaN. For this reason, we have to make sure we clamp the dot product before calling acos().
     53    auto dotProduct = clampTo(sourceToListener.dot(sourceOrientation), -1.0, 1.0);
    5154
    5255    // Angle between the source orientation vector and the source-listener vector
    53     double dotProduct = sourceToListener.dot(normalizedSourceOrientation);
    54     double angle = 180.0 * acos(dotProduct) / piDouble;
     56    double angle = rad2deg(acos(dotProduct));
    5557    double absAngle = fabs(angle);
    5658
     
    6062    double gain = 1.0;
    6163
    62     if (absAngle <= absInnerAngle)
     64    if (absAngle <= absInnerAngle) {
    6365        // No attenuation
    6466        gain = 1.0;
    65     else if (absAngle >= absOuterAngle)
     67    } else if (absAngle >= absOuterAngle) {
    6668        // Max attenuation
    6769        gain = m_outerGain;
    68     else {
     70    } else {
    6971        // Between inner and outer cones
    7072        // inner -> outer, x goes from 0 -> 1
Note: See TracChangeset for help on using the changeset viewer.