Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> | |
| 5 <script src="../resources/audit-util.js"></script> | 6 <script src="../resources/audit-util.js"></script> |
| 6 <script src="../resources/audio-testing.js"></script> | 7 <script src="../resources/audit.js"></script> |
| 7 </head> | 8 </head> |
| 8 | 9 |
| 9 <body> | 10 <body> |
| 10 <div id="description"></div> | |
| 11 <div id="console"></div> | |
| 12 | |
| 13 <script> | 11 <script> |
| 14 description("Test pre-emphasis in DynamicsCompressor is removed"); | 12 var audit = Audit.createTaskRunner(); |
| 15 var context; | 13 var context; |
| 16 var compressor; | 14 var compressor; |
| 17 var sampleRate = 44100; | 15 var sampleRate = 44100; |
| 18 var lengthInSeconds = 1; | 16 var lengthInSeconds = 1; |
| 19 var renderedData; | 17 var renderedData; |
| 20 // This threshold experimentally determined. It depends on the the gain va lue of the gain node | 18 // This threshold experimentally determined. It depends on the the gain va lue of the gain node |
| 21 // below and the dynamics compressor. When the DynamicsCompressor had the pre-emphasis | 19 // below and the dynamics compressor. When the DynamicsCompressor had the pre-emphasis |
| 22 // filters, the peak value is about 0.21. Without it, the peak is about 0 .84. | 20 // filters, the peak value is about 0.21. Without it, the peak is about 0 .84. |
| 23 var peakThreshold = 0.83; | 21 var peakThreshold = 0.83; |
| 24 | 22 |
| 25 function checkResult(event) { | 23 function checkResult(renderedBuffer, should) { |
| 26 var renderedBuffer = event.renderedBuffer; | |
| 27 renderedData = renderedBuffer.getChannelData(0); | 24 renderedData = renderedBuffer.getChannelData(0); |
| 28 // Search for a peak in the last part of the data. | 25 // Search for a peak in the last part of the data. |
| 29 var startSample = sampleRate * (lengthInSeconds - .1); | 26 var startSample = sampleRate * (lengthInSeconds - .1); |
| 30 var endSample = renderedData.length; | 27 var endSample = renderedData.length; |
| 31 var k; | 28 var k; |
| 32 var peak = -1; | 29 var peak = -1; |
| 33 | 30 |
| 34 for (k = startSample; k < endSample; ++k) { | 31 for (k = startSample; k < endSample; ++k) { |
| 35 var sample = Math.abs(renderedData[k]); | 32 var sample = Math.abs(renderedData[k]); |
| 36 if (peak < sample) | 33 if (peak < sample) |
| 37 peak = sample; | 34 peak = sample; |
| 38 } | 35 } |
| 39 | 36 |
| 40 if (peak >= peakThreshold) { | 37 should(peak >= peakThreshold, "Pre-emphasis effect not applied") |
| 41 testPassed("Pre-emphasis effect not applied as expected.."); | 38 .beTrue(); |
| 42 } else { | |
| 43 testFailed("Pre-emphasis caused output to be decreased to " + peak | |
| 44 + " (expected >= " + peakThreshold + ")"); | |
| 45 } | |
| 46 | 39 |
| 47 if (compressor.reduction) | 40 should(compressor.reduction !== 0, |
| 48 testPassed("Reduction value changed as expected.") | 41 "Reduction value changed") |
| 49 else | 42 .beTrue(); |
| 50 testFailed("Reduction value is still the default value of 0."); | |
| 51 finishJSTest(); | |
| 52 } | 43 } |
| 53 | 44 |
| 54 function runTest() { | 45 audit.define("test", function (task, should) { |
| 55 window.jsTestIsAsync = true; | 46 task.describe("Test pre-emphasis in DynamicsCompressor is removed"); |
| 56 | 47 |
| 57 context = new OfflineAudioContext(1, sampleRate * lengthInSeconds, sampl eRate); | 48 context = new OfflineAudioContext(1, sampleRate * lengthInSeconds, sampl eRate); |
| 58 // Connect an oscillator to a gain node to the compressor. The | 49 // Connect an oscillator to a gain node to the compressor. The |
| 59 // oscillator frequency is set to a high value for the (original) | 50 // oscillator frequency is set to a high value for the (original) |
| 60 // emphasis to kick in. The gain is a little extra boost to get the | 51 // emphasis to kick in. The gain is a little extra boost to get the |
| 61 // compressor enabled. | 52 // compressor enabled. |
| 62 // | 53 // |
| 63 var osc = context.createOscillator(); | 54 var osc = context.createOscillator(); |
| 64 osc.frequency.value = 15000; | 55 osc.frequency.value = 15000; |
| 65 var gain = context.createGain(); | 56 var gain = context.createGain(); |
| 66 gain.gain.value = 1.5; | 57 gain.gain.value = 1.5; |
| 67 compressor = context.createDynamicsCompressor(); | 58 compressor = context.createDynamicsCompressor(); |
| 68 osc.connect(gain); | 59 osc.connect(gain); |
| 69 gain.connect(compressor); | 60 gain.connect(compressor); |
| 70 compressor.connect(context.destination); | 61 compressor.connect(context.destination); |
| 71 osc.start(); | 62 osc.start(); |
| 72 context.oncomplete = checkResult; | 63 |
| 73 context.startRendering(); | 64 context.startRendering() |
| 74 } | 65 .then(buffer => checkResult(buffer, should)) |
| 66 .then(task.done.bind(task));; | |
|
hongchan
2017/02/06 17:30:26
task => task.done()
Raymond Toy
2017/02/06 18:12:20
Done.
| |
| 67 }); | |
| 75 | 68 |
| 76 runTest(); | 69 audit.run(); |
| 77 successfullyParsed = true; | |
| 78 | |
| 79 </script> | 70 </script> |
| 80 | 71 |
| 81 </body> | 72 </body> |
| 82 </html> | 73 </html> |
| OLD | NEW |