| 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/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> |
| OLD | NEW |