UNPKG

gibberish-dsp

Version:

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

69 lines (51 loc) 2.31 kB
let g = require( 'genish.js' ), filter = require( './filter.js' ) module.exports = function( Gibberish ) { Gibberish.genish.filter24 = ( input, _rez, _cutoff, isLowPass, isStereo=false ) => { let returnValue, polesL = g.data([ 0,0,0,0 ], 1, { meta:true }), peekProps = { interp:'none', mode:'simple' }, rez = g.memo( g.mul( _rez, 5 ) ), cutoff = g.memo( g.div( _cutoff, 11025 ) ), rezzL = g.clamp( g.mul( polesL[3], rez ) ), outputL = g.sub( isStereo ? input[0] : input, rezzL ) polesL[0] = g.add( polesL[0], g.mul( g.add( g.mul(-1, polesL[0] ), outputL ), cutoff )) polesL[1] = g.add( polesL[1], g.mul( g.add( g.mul(-1, polesL[1] ), polesL[0] ), cutoff )) polesL[2] = g.add( polesL[2], g.mul( g.add( g.mul(-1, polesL[2] ), polesL[1] ), cutoff )) polesL[3] = g.add( polesL[3], g.mul( g.add( g.mul(-1, polesL[3] ), polesL[2] ), cutoff )) let left = g.switch( isLowPass, polesL[3], g.sub( outputL, polesL[3] ) ) if( isStereo ) { let polesR = g.data([ 0,0,0,0 ], 1, { meta:true }), rezzR = g.clamp( g.mul( polesR[3], rez ) ), outputR = g.sub( input[1], rezzR ) polesR[0] = g.add( polesR[0], g.mul( g.add( g.mul(-1, polesR[0] ), outputR ), cutoff )) polesR[1] = g.add( polesR[1], g.mul( g.add( g.mul(-1, polesR[1] ), polesR[0] ), cutoff )) polesR[2] = g.add( polesR[2], g.mul( g.add( g.mul(-1, polesR[2] ), polesR[1] ), cutoff )) polesR[3] = g.add( polesR[3], g.mul( g.add( g.mul(-1, polesR[3] ), polesR[2] ), cutoff )) let right = g.switch( isLowPass, polesR[3], g.sub( outputR, polesR[3] ) ) returnValue = [left, right] }else{ returnValue = left } return returnValue } let Filter24 = inputProps => { let filter24 = Object.create( filter ) let props = Object.assign( {}, Filter24.defaults, filter.defaults, inputProps ) let isStereo = props.input.isStereo const __out = Gibberish.factory( filter24, Gibberish.genish.filter24( g.in('input'), g.in('Q'), g.in('cutoff'), g.in('isLowPass'), isStereo ), ['filters','Filter24Classic'], props ) return __out } Filter24.defaults = { input:0, Q: .25, cutoff: 880, isLowPass:1 } return Filter24 }