sw-synth
Version:
Lightweight sound synthesizer designed for real-time user interaction using the Web Audio API
30 lines (29 loc) • 1.06 kB
TypeScript
/** Parameters for the ADSR envelope of the synth. */
export type VoiceBaseParams = {
/** Audio delay in seconds. Increase on Firefox to reduce pops. */
audioDelay: number;
/** Attack time in seconds. */
attackTime: number;
/** Decay time constant (exponential decay from 1 to `sustainLevel`). */
decayTime: number;
/** Steady state amplitude. */
sustainLevel: number;
/** Release time constant (exponential decay from `sustainLevel` to 0). */
releaseTime: number;
};
/**
* Oscillator with ADSR envelope.
* Represents a single "channel" of polyphony. Should be reused for multiple notes.
*/
export declare class VoiceBase {
age: number;
context: BaseAudioContext;
envelope: GainNode;
log: (msg: string) => void;
noteId: number;
voiceId: number;
lastNoteOff?: () => void;
constructor(context: BaseAudioContext, destination: AudioNode, log: (msg: string) => void);
noteOn(frequency: number, velocity: number, noteId: number, params: VoiceBaseParams): () => void;
dispose(): void;
}