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