| 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/audio-testing.js"></script> |
| 9 </head> | 9 </head> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 // Test that we use at least 2049 Fourier coefficients at 192 kHz sample
rate. | 41 // Test that we use at least 2049 Fourier coefficients at 192 kHz sample
rate. |
| 42 { | 42 { |
| 43 name: "192khz-test-2", | 43 name: "192khz-test-2", |
| 44 sampleRate: 192000, | 44 sampleRate: 192000, |
| 45 bigWave: 2049, | 45 bigWave: 2049, |
| 46 smallWave: 2048, | 46 smallWave: 2048, |
| 47 verifier: resultShouldBeNonZero | 47 verifier: resultShouldBeNonZero |
| 48 }, | 48 }, |
| 49 | 49 |
| 50 // Test that we use all 8192 Fourier coefficients at 192 kHz sample rate
. Ideally, we'd | 50 // Test that we use all 8192 Fourier coefficients at 192 kHz sample rate
. |
| 51 // like to compare 8191 coefficients vs 8192 coefficients. However, due
to single-precision | |
| 52 // arithmetic, the wave forms are identical in this case. Thus, use a s
omewhat smaller | |
| 53 // value where the wave forms are actually different. | |
| 54 { | 51 { |
| 55 name: "192khz-test-3", | 52 name: "192khz-test-3", |
| 56 sampleRate: 192000, | 53 sampleRate: 192000, |
| 57 bigWave: 8192, | 54 bigWave: 8192, |
| 58 smallWave: (8 - 1 / 256) * 1024, | 55 smallWave: 8191, |
| 59 verifier: resultShouldBeNonZero | 56 verifier: resultShouldBeNonZero |
| 60 }, | 57 }, |
| 61 | 58 |
| 62 // Tests for contexts at 48 kHz. | 59 // Tests for contexts at 48 kHz. |
| 63 | 60 |
| 64 // Test that we do not use more than 2048 Fourier coefficients at 48 kHz
. This depends on | 61 // Test that we do not use more than 2048 Fourier coefficients at 48 kHz
. This depends on |
| 65 // the internal implementation where, for backward compatibility and spe
ed, we only use 2048 | 62 // the internal implementation where, for backward compatibility and spe
ed, we only use 2048 |
| 66 // coefficients at 48 kHz. (This is also true for rates below 88.2 kHz.
) Also tests that | 63 // coefficients at 48 kHz. (This is also true for rates below 88.2 kHz.
) Also tests that |
| 67 // 8192 coefficients are allowed (but not all coefficients are used, of
course). | 64 // 8192 coefficients are allowed (but not all coefficients are used, of
course). |
| 68 { | 65 { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 function createAudioGraph(sampleRate, bigPeriodicWaveLength, smallPeriodic
WaveLength) { | 175 function createAudioGraph(sampleRate, bigPeriodicWaveLength, smallPeriodic
WaveLength) { |
| 179 context = new OfflineAudioContext(1, renderLength * sampleRate, sampleR
ate); | 176 context = new OfflineAudioContext(1, renderLength * sampleRate, sampleR
ate); |
| 180 | 177 |
| 181 // Two PeriodicWave objects are created with different sizes (small and
big). The contents | 178 // 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. | 179 // are the same except that the samll sized PeriodicWave has fewer coef
ficients. |
| 183 var smallWaveRealCoef = new Float32Array(smallPeriodicWaveLength); | 180 var smallWaveRealCoef = new Float32Array(smallPeriodicWaveLength); |
| 184 var smallWaveImagCoef = new Float32Array(smallPeriodicWaveLength); | 181 var smallWaveImagCoef = new Float32Array(smallPeriodicWaveLength); |
| 185 var bigWaveRealCoef = new Float32Array(bigPeriodicWaveLength); | 182 var bigWaveRealCoef = new Float32Array(bigPeriodicWaveLength); |
| 186 var bigWaveImagCoef = new Float32Array(bigPeriodicWaveLength); | 183 var bigWaveImagCoef = new Float32Array(bigPeriodicWaveLength); |
| 187 | 184 |
| 188 // Set up the Fourier coefficients for a square wave. | 185 // Set up the Fourier coefficients for a sawtooth wave. We use |
| 189 for (var k = 0; k < bigPeriodicWaveLength; k += 2) { | 186 // sawtooth because all coefficients are non-zero |
| 190 bigWaveImagCoef[k] = 4 / Math.PI / k; | 187 bigWaveImagCoef[0] = 0; |
| 188 for (var k = 1; k < bigPeriodicWaveLength; k++) { |
| 189 var piFactor = 2 / (Math.PI * k); |
| 190 bigWaveImagCoef[k] = piFactor * ((k % 2 === 0) ? -1 : 1); |
| 191 if (k < smallPeriodicWaveLength) | 191 if (k < smallPeriodicWaveLength) |
| 192 smallWaveImagCoef[k] = bigWaveImagCoef[k]; | 192 smallWaveImagCoef[k] = bigWaveImagCoef[k]; |
| 193 } | 193 } |
| 194 | 194 |
| 195 var smallPeriodicWave = context.createPeriodicWave(smallWaveRealCoef, s
mallWaveImagCoef); | 195 var smallPeriodicWave = context.createPeriodicWave(smallWaveRealCoef, s
mallWaveImagCoef); |
| 196 var bigPeriodicWave = context.createPeriodicWave(bigWaveRealCoef, bigWa
veImagCoef); | 196 var bigPeriodicWave = context.createPeriodicWave(bigWaveRealCoef, bigWa
veImagCoef); |
| 197 | 197 |
| 198 // Create oscillators using these PeriodicWave's. | 198 // Create oscillators using these PeriodicWave's. |
| 199 var smallOscillator = context.createOscillator(); | 199 var smallOscillator = context.createOscillator(); |
| 200 var bigOscillator = context.createOscillator(); | 200 var bigOscillator = context.createOscillator(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 | 245 |
| 246 defineAuditTests(); | 246 defineAuditTests(); |
| 247 audit.runTasks(); | 247 audit.runTasks(); |
| 248 | 248 |
| 249 successfullyParsed = true; | 249 successfullyParsed = true; |
| 250 </script> | 250 </script> |
| 251 </body> | 251 </body> |
| 252 </html> | 252 </html> |
| OLD | NEW |