OLD | NEW |
(Empty) | |
| 1 var freqs = [200, 500, 1800]; |
| 2 var curTestIdx = 0; |
| 3 if (!this.audioContext) { |
| 4 this.audioContext = new AudioContext(); |
| 5 this.gainNode = this.audioContext.createGain(); |
| 6 this.gainNode.gain.value = 0.5; |
| 7 this.gainNode.connect(this.audioContext.destination); |
| 8 } |
| 9 if (!this.oscillator || |
| 10 this.oscillator.frequency.value != freqs[curTestIdx]) { |
| 11 // Note: We recreate the oscillator each time because this switches the |
| 12 // audio frequency immediately. Re-using the same oscillator tends to take |
| 13 // several hundred milliseconds to ramp-up/down the frequency. |
| 14 if (this.oscillator) { |
| 15 this.oscillator.stop(); |
| 16 this.oscillator.disconnect(); |
| 17 } |
| 18 this.oscillator = this.audioContext.createOscillator(); |
| 19 this.oscillator.type = OscillatorNode.SINE; |
| 20 this.oscillator.frequency.value = freqs[curTestIdx]; |
| 21 this.oscillator.connect(this.gainNode); |
| 22 this.oscillator.start(); |
| 23 } |
OLD | NEW |