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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!doctype html>
2 <html>
3 <head>
4 <title>Test WaveShaper Copies Curve Data</title>
5 <script src="../resources/testharness.js"></script>
6 <script src="../resources/testharnessreport.js"></script>
7 <script src="resources/audio-testing.js"></script>
8 </head>
9
10 <body>
11 <script>
12 // Sample rate and number of frames are fairly arbitrary. We need to
13 // render, however, at least 384 frames. 1024 is a nice small value.
14 var sampleRate = 16000;
15 var renderFrames = 1024;
16
17 var audit = Audit.createTaskRunner();
18
19 audit.defineTask("test copying", function (taskDone) {
20 // Two-channel context; channel 0 contains the test data and channel 1
21 // contains the expected result. Channel 1 has the normal WaveShaper
22 // output and channel 0 has the WaveShaper output with a modified curve.
23 var context = new OfflineAudioContext(2, renderFrames, sampleRate);
24
25 // Just use a default oscillator as the source. Doesn't really matter
26 // what we use.
27 var src = context.createOscillator();
28 src.type = "sawtooth";
29
30 // Create the wave shapers: ws0 is the test shaper, and ws1 is the
31 // reference wave shaper.
32 var ws0 = context.createWaveShaper();
33 var ws1 = context.createWaveShaper();
34
35 // Wave shaper curves. Doesn't really matter what we use as long as it
36 // modifies the input in some way. Thus, keep it simple and just invert
37 // the input.
38 var desiredCurve = [1, 0, -1];
39 var curve0 = Float32Array.from(desiredCurve);
40 var curve1 = Float32Array.from(desiredCurve);
41
42 ws0.curve = curve0;
43 ws1.curve = curve1;
44
45 var merger = context.createChannelMerger(2);
46
47 // Connect the graph
48 src.connect(ws0);
49 src.connect(ws1);
50
51 ws0.connect(merger, 0, 0);
52 ws1.connect(merger, 0, 1);
53
54 merger.connect(context.destination);
55
56 // Let the context run for a bit and then modify the curve for ws0.
57 // Doesn't really matter what we modify the curve to as long as it's
58 // different.
59 context.suspend(256 / context.sampleRate)
60 .then(function () {
61 curve0[0] = -0.5;
62 curve0[1] = 0.125;
63 curve0[2] = 0.75;
64 })
65 .then(context.resume.bind(context));
66
67 src.start();
68
69 context.startRendering().then(function (renderedBuffer) {
70 var actual = renderedBuffer.getChannelData(0);
71 var expected = renderedBuffer.getChannelData(1);
72
73 // Modifying the wave shaper curve should not modify the output so the
74 // outputs from the two wave shaper nodes should be exactly identical.
75 var success = Should("WaveShaper with modified curve", actual)
76 .beEqualToArray(expected);
77
78 Should("Summary: ", success).summarize(
79 "Output correctly did not change with modified WaveShaper curve.",
80 "Output incorrectly changed due to modified WaveShaper curve.");
81 }).then(taskDone);
82 });
83
84 audit.runTasks();
85 </script>
86 </body>
87 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698