4 <script src=
"../resources/js-test.js"></script>
5 <script src=
"resources/compatibility.js"></script>
6 <script type=
"text/javascript" src=
"resources/audio-testing.js"></script>
10 <div id=
"description"></div>
11 <div id=
"console"></div>
14 description("Test pre-emphasis in DynamicsCompressor is removed");
16 var sampleRate
= 44100;
17 var lengthInSeconds
= 1;
19 // This threshold experimentally determined. It depends on the the gain value of the gain node
20 // below and the dynamics compressor. When the DynamicsCompressor had the pre-emphasis
21 // filters, the peak value is about 0.21. Without it, the peak is about 0.84.
22 var peakThreshold
= 0.83;
24 function checkResult(event
) {
25 var renderedBuffer
= event
.renderedBuffer
;
26 renderedData
= renderedBuffer
.getChannelData(0);
27 // Search for a peak in the last part of the data.
28 var startSample
= sampleRate
* (lengthInSeconds
- .1);
29 var endSample
= renderedData
.length
;
33 for (k
= startSample
; k
< endSample
; ++k
) {
34 var sample
= Math
.abs(renderedData
[k
]);
39 if (peak
>= peakThreshold
) {
40 testPassed("Pre-emphasis effect not applied as expected..");
42 testFailed("Pre-emphasis caused output to be decreased to " + peak
43 + " (expected >= " + peakThreshold
+ ")");
50 if (!window
.testRunner
) {
51 testRunner
.dumpAsTest();
52 testRunner
.waitUntilDone();
55 window
.jsTestIsAsync
= true;
57 context
= new OfflineAudioContext(1, sampleRate
* lengthInSeconds
, sampleRate
);
58 // Connect an oscillator to a gain node to the compressor. The
59 // 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
61 // compressor enabled.
63 var osc
= context
.createOscillator();
64 osc
.frequency
.value
= 15000;
65 var gain
= context
.createGain();
66 gain
.gain
.value
= 1.5;
67 var compressor
= context
.createDynamicsCompressor();
69 gain
.connect(compressor
);
70 compressor
.connect(context
.destination
);
72 context
.oncomplete
= checkResult
;
73 context
.startRendering();
77 successfullyParsed
= true;