Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/tabs/basics/sinewave.js |
| diff --git a/chrome/test/data/extensions/api_test/tabs/basics/sinewave.js b/chrome/test/data/extensions/api_test/tabs/basics/sinewave.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7895012c09fa4dbefb9439df5c96cc84141019f8 |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/api_test/tabs/basics/sinewave.js |
| @@ -0,0 +1,33 @@ |
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +function enableSineWave() { |
| + var freqs = [200, 500, 1800]; |
| + var curTestIdx = 0; |
|
not at google - send to devlin
2015/06/01 20:33:57
am I missing something, or is curTestIdx never act
Jared Sohn
2015/06/02 08:54:38
Just a note on this: I didn't write most of this c
|
| + if (!this.audioContext) { |
| + this.audioContext = new AudioContext(); |
|
not at google - send to devlin
2015/06/01 20:33:56
I'd rather not use |this| here. Trivia: it actuall
Jared Sohn
2015/06/02 08:54:38
Done.
|
| + this.gainNode = this.audioContext.createGain(); |
| + this.gainNode.gain.value = 0.5; |
| + this.gainNode.connect(this.audioContext.destination); |
| + } |
| + if (!this.oscillator || |
| + this.oscillator.frequency.value != freqs[curTestIdx]) { |
| + // Note: We recreate the oscillator each time because this switches the |
| + // audio frequency immediately. Re-using the same oscillator tends to take |
| + // several hundred milliseconds to ramp-up/down the frequency. |
| + if (this.oscillator) { |
| + this.oscillator.stop(); |
| + this.oscillator.disconnect(); |
| + } |
| + this.oscillator = this.audioContext.createOscillator(); |
| + this.oscillator.type = OscillatorNode.SINE; |
| + this.oscillator.frequency.value = freqs[curTestIdx]; |
| + this.oscillator.connect(this.gainNode); |
| + this.oscillator.start(); |
| + } |
| +} |
| + |
| +function disableSineWave() { |
| + this.oscillator.stop(); |
| +} |