| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test Different PeriodicWave Lengths at Different Sample Rates</title> | 4 <title>Test Different PeriodicWave Lengths at Different Sample Rates</title> |
| 5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 8 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audit.js"></script> |
| 9 </head> | 9 </head> |
| 10 | 10 |
| 11 <body> | 11 <body> |
| 12 <script> | 12 <script> |
| 13 // Test PeriodicWave objects with varying number of coefficients at differ
ent sample rates. | 13 // Test PeriodicWave objects with varying number of coefficients at differ
ent sample rates. |
| 14 // Basically, verify that the coefficients are used at the appropriate sam
ple rates. This is | 14 // Basically, verify that the coefficients are used at the appropriate sam
ple rates. This is |
| 15 // done by comparing the outputs of two periodic waves used in oscillators
. The output should | 15 // done by comparing the outputs of two periodic waves used in oscillators
. The output should |
| 16 // either be exactly zero or not depending on whether the coefficients wer
e used. | 16 // either be exactly zero or not depending on whether the coefficients wer
e used. |
| 17 | 17 |
| 18 var renderLength = 1; | 18 var renderLength = 1; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 ]; | 135 ]; |
| 136 | 136 |
| 137 function generatePrefix (sampleRate, bigLength, smallLength) { | 137 function generatePrefix (sampleRate, bigLength, smallLength) { |
| 138 return "At " + (sampleRate / 1000) + " kHz, PeriodicWave with " | 138 return "At " + (sampleRate / 1000) + " kHz, PeriodicWave with " |
| 139 + bigLength + " coefficients vs " | 139 + bigLength + " coefficients vs " |
| 140 + smallLength + ": "; | 140 + smallLength + ": "; |
| 141 } | 141 } |
| 142 | 142 |
| 143 // Returns a function the verifies that the result is zero. The parameter
s control what is | 143 // Returns a function the verifies that the result is zero. The parameter
s control what is |
| 144 // printed in the messages. | 144 // printed in the messages. |
| 145 function resultShouldBeZero(sampleRate, bigLength, smallLength) { | 145 function resultShouldBeZero(should, sampleRate, bigLength, smallLength) { |
| 146 return function (buffer) { | 146 return function (buffer) { |
| 147 var prefix = generatePrefix(sampleRate, bigLength, smallLength); | 147 var prefix = generatePrefix(sampleRate, bigLength, smallLength); |
| 148 Should(prefix + "are identical", isBufferZero(buffer)) | 148 should(isBufferZero(buffer), prefix + "are identical") |
| 149 .beEqualTo(true); | 149 .beEqualTo(true); |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Returns a function the verifies that the result is non-zero. The param
eters control what is | 153 // Returns a function the verifies that the result is non-zero. The param
eters control what is |
| 154 // printed in the messages. | 154 // printed in the messages. |
| 155 function resultShouldBeNonZero(sampleRate, bigLength, smallLength) { | 155 function resultShouldBeNonZero(should, sampleRate, bigLength, smallLength)
{ |
| 156 return function (buffer) { | 156 return function (buffer) { |
| 157 var prefix = generatePrefix(sampleRate, bigLength, smallLength); | 157 var prefix = generatePrefix(sampleRate, bigLength, smallLength); |
| 158 Should(prefix + "are different", !isBufferZero(buffer)) | 158 should(!isBufferZero(buffer), prefix + "are different") |
| 159 .beEqualTo(true); | 159 .beEqualTo(true); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Creates a function that is used to run an Audit test for a given sample
rate, periodic wave | 163 // Creates a function that is used to run an Audit test for a given sample
rate, periodic wave |
| 164 // sizes, and verifier. | 164 // sizes, and verifier. |
| 165 function createAuditTestFunction(sampleRate, bigLength, smallLength, verif
ier) { | 165 function createAuditTestFunction(sampleRate, bigLength, smallLength, verif
ier) { |
| 166 return function (done) { | 166 return (task, should) => { |
| 167 // Create the audio graph, render it, and then verify that the output
is the expected | 167 // Create the audio graph, render it, and then verify that the output
is the expected |
| 168 // result. | 168 // result. |
| 169 createAudioGraph(sampleRate, bigLength, smallLength); | 169 createAudioGraph(sampleRate, bigLength, smallLength); |
| 170 | 170 |
| 171 context.startRendering() | 171 return context.startRendering() |
| 172 .then(verifier(sampleRate, bigLength, smallLength)) | 172 .then(verifier(should, sampleRate, bigLength, smallLength)) |
| 173 .then(done); | 173 .then(() => task.done()); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 // Create the audio graph for the test. | 177 // Create the audio graph for the test. |
| 178 function createAudioGraph(sampleRate, bigPeriodicWaveLength, smallPeriodic
WaveLength) { | 178 function createAudioGraph(sampleRate, bigPeriodicWaveLength, smallPeriodic
WaveLength) { |
| 179 context = new OfflineAudioContext(1, renderLength * sampleRate, sampleR
ate); | 179 context = new OfflineAudioContext(1, renderLength * sampleRate, sampleR
ate); |
| 180 | 180 |
| 181 // Two PeriodicWave objects are created with different sizes (small and
big). The contents | 181 // Two PeriodicWave objects are created with different sizes (small and
big). The contents |
| 182 // are the same except that the samll sized PeriodicWave has fewer coef
ficients. | 182 // are the same except that the samll sized PeriodicWave has fewer coef
ficients. |
| 183 var smallWaveRealCoef = new Float32Array(smallPeriodicWaveLength); | 183 var smallWaveRealCoef = new Float32Array(smallPeriodicWaveLength); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 return true; | 227 return true; |
| 228 } | 228 } |
| 229 | 229 |
| 230 // Ensure the actual Audit test name is unique by prepending an index to t
he provided test | 230 // Ensure the actual Audit test name is unique by prepending an index to t
he provided test |
| 231 // name. | 231 // name. |
| 232 function actualTestName(name, index) { | 232 function actualTestName(name, index) { |
| 233 return index + ":" + name; | 233 return index + ":" + name; |
| 234 } | 234 } |
| 235 | 235 |
| 236 // Define the tasks based on the entries in testSet. | 236 // Define the tasks based on the entries in testSet. |
| 237 function defineAuditTests () { | 237 function defineAuditTests() { |
| 238 for (var k = 0; k < testSet.length; ++k) { | 238 for (var k = 0; k < testSet.length; ++k) { |
| 239 var test = testSet[k]; | 239 let {name, sampleRate, bigWave, smallWave, verifier} = testSet[k]; |
| 240 var actualName = actualTestName(test.name, k); | 240 let actualName = actualTestName(name, k); |
| 241 audit.defineTask(actualName, | 241 audit.define(actualName, |
| 242 createAuditTestFunction(test.sampleRate, test.bigWave, test.smallWav
e, test.verifier)); | 242 createAuditTestFunction(sampleRate, bigWave, smallWave, verifier)); |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 | 245 |
| 246 defineAuditTests(); | 246 defineAuditTests(); |
| 247 audit.runTasks(); | 247 audit.run(); |
| 248 | |
| 249 successfullyParsed = true; | |
| 250 </script> | 248 </script> |
| 251 </body> | 249 </body> |
| 252 </html> | 250 </html> |
| OLD | NEW |