adsr-gain-node
Simple object for getting an ADSR gain node
Install:
npm install --save adsr-gain-node
Example usage
var adsrGainNode = var audioCtx = ; var oscillator = audioCtx; // Helper function to get new gain node { let adsr = audioCtx; adsr; return adsr} // Begin time for gainvar nowTime = audioCtxcurrentTime // Get adsr and the gain node// Time it to begin in current time + 5 secslet testTime = 2 var adsr = var gainNode = adsr; // Connect the oscillator to the gain nodeoscillator;gainNode; // StartoscillatorstartnowTime + testTime; // Stop oscillator according to the ADSRlet endTime = adsr + testTimeoscillator // On a piano you may want to release the note, when// the key is released. // // Then you may do something like this to end the note and the gain node: // E.g onKeyUp: // oscillator.stop(this.adsr.releaseTimeNow())// adsr.releaseNow()
There is also a HTML form which can generate a web interface for the control of gain nodes.
You can see it on https://diversen.github.io/adsr-gain-node/
The source is test.js
License
MIT © Dennis Iversen