OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 var freqs = [200, 500, 1800]; |
| 6 var curTestIdx = 0; |
| 7 if (!this.audioContext) { |
| 8 this.audioContext = new AudioContext(); |
| 9 this.gainNode = this.audioContext.createGain(); |
| 10 this.gainNode.gain.value = 0.5; |
| 11 this.gainNode.connect(this.audioContext.destination); |
| 12 } |
| 13 if (!this.oscillator || |
| 14 this.oscillator.frequency.value != freqs[curTestIdx]) { |
| 15 // Note: We recreate the oscillator each time because this switches the |
| 16 // audio frequency immediately. Re-using the same oscillator tends to take |
| 17 // several hundred milliseconds to ramp-up/down the frequency. |
| 18 if (this.oscillator) { |
| 19 this.oscillator.stop(); |
| 20 this.oscillator.disconnect(); |
| 21 } |
| 22 this.oscillator = this.audioContext.createOscillator(); |
| 23 this.oscillator.type = OscillatorNode.SINE; |
| 24 this.oscillator.frequency.value = freqs[curTestIdx]; |
| 25 this.oscillator.connect(this.gainNode); |
| 26 this.oscillator.start(); |
| 27 } |
OLD | NEW |