| 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/audit.js"></script> |
| 8 <script src="../resources/fft.js"></script> | 8 <script src="../resources/fft.js"></script> |
| 9 <script src="../resources/realtimeanalyser-testing.js"></script> | 9 <script src="../resources/realtimeanalyser-testing.js"></script> |
| 10 <title>Test AnalyserNode Downmixing</title> | 10 <title>Test AnalyserNode Downmixing</title> |
| 11 </head> | 11 </head> |
| 12 | 12 |
| 13 <body> | 13 <body> |
| 14 <script> | 14 <script> |
| 15 var sampleRate = 44100; | 15 var sampleRate = 44100; |
| 16 var renderFrames = 2048; | 16 var renderFrames = 2048; |
| 17 | 17 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 34 message: "5.1", | 34 message: "5.1", |
| 35 floatRelError: 2.0215e-7 | 35 floatRelError: 2.0215e-7 |
| 36 }, { | 36 }, { |
| 37 channelCount: 3, | 37 channelCount: 3, |
| 38 message: "3-channel", | 38 message: "3-channel", |
| 39 floatRelError: 6.3283e-8 | 39 floatRelError: 6.3283e-8 |
| 40 }]; | 40 }]; |
| 41 | 41 |
| 42 // Create tasks for each entry in testConfigs | 42 // Create tasks for each entry in testConfigs |
| 43 for (k in testConfigs) { | 43 for (k in testConfigs) { |
| 44 audit.defineTask(testConfigs[k].message, (function (config) { | 44 audit.define(testConfigs[k].message, (function (config) { |
| 45 return function(done) { | 45 return function(task, should) { |
| 46 runTest(config).then(done); | 46 runTest(config, should).then(() => task.done()); |
| 47 }; | 47 }; |
| 48 })(testConfigs[k])); | 48 })(testConfigs[k])); |
| 49 } | 49 } |
| 50 | 50 |
| 51 audit.defineTask("finish", function (done) { | 51 audit.run(); |
| 52 done(); | |
| 53 }); | |
| 54 | |
| 55 audit.runTasks(); | |
| 56 | 52 |
| 57 // Test downmixing of the AnalyserNode time data. We use the downmixing t
hat automatically | 53 // Test downmixing of the AnalyserNode time data. We use the downmixing t
hat automatically |
| 58 // happens in the destination node to generate the reference data which is
compared to the | 54 // happens in the destination node to generate the reference data which is
compared to the |
| 59 // data that the Analyser node has captured. | 55 // data that the Analyser node has captured. |
| 60 function runTest(options) { | 56 function runTest(options, should) { |
| 61 // Context MUST have exactly one channel so that we downmix the source t
o mono to generate | 57 // Context MUST have exactly one channel so that we downmix the source t
o mono to generate |
| 62 // the reference. | 58 // the reference. |
| 63 var context = new OfflineAudioContext(1, renderFrames, sampleRate); | 59 var context = new OfflineAudioContext(1, renderFrames, sampleRate); |
| 64 | 60 |
| 65 var channels = options.channelCount || 1; | 61 var channels = options.channelCount || 1; |
| 66 var source = context.createBufferSource(); | 62 var source = context.createBufferSource(); |
| 67 | 63 |
| 68 // The signals in each channel. Doesn't matter much what is in here, but
it's best if the | 64 // The signals in each channel. Doesn't matter much what is in here, but
it's best if the |
| 69 // values aren't linearly increasing so that the average of the values i
sn't one of the | 65 // values aren't linearly increasing so that the average of the values i
sn't one of the |
| 70 // values (in case the implementation does something silly). Only need
to support up to 6 | 66 // values (in case the implementation does something silly). Only need
to support up to 6 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 92 analyser.getFloatTimeDomainData(timeData); | 88 analyser.getFloatTimeDomainData(timeData); |
| 93 analyser.getFloatFrequencyData(freqData); | 89 analyser.getFloatFrequencyData(freqData); |
| 94 }).then(context.resume.bind(context)); | 90 }).then(context.resume.bind(context)); |
| 95 | 91 |
| 96 source.start(); | 92 source.start(); |
| 97 return context.startRendering().then(function (renderedBuffer) { | 93 return context.startRendering().then(function (renderedBuffer) { |
| 98 var success = true; | 94 var success = true; |
| 99 | 95 |
| 100 // Verify the time domain data is correct. | 96 // Verify the time domain data is correct. |
| 101 var prefix = "Analyser downmix " + options.message + " to mono" | 97 var prefix = "Analyser downmix " + options.message + " to mono" |
| 102 success = Should(prefix + " time data", timeData) | 98 should(timeData, prefix + " time data") |
| 103 .beEqualToArray(renderedBuffer.getChannelData(0).subarray(0, analyse
r.fftSize)); | 99 .beEqualToArray(renderedBuffer.getChannelData(0).subarray(0, analyse
r.fftSize)); |
| 104 | 100 |
| 105 var expectedTimeData = renderedBuffer.getChannelData(0).subarray(0, an
alyser.fftSize); | 101 var expectedTimeData = renderedBuffer.getChannelData(0).subarray(0, an
alyser.fftSize); |
| 106 var fftOrder = Math.floor(Math.log2(analyser.fftSize)); | 102 var fftOrder = Math.floor(Math.log2(analyser.fftSize)); |
| 107 var expectedFreqData = computeFFTMagnitude(expectedTimeData, fftOrder)
.map(linearToDb); | 103 var expectedFreqData = computeFFTMagnitude(expectedTimeData, fftOrder)
.map(linearToDb); |
| 108 | 104 |
| 109 success = compareFloatFreq(prefix + " freq data", freqData, expectedFr
eqData, { | 105 var success = compareFloatFreq(prefix + " freq data", freqData, |
| 106 expectedFreqData, should, { |
| 110 precision: 6, | 107 precision: 6, |
| 111 floatRelError: options.floatRelError, | 108 floatRelError: options.floatRelError, |
| 112 }) && success; | 109 }); |
| 113 | |
| 114 Should(prefix, success) | |
| 115 .summarize("downmixed correctly.", | |
| 116 "no downmixed correctly."); | |
| 117 }); | 110 }); |
| 118 } | 111 } |
| 119 </script> | 112 </script> |
| 120 </body> | 113 </body> |
| 121 </html> | 114 </html> |
| OLD | NEW |