gibberish-dsp
Version:
Gibberish is designed to be an optimized API for audio synthesis using per-sample techniques.
33 lines (20 loc) • 835 B
JavaScript
const ugen = require( '../ugen.js' ),
g = require( 'genish.js' )
module.exports = function( Gibberish ) {
const Ramp = function( argumentProps ) {
const ramp = Object.create( ugen ),
length = g.in( 'length' ),
from = g.in( 'from' ),
to = g.in( 'to' )
const props = Object.assign({}, Ramp.defaults, argumentProps )
const reset = g.bang()
const phase = g.accum( g.div( 1, length ), reset, { shouldWrap:props.shouldLoop, shouldClamp:true }),
diff = g.sub( to, from ),
graph = g.add( from, g.mul( phase, diff ) )
ramp.trigger = reset.trigger
const out = Gibberish.factory( ramp, graph, ['envelopes','ramp'], props )
return out
}
Ramp.defaults = { from:0, to:1, length:g.gen.samplerate, shouldLoop:false }
return Ramp
}