Index: LayoutTests/webaudio/dynamicscompressor-simple.html |
diff --git a/LayoutTests/webaudio/dynamicscompressor-simple.html b/LayoutTests/webaudio/dynamicscompressor-simple.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b4000d21e8b656ee9a898138347f1a3c2abf05f8 |
--- /dev/null |
+++ b/LayoutTests/webaudio/dynamicscompressor-simple.html |
@@ -0,0 +1,81 @@ |
+<!DOCTYPE HTML> |
+<html> |
+ <head> |
+ <script src="../resources/js-test.js"></script> |
+ <script type="text/javascript" src="resources/audio-testing.js"></script> |
+ </head> |
+ |
+ <body> |
+ <div id="description"></div> |
+ <div id="console"></div> |
+ |
+ <script> |
+ description("Test pre-emphasis in DynamicsCompressor is removed"); |
+ var context; |
+ var sampleRate = 44100; |
+ var lengthInSeconds = 1; |
+ var renderedData; |
+ // This threshold experimentally determined. It depends on the the gain value of the gain node |
+ // below and the dynamics compressor. When the DynamicsCompressor had the pre-emphasis |
+ // filters, the peak value is about 0.21. Without it, the peak is 0.85. |
+ var peakThreshold = 0.85; |
+ |
+ function checkResult(event) { |
+ var renderedBuffer = event.renderedBuffer; |
+ renderedData = renderedBuffer.getChannelData(0); |
+ // Search for a peak in the last part of the data. |
+ var startSample = sampleRate * (lengthInSeconds - .1); |
+ var endSample = renderedData.length; |
+ var k; |
+ var peak = -1; |
+ |
+ for (k = startSample; k < endSample; ++k) { |
+ var sample = Math.abs(renderedData[k]); |
+ if (peak < sample) |
+ peak = sample; |
+ } |
+ |
+ if (peak >= peakThreshold) { |
+ testPassed("Pre-emphasis effect not applied as expected.."); |
+ } else { |
+ testFailed("Pre-emphasis caused output to be decreased to " + peak |
+ + " (expected >= " + peakThreshold + ")"); |
+ } |
+ |
+ finishJSTest(); |
+ } |
+ |
+ function runTest() { |
+ if (!window.testRunner) { |
+ testRunner.dumpAsTest(); |
+ testRunner.waitUntilDone(); |
+ } |
+ |
+ window.jsTestIsAsync = true; |
+ |
+ context = new webkitOfflineAudioContext(1, sampleRate * lengthInSeconds, sampleRate); |
+ // Connect an oscillator to a gain node to the compressor. The |
+ // oscillator frequency is set to a high value for the (original) |
+ // emphasis to kick in. The gain is a little extra boost to get the |
+ // compressor enabled. |
+ // |
+ var osc = context.createOscillator(); |
+ osc.frequency.value = 15000; |
+ var gain = context.createGain(); |
+ gain.gain.value = 1.5; |
+ var compressor = context.createDynamicsCompressor(); |
+ osc.connect(gain); |
+ gain.connect(compressor); |
+ compressor.connect(context.destination); |
+ osc.start(); |
+ context.oncomplete = checkResult; |
+ context.startRendering(); |
+ } |
+ |
+ runTest(); |
+ successfullyParsed = true; |
+ |
+ </script> |
+ |
+ </body> |
+</html> |