UNPKG

gibberish-dsp

Version:

Gibberish is designed to be an optimized API for audio synthesis using per-sample techniques.

43 lines (30 loc) 1.17 kB
let g = require( 'genish.js' ), instrument = require( './instrument.js' ) module.exports = function( Gibberish ) { const Cowbell = argumentProps => { let cowbell = Object.create( instrument ) const decay = g.in( 'decay' ), gain = g.in( 'gain' ), loudness = g.in( 'loudness' ), triggerLoudness = g.in( '__triggerLoudness' ) const props = Object.assign( {}, Cowbell.defaults, argumentProps ) const bpfCutoff = g.param( 'bpfc', 1000 ), s1 = Gibberish.oscillators.factory( 'square', 560 ), s2 = Gibberish.oscillators.factory( 'square', 845 ), eg = g.decay( g.mul( decay, g.gen.samplerate * 2 ), { initValue:0 }), bpf = g.svf( g.add( s1,s2 ), bpfCutoff, 3, 2, false ), envBpf = g.mul( bpf, eg ), out = g.mul( envBpf, g.mul( gain, loudness, triggerLoudness ) ) cowbell.env = eg cowbell.isStereo = false cowbell = Gibberish.factory( cowbell, out, ['instruments', 'cowbell'], props ) return cowbell } Cowbell.defaults = { gain: 1, decay:.5, loudness:1, __triggerLoudness:1 } return Cowbell }