audio-scheduler
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Audio Scheduler

Accurate timing for the Web Audio Api, with realtime changes to tempo and sequence.

Install

npm install audio-scheduler

Example

import {AudioScheduler} from 'audio-scheduler'

const quarterNote = 1
const eightNote = 0.5 

const audioContext = new AudioContext()

const options = {
    tempo: 128,
    intervalLengths: [quarterNote, quarterNote, eightNote],
    infinite: true,
    context: audioContext,
}

const scheduler = new AudioScheduler(options)

function synth(time) {
    const osc = audioContext.createOscillator()
    osc.connect(audioContext.destination)
    osc.start(time)
    const stopTime = time + 0.05
    osc.stop(stopTime)
}

scheduler.startInterval(synth)

API

startInterval(callback: Function): number

stopInterval(interval: number): void

setTempo(tempo: number): void

updateIntervals(intervalList: number[]): void

push(newInterval: number): void

shift(): void

pop(): void

pause(): void

unpause(): void

Package Sidebar

Install

npm i audio-scheduler

Weekly Downloads

1

Version

0.1.0

License

ISC

Unpacked Size

32.1 kB

Total Files

14

Last publish

Collaborators

  • sonnykjellberg