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