Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../resources/testharness.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> | 5 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="../resources/audit-util.js"></script> | 6 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> | 7 <script src="../resources/audio-testing.js"></script> |
| 8 <title>Test OscillatorNode with Negative Frequency</title> | 8 <title>Test OscillatorNode with Negative Frequency</title> |
| 9 </head> | 9 </head> |
| 10 | 10 |
| 11 <body> | 11 <body> |
| 12 <script> | 12 <script> |
| 13 // Some arbitrary sample rate for the offline context. | 13 // Some arbitrary sample rate for the offline context. But it MUST be |
| 14 var sampleRate = 48000; | 14 // at least twice the oscillator frequency that we're using for the |
| 15 var renderDuration = 1; | 15 // test. (Currently 440 Hz.) |
| 16 var sampleRate = 16000; | |
| 17 // A failyr arbitrary duration that should have at least 1-2 sample | |
|
hongchan
2017/03/16 21:46:09
Can we add one empty line before l.17?
Raymond Toy
2017/03/16 22:13:12
Done. And fixed the typo. :-)
| |
| 18 // periods of the oscillator (at a nominal 440 Hz). | |
| 19 var renderDuration = 0.1; | |
| 16 var renderFrames = renderDuration * sampleRate; | 20 var renderFrames = renderDuration * sampleRate; |
| 17 | 21 |
| 18 var audit = Audit.createTaskRunner(); | 22 var audit = Audit.createTaskRunner(); |
| 19 | 23 |
| 20 audit.defineTask("sine", function (done) { | 24 audit.defineTask("sine", function (done) { |
| 21 runTest({ | 25 runTest({ |
| 22 message: "Sum of positive and negative frequency sine oscillators", | 26 message: "Sum of positive and negative frequency sine oscillators", |
| 23 type: "sine", | 27 type: "sine", |
| 24 threshold: 4.7684e-7 | 28 threshold: 3.5763e-7 |
| 25 }).then(done); | 29 }).then(done); |
| 26 }); | 30 }); |
| 27 | 31 |
| 28 audit.defineTask("square", function (done) { | 32 audit.defineTask("square", function (done) { |
| 29 runTest({ | 33 runTest({ |
| 30 message: "Sum of positive and negative frequency square oscillators", | 34 message: "Sum of positive and negative frequency square oscillators", |
| 31 type: "square", | 35 type: "square", |
| 32 threshold: 4.4108e-6 | 36 threshold: 1.4753e-6 |
| 33 }).then(done); | 37 }).then(done); |
| 34 }); | 38 }); |
| 35 | 39 |
| 36 audit.defineTask("sawtooth", function (done) { | 40 audit.defineTask("sawtooth", function (done) { |
| 37 runTest({ | 41 runTest({ |
| 38 message: "Sum of positive and negative frequency sawtooth oscillators" , | 42 message: "Sum of positive and negative frequency sawtooth oscillators" , |
| 39 type: "sawtooth", | 43 type: "sawtooth", |
| 40 threshold: 4.3735e-6 | 44 threshold: 1.4753e-6 |
| 41 }).then(done); | 45 }).then(done); |
| 42 }); | 46 }); |
| 43 | 47 |
| 44 audit.defineTask("triangle", function (done) { | 48 audit.defineTask("triangle", function (done) { |
| 45 runTest({ | 49 runTest({ |
| 46 message: "Sum of positive and negative frequency triangle oscillators" , | 50 message: "Sum of positive and negative frequency triangle oscillators" , |
| 47 type: "triangle", | 51 type: "triangle", |
| 48 threshold: 3.5763e-7 | 52 threshold: 2.9803e-7 |
| 49 }).then(done); | 53 }).then(done); |
| 50 }); | 54 }); |
| 51 | 55 |
| 52 audit.defineTask("auto-sawtooth", function (done) { | 56 audit.defineTask("auto-sawtooth", function (done) { |
| 53 runTest({ | 57 runTest({ |
| 54 message: "Sum of positive and negative frequency-ramped sawtooth oscil lators", | 58 message: "Sum of positive and negative frequency-ramped sawtooth oscil lators", |
| 55 type: "sawtooth", | 59 type: "sawtooth", |
| 56 automation: { | 60 automation: { |
| 57 type: "linearRampToValueAtTime", | 61 type: "linearRampToValueAtTime", |
| 58 startTime: 0, | 62 startTime: 0, |
| 59 endTime: renderDuration / 2, | 63 endTime: renderDuration / 2, |
| 60 startFrequency: 440, | 64 startFrequency: 440, |
| 61 endFrequency: sampleRate / 4 | 65 endFrequency: sampleRate / 4 |
| 62 }, | 66 }, |
| 63 threshold: 4.1202e-6 | 67 threshold: 1.2070e-6 |
| 64 }).then(done); | 68 }).then(done); |
| 65 }); | 69 }); |
| 66 | 70 |
| 67 audit.defineTask("periodic-wave", function (done) { | 71 audit.defineTask("periodic-wave", function (done) { |
| 68 // Test negative frequencies for a custom oscillator. Two channels are | 72 // Test negative frequencies for a custom oscillator. Two channels are |
| 69 // needed for the context; one for the expected result, and one for the | 73 // needed for the context; one for the expected result, and one for the |
| 70 // actual, as explained below. | 74 // actual, as explained below. |
| 71 var context = new OfflineAudioContext(2, renderFrames, sampleRate); | 75 var context = new OfflineAudioContext(2, renderFrames, sampleRate); |
| 72 | 76 |
| 73 var oscPositive = context.createOscillator(); | 77 var oscPositive = context.createOscillator(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 oscNegative.start(); | 135 oscNegative.start(); |
| 132 | 136 |
| 133 context.startRendering().then(function (buffer) { | 137 context.startRendering().then(function (buffer) { |
| 134 var expected = buffer.getChannelData(0); | 138 var expected = buffer.getChannelData(0); |
| 135 var actual = buffer.getChannelData(1); | 139 var actual = buffer.getChannelData(1); |
| 136 | 140 |
| 137 Should("Sum of positive and negative frequency custom oscillators", | 141 Should("Sum of positive and negative frequency custom oscillators", |
| 138 actual, { | 142 actual, { |
| 139 precision: 6 | 143 precision: 6 |
| 140 }) | 144 }) |
| 141 .beCloseToArray(expected, 4.7684e-7); | 145 .beCloseToArray(expected, 3.5763e-7); |
| 142 }).then(done); | 146 }).then(done); |
| 143 }); | 147 }); |
| 144 | 148 |
| 145 audit.runTasks(); | 149 audit.runTasks(); |
| 146 | 150 |
| 147 function runTest(options) { | 151 function runTest(options) { |
| 148 // To test if negative frequencies work, create two oscillators. One | 152 // To test if negative frequencies work, create two oscillators. One |
| 149 // has a positive frequency and the other has a negative frequency. | 153 // has a positive frequency and the other has a negative frequency. |
| 150 // Sum the oscillator outputs; the output should be zero because all of | 154 // Sum the oscillator outputs; the output should be zero because all of |
| 151 // the builtin oscillator types are odd functions of frequency. | 155 // the builtin oscillator types are odd functions of frequency. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 181 var zero = new Float32Array(result.length); | 185 var zero = new Float32Array(result.length); |
| 182 zero.fill(0); | 186 zero.fill(0); |
| 183 Should(options.message, result, { | 187 Should(options.message, result, { |
| 184 verbose: true | 188 verbose: true |
| 185 }).beCloseToArray(zero, options.threshold || 0); | 189 }).beCloseToArray(zero, options.threshold || 0); |
| 186 }); | 190 }); |
| 187 } | 191 } |
| 188 </script> | 192 </script> |
| 189 </body> | 193 </body> |
| 190 </html> | 194 </html> |
| OLD | NEW |