summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorCheng-Yi Chiang <cychiang@chromium.org>2014-02-18 15:07:05 +0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-03-03 14:18:50 +0000
commit257eb2abf4e92a0eabc53642da01abeec9527ac4 (patch)
tree42e89adc86f4a5dc4929158a7a756ffbe57f574b /scripts
parent4dcc739672538350f8f5e6555bea1a2c0134c168 (diff)
downloadadhd-257eb2abf4e92a0eabc53642da01abeec9527ac4.tar.gz
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 <hychao@chromium.org> Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org> Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/audio_tuning/frontend/audio.js71
1 files changed, 71 insertions, 0 deletions
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 */