From 257eb2abf4e92a0eabc53642da01abeec9527ac4 Mon Sep 17 00:00:00 2001 From: Cheng-Yi Chiang Date: Tue, 18 Feb 2014 15:07:05 +0800 Subject: scripts: Modify audio.js for emphasis_disabled in drc There is a new parameter "emphasis_disabled" in drc. This patch modifies audio.js file in audio_tuning webpage such that it will check if emphasis/disemphasis is disabled in chrome, then determine drc.emphasis_disabled config value. BUG=chrome-os-partner:25940 TEST=run audio_tuning webpage with modified audio.js. Checks that the output config contains "drc.emphasis_disabled": 0 for chrome without https://codereview.chromium.org/152333003/, and contains "drc.emphasis_disabled": 1 for chrome with https://codereview.chromium.org/152333003/. Change-Id: I6ef355a1d7cd6a4ac340f711d4270a6a88d42b27 Reviewed-on: https://chromium-review.googlesource.com/186857 Reviewed-by: Hsinyu Chao Commit-Queue: Cheng-Yi Chiang Tested-by: Cheng-Yi Chiang --- scripts/audio_tuning/frontend/audio.js | 71 ++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'scripts') diff --git a/scripts/audio_tuning/frontend/audio.js b/scripts/audio_tuning/frontend/audio.js index 022c160d..887ca155 100644 --- a/scripts/audio_tuning/frontend/audio.js +++ b/scripts/audio_tuning/frontend/audio.js @@ -544,6 +544,77 @@ function drc_3band() { this.input = input; this.output = output; this.config = config; + + get_emphasis_disabled(); +} + + +/* This snippet came from LayoutTests/webaudio/dynamicscompressor-simple.html in + * https://codereview.chromium.org/152333003/. It can determine if + * emphasis/deemphasis is disabled in the browser. Then it sets the value to + * drc.emphasis_disabled in the config.*/ +function get_emphasis_disabled() { + var context; + var sampleRate = 44100; + var lengthInSeconds = 1; + var renderedData; + // This threshold is 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; + var emphasis_disabled = 0; + + for (k = startSample; k < endSample; ++k) { + var sample = Math.abs(renderedData[k]); + if (peak < sample) + peak = sample; + } + + if (peak >= peakThreshold) { + console.log("Pre-emphasis effect not applied as expected.."); + emphasis_disabled = 1; + } else { + console.log("Pre-emphasis caused output to be decreased to " + peak + + " (expected >= " + peakThreshold + ")"); + emphasis_disabled = 0; + } + set_config('drc', 'emphasis_disabled', emphasis_disabled); + } + + function runTest() { + + 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(); + } /* Returns one DRC filter */ -- cgit v1.2.3