4 <script src="../resources/js-test.js"></script>
5 <script type="text/javascript" src="resources/audio-testing.js"></script>
9 <div id="description"></div>
10 <div id="console"></div>
13 description("Test pre-emphasis in DynamicsCompressor is removed");
15 var sampleRate = 44100;
16 var lengthInSeconds = 1;
18 // This threshold experimentally determined. It depends on the the gain value 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;
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;
32 for (k = startSample; k < endSample; ++k) {
33 var sample = Math.abs(renderedData[k]);
38 if (peak >= peakThreshold) {
39 testPassed("Pre-emphasis effect not applied as expected..");
41 testFailed("Pre-emphasis caused output to be decreased to " + peak
42 + " (expected >= " + peakThreshold + ")");
49 if (!window.testRunner) {
50 testRunner.dumpAsTest();
51 testRunner.waitUntilDone();
54 window.jsTestIsAsync = true;
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.
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();
68 gain.connect(compressor);
69 compressor.connect(context.destination);
71 context.oncomplete = checkResult;
72 context.startRendering();
76 successfullyParsed = true;