gibberish-dsp
Version:
Gibberish is designed to be an optimized API for audio synthesis using per-sample techniques.
71 lines (56 loc) • 1.88 kB
JavaScript
let g = require( 'genish.js' ),
effect = require( './effect.js' )
module.exports = function( Gibberish ) {
let Delay = inputProps => {
let props = Object.assign( { delayLength: 88200 }, effect.defaults, Delay.defaults, inputProps ),
delay = Object.create( effect )
let out
delay.__createGraph = function() {
let isStereo = false
if( out === undefined ) {
isStereo = typeof props.input.isStereo !== 'undefined' ? props.input.isStereo : false
}else{
isStereo = out.input.isStereo
out.isStereo = isStereo
}
const input = g.in( 'input' ),
inputGain = g.in( 'inputGain' ),
delayTime = g.in( 'time' ),
wetdry = g.in( 'wetdry' ),
leftInput = isStereo ? g.mul( input[ 0 ], inputGain ) : g.mul( input, inputGain ),
rightInput = isStereo ? g.mul( input[ 1 ], inputGain ) : null
const feedback = g.in( 'feedback' )
// left channel
const feedbackHistoryL = g.history()
const echoL = g.delay( g.add( leftInput, g.mul( feedbackHistoryL.out, feedback ) ), delayTime, { size:props.delayLength })
feedbackHistoryL.in( echoL )
const left = g.mix( leftInput, echoL, wetdry )
if( isStereo ) {
// right channel
const feedbackHistoryR = g.history()
const echoR = g.delay( g.add( rightInput, g.mul( feedbackHistoryR.out, feedback ) ), delayTime, { size:props.delayLength })
feedbackHistoryR.in( echoR )
const right = g.mix( rightInput, echoR, wetdry )
delay.graph = [ left, right ]
}else{
delay.graph = left
}
}
delay.__createGraph()
delay.__requiresRecompilation = [ 'input' ]
out = Gibberish.factory(
delay,
delay.graph,
['fx','delay'],
props
)
return out
}
Delay.defaults = {
input:0,
feedback:.5,
time: 11025,
wetdry: .5
}
return Delay
}