2.11.0 • Published 8 years ago

bopper v2.11.0

Weekly downloads
30
License
MIT
Repository
github
Last release
8 years ago

bopper

A streaming clock source for scheduling Web Audio events rhythmically.

Use with ditty if you want to create loop sequences.

Install

$ npm install bopper

Require into your browser bundle with browserify.

Example

var audioContext = new AudioContext()
var bopper = require('bopper')(audioContext)

// save a reference on the window to avoid garbage collection
window.scheduler = bopper

var playback = [
  {position: 0, length: 0.1},
  {position: 1, length: 0.1},
  {position: 2, length: 0.1},
  {position: 3, length: 0.1},
  {position: 3.5, length: 0.1},
  {position: 4, length: 0.1},
  {position: 5, length: 0.1},
  {position: 6, length: 0.1},
  {position: 7, length: 0.1},
  {position: 7+1/3, length: 0.1},
  {position: 7+2/3, length: 0.1}
]

// emits data roughly every 20ms

bopper.on('data', function(schedule){
  // schedule: from, to, time, beatDuration

  playback.forEach(function(note){
    if (note.position >= schedule.from && note.position < schedule.to){
      var delta = note.position - schedule.from
      var time = schedule.time + delta
      var duration = note.length * schedule.beatDuration
      play(time, duration)
    }
  })

})

function play(at, duration){
  var oscillator = audioContext.createOscillator()
  oscillator.connect(audioContext.destination)
  oscillator.start(at)
  oscillator.stop(at+duration)
}

bopper.setTempo(120)
bopper.start()

To run the example npm install -g beefy then beefy example.js and navigate to http://localhost:9966/

2.11.0

8 years ago

2.10.0

8 years ago

2.9.2

9 years ago

2.9.1

9 years ago

2.9.0

9 years ago

2.8.0

9 years ago

2.7.0

9 years ago

2.6.0

9 years ago

2.5.0

9 years ago

2.4.1

9 years ago

2.4.0

9 years ago

2.3.1

9 years ago

2.3.0

9 years ago

2.2.5

9 years ago

2.2.4

9 years ago

2.2.3

10 years ago

2.2.2

10 years ago

2.2.1

10 years ago

2.1.1

10 years ago

2.1.0

10 years ago

2.0.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.2.0

10 years ago

0.1.1

11 years ago

0.1.0

11 years ago