Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
adsr-envelope
Advanced tools
ADSR Envelope
Node.js
npm install adsr-envelope
constructor(opts: object = {})
attackTime: number
default: 0.01 (10msec)decayTime: number
default: 0.3 (300msec)sustainLevel: number
default: 0.5releaseTime: number
default: 1 (1sec)gateTime: number
default: InfinitysustainTime: number
duration: number
peakLevel: number
default: 1epsilon: number
default: 0.001attackCurve: string
default: lin
decayCurve: string
default: lin
releaseCurve: string
default: lin
duration: number
attackTime: number
decayTime: number
sustainTime: number
sustainLevel: number
releaseTime: number
gateTime: number
peakLevel: number
epsilon: number
attackCurve: string
decayCurve: string
releaseCurve: string
valueAt(time: number = 0): number
applyTo(audioParam: AudioParam, playbackTime: number = 0): self
getWebAudioAPIMethods(playbackTime: number = 0): Array[]
clone(): ADSREnvelope
import ADSREnvelope from "adsr-envelope";
let audioContext = new AudioContext();
let oscillator = audioContext.createOscillator();
let gain = audioContext.createGain();
let adsr = new ADSREnvelope({
attackTime: 0.5,
decayTime: 0.25,
sustainLevel: 0.8,
releaseTime: 2.5,
gateTime: 6,
releaseCurve: "exp",
});
adsr.applyTo(gain.gain, audioContext.currentTime);
console.log(adsr.getWebAudioAPIMethods());
// [
// [ "setValueAtTime", 0, 0 ],
// [ "linearRampToValueAtTime", 1, 0.5 ],
// [ "linearRampToValueAtTime", 0.8, 0.75],
// [ "setValueAtTime", 0.8, 6 ],
// [ "exponentialRampToValueAtTime", 0.001, 8.5 ],
// ]
oscillator.start(audioContext.currentTime);
oscillator.stop(audioContext.currentTime + adsr.duration);
oscillator.connect(gain);
gain.connect(audioContext.destination);
import ADSREnvelope from "adsr-envelope";
let audioContext = new AudioContext();
let adsr = new ADSREnvelope({
attackTime: 0.5,
decayTime: 0.25,
sustainLevel: 0.8,
releaseTime: 2.5,
gateTime: 6,
releaseCurve: "exp",
});
let noteMap = {};
class Note {
constructor(audioContext, noteNumber, envelope) {
this.audioContext = audioContext;
this.noteNumber = noteNumber;
this.envelope = envelope;
this.startTime = 0;
this.oscillator = audioContext.createOscillator();
this.gain = audioContext.createGain();
this.oscillator.frequency.value = midicps(noteNumber);
this.oscillator.onended = () => {
this.oscillator.disconnect();
this.gain.disconnect();
};
this.oscillator.connect(this.gain);
this.gain.connect(audioContext.destination);
}
noteOn(playbackTime = this.audioContext.currentTime) {
this.startTime = playbackTime;
this.envelope.gateTime = Infinity;
this.envelope.applyTo(this.gain.gain, playbackTime);
this.oscillator.start(playbackTime);
}
noteOff(playbackTime = this.audioContext.currentTime) {
this.gain.gain.cancelScheduledValues(this.startTime);
this.envelope.gateTime = playbackTime - this.startTime;
this.envelope.applyTo(this.gain.gain, this.startTime);
this.oscillator.stop(this.startTime + this.envelope.duration);
}
}
midiKeyboard.on("noteOn", ({ noteNumber }) => {
if (noteMap[noteNumber]) {
noteMap[noteNumber].noteOff();
}
noteMap[noteNumber] = new Note(audioContext, noteNumber, adsr.clone());
noteMap[noteNumber].noteOn();
});
midiKeyboard.on("noteOff", ({ noteNumber }) => {
if (noteMap[noteNumber]) {
noteMap[noteNumber].noteOff();
}
noteMap[noteNumber] = null;
});
MIT
FAQs
adsr envelope
The npm package adsr-envelope receives a total of 7 weekly downloads. As such, adsr-envelope popularity was classified as not popular.
We found that adsr-envelope demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.