sw-synth
Version:
Lightweight sound synthesizer designed for real-time user interaction using the Web Audio API
45 lines (44 loc) • 2.71 kB
TypeScript
import { AperiodicOscillator, AperiodicWave, UnisonOscillator } from 'aperiodic-oscillator';
import { VoiceBase, VoiceBaseParams } from './base';
export { AperiodicWave } from 'aperiodic-oscillator';
/** Parameters for the timbre and ADSR envelope of the synth. */
export interface OscillatorVoiceParams extends VoiceBaseParams {
/** One of `"sine"`, `"sawtooth"`, `"triangle"`, `"square"` or `"custom"` if `periodicWave` is set. */
type: OscillatorType;
/** Custom waveform. */
periodicWave?: PeriodicWave;
}
/** Parameters for the timbre, ADSR and voice stack of the synth.*/
export interface UnisonVoiceParams extends OscillatorVoiceParams {
/** Number of voices to play in unison. */
stackSize: number;
/** Spread of voice frequencies in ±Hertz. */
spread: number;
}
/** Parameters for the inharmonic timbre and ADSR of the synth. See [aperiodic-oscillator](https://xenharmonic-devs.github.io/aperiodic-oscillator/index.html) documentation for [AperiodicWave](https://xenharmonic-devs.github.io/aperiodic-oscillator/classes/AperiodicWave.html). */
export interface AperiodicVoiceParams extends VoiceBaseParams {
/** [AperiodicWave](https://xenharmonic-devs.github.io/aperiodic-oscillator/classes/AperiodicWave.html) representing an inharmonic timbre. */
aperiodicWave: AperiodicWave;
}
export declare function defaultParams(): OscillatorVoiceParams;
export declare function defaultUnisonParams(): UnisonVoiceParams;
export declare class OscillatorVoiceBase extends VoiceBase {
oscillator: OscillatorNode;
constructor(context: BaseAudioContext, destination: AudioNode, log: (msg: string) => void, oscillatorClass: typeof OscillatorNode);
noteOn(frequency: number, velocity: number, noteId: number, params: VoiceBaseParams): () => void;
dispose(): void;
}
export declare class OscillatorVoice extends OscillatorVoiceBase {
constructor(audioContext: BaseAudioContext, destination: AudioNode, log: (msg: string) => void);
noteOn(frequency: number, velocity: number, noteId: number, params: OscillatorVoiceParams): () => void;
}
export declare class UnisonVoice extends OscillatorVoiceBase {
oscillator: UnisonOscillator;
constructor(audioContext: BaseAudioContext, destination: AudioNode, log: (msg: string) => void);
noteOn(frequency: number, velocity: number, noteId: number, params: UnisonVoiceParams): () => void;
}
export declare class AperiodicVoice extends OscillatorVoiceBase {
oscillator: AperiodicOscillator;
constructor(audioContext: BaseAudioContext, destination: AudioNode, log: (msg: string) => void);
noteOn(frequency: number, velocity: number, noteId: number, params: AperiodicVoiceParams): () => void;
}