Xylophone
Simple library for creating tones using the WebAudioAPI
Installation
npm install xylophone --save
or
Download xylophone.js from master
and include it in your project
Example
// Play one measureawait xylophone.play // Play an array of measuresawait xylophone.play // Create a loop // Stop the loop in 20 secondssetTimeoutcancel, 20000
Usage
interface IMeasure
notes: string // 'C0' through 'C8' on the equal tempered scalelength?: number // The length of each noteoffset?: number // The offset between notes (e.i. `offset: 0` would play all the notes at the same time)type?: "sine" | "square" | "sawtooth" | "triangle"
Xylophone.prototype.play(measure: IMeasure | IMeasure[]): Promise<void>
Plays a series of notes in an IMeasure
. If an array of IMeasure
s is given then each IMeasure
will play when the previous one ends.
- Resolves when all sound has stopped.
Xylophone.prototype.loop(measure: IMeasure | IMeasure[]): Promise<() => void)>
Plays measure
in a loop until canceled.
returns
cancel() => void
Canceles the loop when called
Support
Xylophone supports any browser with AudioContext
or webkitAudioContext
support
See caniuse.com for details
License
MIT