MIDI-like instruments from webaudio
npm install webaudio-instrumentsThis is a simple wrapper for a subset of the functionality in
webaudio-tinysynth.
It lets you play tones from MIDI-like instruments, but without any sound fonts
or audio files - the tones are generated purely from WebAudio oscillators.
``sh`
npm install --save webaudio-instruments
`js
var Instruments = require('webaudio-instruments')
var player = new Instruments()
player.play(
24, // instrument: 24 is "Acoustic Guitar (nylon)"
72, // note: midi number or frequency in Hz (if > 127)
0.5, // velocity: 0..1
0, // delay in seconds
0.5, // duration in seconds
0, // (optional - specify channel for tinysynth to use)
0.05 // (optional - override envelope "attack" parameter)
)
`
* var player = new Instruments(audioContext, destinationNode) player.names
Both parameters are optional.
* player.play(inst, note, vel, delay, duration, channel, attack)
Array of instrument names
* note
See above. Note that instruments numbers over 127 are percussion,
so the parameter is ignored. channel, attack params are optional.player.getCurrentTime()
* player.setQuality(q)
Time value (from the audio context)
* 1
Set the quality to (high) or 0 (low). Low version uses fewer oscillators,player._synth`
see original repo for details.
*
For anything else, access the underlying tinysynth.
All the interesting magic here (the implementation of MIDI instruments using
webaudio oscillators) is from
webaudio-tinysynth!
See that repo for further info and more features.
All I've done is to abstract away the MIDI-related stuff,
add CommonJS support, etc.
My additions here are MIT license. Original source is Apache 2.0.