library which wraps webaudio interface and makes it easier to use.
Currently in development phase, so may works little differently than described. Sorry for that, I am making it in my free time.
these function creates various audio nodes and connects them.
hb.start()
- starts webaudio. Important - you have to call this before using anything from this library!hb.now()
- returns current timehb.clamp(min, v, max)
- enforces limitsmin
andmax
for valuev
hb.midi2cps(nn, A4=440)
- convertsnn
MIDI note number to frequency (based onA4
tuning value)hb.cps2midi(freq, A4=440)
- convertsfreq
ency to MIDI note number (based onA4
tuning value)hb.makeOsc(wave, freq, startAt=hb.now())
- makesOscillatorNode
with waveformwave
and frequencyfreq
hb.makeNoiseOsc(startAt=hb.now())
- makes noise source (2s of generated white noise sample)hb.generateWaveformBuffer(generator, params={}, len=/*one cycle of C3 note*/)
- generateslen
samples of audio buffer by callinggenerator
function withparams
hb.generators
- generators forhb.generateWaveformBuffer
function -sin
,sqr
,pulse({width:0.1})
,saw
,triangle
hb.makeSamplerOsc(buffer, freq, baseFreq=C3 note, startAt=hb.now())
- makes tunableAudioBufferSourceNode
which is (partially) pretending to beOscillatorNode
with frequencyfreq
, tuned tobaseFreq
hb.makeSamplerLoopOsc
- samehb.makeSamplerOsc
, but with loopinghb.makeDrumOsc(buffer, startAt=hb.now())
- makesAudioBufferSourceNode
which is not tunablehb.makeConstantOsc(n)
- makesConstantSourceNode
with offsetn
hb.makeGain(vol=0)
- makesGainNode
with volumevol
hb.makeFilter(type=lowpass, freq=0)
- makesBiquadFilterNode
oftype
type and frequencyfreq
hb.makeAdder
- TBDhb.makeMultiplier
- TBDhb.chain(a, b [, c ...])
- connectsa
andb
or more nodes, stops on first thing which is notAudioNode
hb.unchain(a, b [, c ...])
- disconnectsa
andb
or more nodes, stops on first thing which is notAudioNode
these functions are for realtime manipulation of AudioParam
interface.
hb.moveTo(audioParam, target, time)
- movesaudioParam
intime
time totarget
valuehb.setNow(audioParam, target)
- sets value ofaudioParam
totarget
valuehb.adsrStart(audioParam, env)
- starts ADSR envelopeenv
foraudioParam
hb.adsrStart(audioParam, env)
- stops ADSR envelopeenv
foraudioParam
Default env
definition is {attack: 0.05, decay: 0.01, sustain: 0, release: 0.05, max: 1}
. You can supply only
partial definition, but you need to supply at least empty object ({}
).
Function hb.midi2call(midi_data, synth, only_channel)
- translates midi_data
to method calls on synth
instance, if only_channel
is set then it uses only this channel and ignore others.
Suported calls are:
synth.noteOn(note, velocity)
synth.noteOff(note)
synth.panic()
synth.programChange(program)
synth.pitchBend(bend)
- note that raw values are recalculated to scale -1 to +1synth.CC(controller, value)
- control changesynth.start()
- starts playbacksynth.stop()
- stops playback
There is a basic support for WebMidiLink. You can call function hb.enableWebMidiLink(synth)
and register your synth
to receive events via WebMidiLink. Only channel 1 is now supported.
As setTimeout
and setInterval
notoriously bad at timing, there is metronome in this library. It can be used as base for your sequencers, arpegiators and stuff. It has following interface:
metronome = hb.makeMetronome(callback)
- creates metronome instance withcallback
to be called at each tickmetronome.setBpm(bpm, div=4)
- set tempo tobpm
anddivision
of whole note, default is 120 BPM (quarter notes)metronome.setCps(cps)
- set tempo in cycles per secondmetronome.start()
- starts metronomemetronome.stop()
- stops it
these are complex components - synths, effect units and other devices.
Each component has input
and/or/nor output
, zero or more params and this interface:
var component = hb.ComponentName(out)
compoment.param(name, val)
component.noteOn(nn, vv)
component.noteOff(nn)
component.plan(at, nn, vv, dur)
component.panic()
component.input
and/or/norcomponent.output
mixing board strip-like component - it has EQ, reverb, panning and volume.
Parameters are:
hi
- gain of high frequencies (above 12 kHz)mid
- gain of mid frequencies (around 1000 Hz)low
- gain of low frequencies (below 80 Hz)pan
- panning (-1 hardleft, 0 center, +1 hardright)reverb
- how much of sound will be send to reverb (0-1)reverb_len
- length of reverb in secondsvol
- volume (0-1)
Gain is in dB (safe values are from -20 to +20).
simple component for recording and playing back WAV files. It has following API:
tape.record()
- starts recordingtape.stop()
- stops recording/playbacktape.play()
- plays back recorded audiotape.loadLocalFile(file)
- loads localfile
for playbacktape.loadRemoteFile(url)
- loads remote file for playbacktape.downloadFile()
- download currently loaded file to user's browsertape.makeFilename()
- used to generate filename used for recording
Note - this currently requires wave-encoder-polyfill.js
as no browser currently implements WAV encoder (in MediaRecorder
).
- ub - I use custom library called uboot for DOM-related stuff. There is
ub.chnget
function provided which uses this to watch inputs and use these as params for synth components. - JZZ.js, webmidi.js and WebMIDI - use
hb.midi2call
to translate to synth calls - Tone.js, Pizziato.js and others - as these libraries uses
audioNode
interface it's possible to connect these usinghb.chain
TBD