UNPKG

sw-synth

Version:

Lightweight sound synthesizer designed for real-time user interaction using the Web Audio API

61 lines (60 loc) 2.43 kB
import { VoiceBase, PitchBendRange } from './voice/base.js'; import { AperiodicVoice, AperiodicVoiceParams, OscillatorVoice, UnisonVoice, UnisonVoiceParams } from './voice/oscillator.js'; import { BufferVoice, BufferVoiceParams } from './voice/buffer.js'; export * from './voice/index.js'; /** Infers the `noteOn` parameter type for a given voice type. */ export type VoiceParamsOf<VoiceType extends VoiceBase> = Parameters<VoiceType['noteOn']>[3]; /** * Simple web audio synth of finite polyphony. */ export declare class Synth<VoiceType extends VoiceBase = OscillatorVoice> { audioContext: BaseAudioContext; destination: AudioNode; voiceParams?: VoiceParamsOf<VoiceType>; private pitchBendNode; pitchBend: AudioParam; log: (msg: string) => void; voices: VoiceType[]; constructor(audioContext: BaseAudioContext, destination: AudioNode, log?: (msg: string) => void); protected _newVoice(): VoiceType; setPolyphony(maxPolyphony: number): void; get maxPolyphony(): number; set maxPolyphony(value: number); protected _allocateVoice(): VoiceType | undefined; /** * Start playing a note at the specified frequency and velocity. * @param frequency Frequency in Hertz. * @param velocity Voice amplitude. Recommended range is 0 to 1. * @param pitchBendRange Asymmetric pitch bend range. Determines the effect of {@link Synth.pitchBend} on this note. * @returns A callback that stops playing the note. */ noteOn(frequency: number, velocity: number, pitchBendRange?: PitchBendRange): () => 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<UnisonVoice> { voiceParams?: UnisonVoiceParams; voices: UnisonVoice[]; protected _newVoice(): UnisonVoice; } /** * Web audio synth of finite polyphony that supports inharmonic timbres. */ export declare class AperiodicSynth extends Synth<AperiodicVoice> { voiceParams?: AperiodicVoiceParams; voices: AperiodicVoice[]; protected _newVoice(): AperiodicVoice; } /** * Web audio synth of finite polyphony with user-provided audio buffers. */ export declare class BufferSynth extends Synth<BufferVoice> { voiceParams?: BufferVoiceParams; voices: BufferVoice[]; protected _newVoice(): BufferVoice; }