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