[Webkit-unassigned] [Bug 129333] New: WaveShaperNode interpolation does not match specification

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Feb 25 13:46:02 PST 2014


           Summary: WaveShaperNode interpolation does not match
           Product: WebKit
           Version: 528+ (Nightly build)
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: Web Audio
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: webaudio.at.pendragon at gmail.com
                CC: crogers at google.com

Created an attachment (id=225181)
 --> (https://bugs.webkit.org/attachment.cgi?id=225181&action=review)
HTML page that demonstates the bug

The interpolation for the Web Audio WaveShaperNode does not work properly.

I have created the follow JavaScript to demonstrate the 2 problems:
var c=new webkitOfflineAudioContext(1, 23, 48000);

//Create input values between -1.1 and + 1.1.
var b=c.createBuffer(1, 23, 48000);
var d=b.getChannelData(0);
for (var i=0; i<23; i++){ d[i]=(i*.1)-1.1; }
var src=c.createBufferSource();

//Simple wave-shaper. It should map -1 to 0, 0 to 1, and +1 to 0 - and interpolate all
//points between.
var ws=c.createWaveShaper();
var curve=new Float32Array(3);

  var outputData=ev.renderedBuffer.getChannelData(0);
  var msgItems=[];
  for (var i=0; i<23; i++){
    msgItems.push("Input value " + d[i].toFixed(4) +
      " => output value " + outputData[i].toFixed(4));

The specification says "Any sample value less than -1 will correspond to the first value in the curve array."
* An input of -1.1 returns a value -0.1500, it should return 0.0000

The specification says "Each input sample within this range will index into the shaping curve
with a signal level of zero corresponding to the center value of the curve array."
* An input of 0 returns a value of 0.5000, it should return 1.0000
* An input of 0.4 returns a value of 0.0000, it should return 0.8000

The problem appears to be in WaveShaperDSPKernel.cpp - I think it should be changed to something like:

double virtualIndex = 0.5 * (input + 1) * curveLength;
double output;
if (virtualIndex <= -1) {
  output = curve[0];
} else if (virtualIndex >= curve[curveLength-1]) {
  output = curve[curveLength-1];
} else {
  var index1 = (int)virtualIndex;
  var value1 = curve[index1];
  var value2 = curve[index1+1];
  var interpolationFactor = virtualIndex - index1;
  output = (1.0 - interpolationFactor) * value1 + interpolationFactor * value2;

The current test HTML page only tests input values that fall between -1 and +1 - and the
error from the mid-point and end-point of the curve are disguised by the large number of
elements in the curve array.

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