Last active
          November 6, 2017 20:50 
        
      - 
      
- 
        Save beefchimi/dae0fa17761a7c19deb1fdcfcee3a4bc to your computer and use it in GitHub Desktop. 
    Vibrato method
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const defaultLFO = { | |
| type: 'sine', | |
| freq: 12, | |
| volume: 40, | |
| }; | |
| // Uses same `duration` as "source" oscillator | |
| vibrato(duration, options = {}) { | |
| const config = Object.assign(defaultLFO, options); | |
| this.lfo = this.context.createOscillator(); | |
| this.lfoGainNode = this.context.createGain(); | |
| this.lfo.type = config.type; | |
| this.lfo.frequency.value = config.freq; | |
| // Volume will control the intensity of the effect | |
| this.lfoGainNode.gain.value = config.volume; | |
| // Instead of connecting the LFO to the AudioContext.destination, | |
| // we connect it to the "source" oscillator's frequency instead | |
| this.lfo.connect(this.lfoGainNode); | |
| this.lfoGainNode.connect(this.oscillator.frequency); | |
| this.lfo.start(); | |
| this.lfo.stop(duration); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment