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 function enableSineWave() { | |
6 var freqs = [200, 500, 1800]; | |
7 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
| |
8 if (!this.audioContext) { | |
9 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.
| |
10 this.gainNode = this.audioContext.createGain(); | |
11 this.gainNode.gain.value = 0.5; | |
12 this.gainNode.connect(this.audioContext.destination); | |
13 } | |
14 if (!this.oscillator || | |
15 this.oscillator.frequency.value != freqs[curTestIdx]) { | |
16 // Note: We recreate the oscillator each time because this switches the | |
17 // audio frequency immediately. Re-using the same oscillator tends to take | |
18 // several hundred milliseconds to ramp-up/down the frequency. | |
19 if (this.oscillator) { | |
20 this.oscillator.stop(); | |
21 this.oscillator.disconnect(); | |
22 } | |
23 this.oscillator = this.audioContext.createOscillator(); | |
24 this.oscillator.type = OscillatorNode.SINE; | |
25 this.oscillator.frequency.value = freqs[curTestIdx]; | |
26 this.oscillator.connect(this.gainNode); | |
27 this.oscillator.start(); | |
28 } | |
29 } | |
30 | |
31 function disableSineWave() { | |
32 this.oscillator.stop(); | |
33 } | |
OLD | NEW |