1.7.0 • Published 6 years ago

beat-emitter v1.7.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

beat-emitter

WebAudio scheduler with an event emitter

Features

  • runs as a web worker (so that setInterval fires more reliably)
  • schedules audio events with a slight look-ahead, for precise timing

Usage

const beatEmitter = require('beat-emitter')

const ac = new AudioContext()
const beats = beatEmitter(ac)

beats.setBpm(110)

// optional: shuffle factor (best results between .02 and .09)
beats.setShuffle(.07)

beats.start()
beats.schedule((beat, time) => {
  // play a note every 2nd beat
  if (beat % 2 === 0) {
    const osc = ac.createOscillator()
    osc.frequency.value = 440
    osc.start(time)
    osc.stop(time + 0.1)
    osc.connect(ac.destination)
  }
})

Acknowledgements

I learned a lot from reading https://github.com/cwilso/metronome and based the code on this.

1.7.0

6 years ago

1.6.0

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago