Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Unified Diff: third_party/WebKit/LayoutTests/webaudio/waveshaper-copy-curve.html

Issue 2223613002: WaveShaperNode should copy its curve. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/webaudio/waveshaper-copy-curve.html
diff --git a/third_party/WebKit/LayoutTests/webaudio/waveshaper-copy-curve.html b/third_party/WebKit/LayoutTests/webaudio/waveshaper-copy-curve.html
new file mode 100644
index 0000000000000000000000000000000000000000..5ebed9d009e9ef4cb01e0452a314d542de5a1e5d
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/webaudio/waveshaper-copy-curve.html
@@ -0,0 +1,87 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Test WaveShaper Copies Curve Data</title>
+ <script src="../resources/testharness.js"></script>
+ <script src="../resources/testharnessreport.js"></script>
+ <script src="resources/audio-testing.js"></script>
+ </head>
+
+ <body>
+ <script>
+ // Sample rate and number of frames are fairly arbitrary. We need to
+ // render, however, at least 384 frames. 1024 is a nice small value.
+ var sampleRate = 16000;
+ var renderFrames = 1024;
+
+ var audit = Audit.createTaskRunner();
+
+ audit.defineTask("test copying", function (taskDone) {
+ // Two-channel context; channel 0 contains the test data and channel 1
+ // contains the expected result. Channel 1 has the normal WaveShaper
+ // output and channel 0 has the WaveShaper output with a modified curve.
+ var context = new OfflineAudioContext(2, renderFrames, sampleRate);
+
+ // Just use a default oscillator as the source. Doesn't really matter
+ // what we use.
+ var src = context.createOscillator();
+ src.type = "sawtooth";
+
+ // Create the wave shapers: ws0 is the test shaper, and ws1 is the
+ // reference wave shaper.
+ var ws0 = context.createWaveShaper();
+ var ws1 = context.createWaveShaper();
+
+ // Wave shaper curves. Doesn't really matter what we use as long as it
+ // modifies the input in some way. Thus, keep it simple and just invert
+ // the input.
+ var desiredCurve = [1, 0, -1];
+ var curve0 = Float32Array.from(desiredCurve);
+ var curve1 = Float32Array.from(desiredCurve);
+
+ ws0.curve = curve0;
+ ws1.curve = curve1;
+
+ var merger = context.createChannelMerger(2);
+
+ // Connect the graph
+ src.connect(ws0);
+ src.connect(ws1);
+
+ ws0.connect(merger, 0, 0);
+ ws1.connect(merger, 0, 1);
+
+ merger.connect(context.destination);
+
+ // Let the context run for a bit and then modify the curve for ws0.
+ // Doesn't really matter what we modify the curve to as long as it's
+ // different.
+ context.suspend(256 / context.sampleRate)
+ .then(function () {
+ curve0[0] = -0.5;
+ curve0[1] = 0.125;
+ curve0[2] = 0.75;
+ })
+ .then(context.resume.bind(context));
+
+ src.start();
+
+ context.startRendering().then(function (renderedBuffer) {
+ var actual = renderedBuffer.getChannelData(0);
+ var expected = renderedBuffer.getChannelData(1);
+
+ // Modifying the wave shaper curve should not modify the output so the
+ // outputs from the two wave shaper nodes should be exactly identical.
+ var success = Should("WaveShaper with modified curve", actual)
+ .beEqualToArray(expected);
+
+ Should("Summary: ", success).summarize(
+ "Output correctly did not change with modified WaveShaper curve.",
+ "Output incorrectly changed due to modified WaveShaper curve.");
+ }).then(taskDone);
+ });
+
+ audit.runTasks();
+ </script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698