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