| 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 |
| 18 // A fairly arbitrary duration that should have at least 1-2 sample |
| 19 // periods of the oscillator (at a nominal 440 Hz). |
| 20 var renderDuration = 0.1; |
| 16 var renderFrames = renderDuration * sampleRate; | 21 var renderFrames = renderDuration * sampleRate; |
| 17 | 22 |
| 18 var audit = Audit.createTaskRunner(); | 23 var audit = Audit.createTaskRunner(); |
| 19 | 24 |
| 20 audit.defineTask("sine", function (done) { | 25 audit.defineTask("sine", function (done) { |
| 21 runTest({ | 26 runTest({ |
| 22 message: "Sum of positive and negative frequency sine oscillators", | 27 message: "Sum of positive and negative frequency sine oscillators", |
| 23 type: "sine", | 28 type: "sine", |
| 24 threshold: 4.7684e-7 | 29 threshold: 3.5763e-7 |
| 25 }).then(done); | 30 }).then(done); |
| 26 }); | 31 }); |
| 27 | 32 |
| 28 audit.defineTask("square", function (done) { | 33 audit.defineTask("square", function (done) { |
| 29 runTest({ | 34 runTest({ |
| 30 message: "Sum of positive and negative frequency square oscillators", | 35 message: "Sum of positive and negative frequency square oscillators", |
| 31 type: "square", | 36 type: "square", |
| 32 threshold: 4.4108e-6 | 37 threshold: 1.4753e-6 |
| 33 }).then(done); | 38 }).then(done); |
| 34 }); | 39 }); |
| 35 | 40 |
| 36 audit.defineTask("sawtooth", function (done) { | 41 audit.defineTask("sawtooth", function (done) { |
| 37 runTest({ | 42 runTest({ |
| 38 message: "Sum of positive and negative frequency sawtooth oscillators"
, | 43 message: "Sum of positive and negative frequency sawtooth oscillators"
, |
| 39 type: "sawtooth", | 44 type: "sawtooth", |
| 40 threshold: 4.3735e-6 | 45 threshold: 1.4753e-6 |
| 41 }).then(done); | 46 }).then(done); |
| 42 }); | 47 }); |
| 43 | 48 |
| 44 audit.defineTask("triangle", function (done) { | 49 audit.defineTask("triangle", function (done) { |
| 45 runTest({ | 50 runTest({ |
| 46 message: "Sum of positive and negative frequency triangle oscillators"
, | 51 message: "Sum of positive and negative frequency triangle oscillators"
, |
| 47 type: "triangle", | 52 type: "triangle", |
| 48 threshold: 3.5763e-7 | 53 threshold: 2.9803e-7 |
| 49 }).then(done); | 54 }).then(done); |
| 50 }); | 55 }); |
| 51 | 56 |
| 52 audit.defineTask("auto-sawtooth", function (done) { | 57 audit.defineTask("auto-sawtooth", function (done) { |
| 53 runTest({ | 58 runTest({ |
| 54 message: "Sum of positive and negative frequency-ramped sawtooth oscil
lators", | 59 message: "Sum of positive and negative frequency-ramped sawtooth oscil
lators", |
| 55 type: "sawtooth", | 60 type: "sawtooth", |
| 56 automation: { | 61 automation: { |
| 57 type: "linearRampToValueAtTime", | 62 type: "linearRampToValueAtTime", |
| 58 startTime: 0, | 63 startTime: 0, |
| 59 endTime: renderDuration / 2, | 64 endTime: renderDuration / 2, |
| 60 startFrequency: 440, | 65 startFrequency: 440, |
| 61 endFrequency: sampleRate / 4 | 66 endFrequency: sampleRate / 4 |
| 62 }, | 67 }, |
| 63 threshold: 4.1202e-6 | 68 threshold: 1.2368e-6 |
| 64 }).then(done); | 69 }).then(done); |
| 65 }); | 70 }); |
| 66 | 71 |
| 67 audit.defineTask("periodic-wave", function (done) { | 72 audit.defineTask("periodic-wave", function (done) { |
| 68 // Test negative frequencies for a custom oscillator. Two channels are | 73 // Test negative frequencies for a custom oscillator. Two channels are |
| 69 // needed for the context; one for the expected result, and one for the | 74 // needed for the context; one for the expected result, and one for the |
| 70 // actual, as explained below. | 75 // actual, as explained below. |
| 71 var context = new OfflineAudioContext(2, renderFrames, sampleRate); | 76 var context = new OfflineAudioContext(2, renderFrames, sampleRate); |
| 72 | 77 |
| 73 var oscPositive = context.createOscillator(); | 78 var oscPositive = context.createOscillator(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 oscNegative.start(); | 136 oscNegative.start(); |
| 132 | 137 |
| 133 context.startRendering().then(function (buffer) { | 138 context.startRendering().then(function (buffer) { |
| 134 var expected = buffer.getChannelData(0); | 139 var expected = buffer.getChannelData(0); |
| 135 var actual = buffer.getChannelData(1); | 140 var actual = buffer.getChannelData(1); |
| 136 | 141 |
| 137 Should("Sum of positive and negative frequency custom oscillators", | 142 Should("Sum of positive and negative frequency custom oscillators", |
| 138 actual, { | 143 actual, { |
| 139 precision: 6 | 144 precision: 6 |
| 140 }) | 145 }) |
| 141 .beCloseToArray(expected, 4.7684e-7); | 146 .beCloseToArray(expected, 3.5763e-7); |
| 142 }).then(done); | 147 }).then(done); |
| 143 }); | 148 }); |
| 144 | 149 |
| 145 audit.runTasks(); | 150 audit.runTasks(); |
| 146 | 151 |
| 147 function runTest(options) { | 152 function runTest(options) { |
| 148 // To test if negative frequencies work, create two oscillators. One | 153 // To test if negative frequencies work, create two oscillators. One |
| 149 // has a positive frequency and the other has a negative frequency. | 154 // has a positive frequency and the other has a negative frequency. |
| 150 // Sum the oscillator outputs; the output should be zero because all of | 155 // Sum the oscillator outputs; the output should be zero because all of |
| 151 // the builtin oscillator types are odd functions of frequency. | 156 // the builtin oscillator types are odd functions of frequency. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 181 var zero = new Float32Array(result.length); | 186 var zero = new Float32Array(result.length); |
| 182 zero.fill(0); | 187 zero.fill(0); |
| 183 Should(options.message, result, { | 188 Should(options.message, result, { |
| 184 verbose: true | 189 verbose: true |
| 185 }).beCloseToArray(zero, options.threshold || 0); | 190 }).beCloseToArray(zero, options.threshold || 0); |
| 186 }); | 191 }); |
| 187 } | 192 } |
| 188 </script> | 193 </script> |
| 189 </body> | 194 </body> |
| 190 </html> | 195 </html> |
| OLD | NEW |