sw-synth
Version:
Lightweight sound synthesizer designed for real-time user interaction using the Web Audio API
56 lines (55 loc) • 1.94 kB
TypeScript
import { VoiceBaseParams, VoiceBase } from './voice/base';
import { AperiodicVoice, AperiodicVoiceParams, UnisonVoice, UnisonVoiceParams } from './voice/oscillator';
import { BufferVoice, BufferVoiceParams } from './voice/buffer';
export * from './voice';
/**
* Simple web audio synth of finite polyphony.
*/
export declare class Synth {
audioContext: BaseAudioContext;
destination: AudioNode;
voiceParams?: VoiceBaseParams;
log: (msg: string) => void;
voices: VoiceBase[];
constructor(audioContext: BaseAudioContext, destination: AudioNode, log?: (msg: string) => void);
protected _newVoice(): VoiceBase;
setPolyphony(maxPolyphony: number): void;
get maxPolyphony(): number;
set maxPolyphony(value: number);
protected _allocateVoice(): VoiceBase | undefined;
/**
* Start playing a note at the specified frequency and velocity.
* @param frequency Frequency in Hertz.
* @param velocity Voice amplitude. Recomended range from 0 to 1.
* @returns A callback that stops playing the note.
*/
noteOn(frequency: number, velocity: number): () => void;
/**
* Trigger panic and release all notes.
*/
allNotesOff(): void;
}
/**
* Web audio synth of finite polyphony where the voices are stacked in unison.
*/
export declare class UnisonSynth extends Synth {
voiceParams?: UnisonVoiceParams;
voices: UnisonVoice[];
protected _newVoice(): UnisonVoice;
}
/**
* Web audio synth of finite polyphony that supports inharmonic timbres.
*/
export declare class AperiodicSynth extends Synth {
voiceParams?: AperiodicVoiceParams;
voices: AperiodicVoice[];
protected _newVoice(): AperiodicVoice;
}
/**
* Web audio synth of finite polyphony with user-provided audio buffers.
*/
export declare class BufferSynth extends Synth {
voiceParams?: BufferVoiceParams;
voices: BufferVoice[];
protected _newVoice(): BufferVoice;
}