UNPKG

6.57 kBTypeScriptView Raw
1import { Cents, Degrees, Frequency, Seconds, Time } from "../../core/type/Units.js";
2import { Signal } from "../../signal/Signal.js";
3import { Source } from "../Source.js";
4import { AMOscillator } from "./AMOscillator.js";
5import { FatOscillator } from "./FatOscillator.js";
6import { FMOscillator } from "./FMOscillator.js";
7import { Oscillator } from "./Oscillator.js";
8import { OmniOscillatorOptions, OmniOscillatorType, ToneOscillatorInterface, ToneOscillatorType } from "./OscillatorInterface.js";
9import { PulseOscillator } from "./PulseOscillator.js";
10import { PWMOscillator } from "./PWMOscillator.js";
11export { OmniOscillatorOptions } from "./OscillatorInterface.js";
12/**
13 * All of the oscillator types that OmniOscillator can take on
14 */
15type AnyOscillator = Oscillator | PWMOscillator | PulseOscillator | FatOscillator | AMOscillator | FMOscillator;
16/**
17 * All of the Oscillator constructor types mapped to their name.
18 */
19interface OmniOscillatorSource {
20 fm: FMOscillator;
21 am: AMOscillator;
22 pwm: PWMOscillator;
23 pulse: PulseOscillator;
24 oscillator: Oscillator;
25 fat: FatOscillator;
26}
27/**
28 * The available oscillator types.
29 */
30export type OmniOscSourceType = keyof OmniOscillatorSource;
31type IsAmOrFmOscillator<Osc, Ret> = Osc extends AMOscillator ? Ret : Osc extends FMOscillator ? Ret : undefined;
32type IsFatOscillator<Osc, Ret> = Osc extends FatOscillator ? Ret : undefined;
33type IsPWMOscillator<Osc, Ret> = Osc extends PWMOscillator ? Ret : undefined;
34type IsPulseOscillator<Osc, Ret> = Osc extends PulseOscillator ? Ret : undefined;
35type IsFMOscillator<Osc, Ret> = Osc extends FMOscillator ? Ret : undefined;
36/**
37 * OmniOscillator aggregates all of the oscillator types into one.
38 * @example
39 * return Tone.Offline(() => {
40 * const omniOsc = new Tone.OmniOscillator("C#4", "pwm").toDestination().start();
41 * }, 0.1, 1);
42 * @category Source
43 */
44export declare class OmniOscillator<OscType extends AnyOscillator> extends Source<OmniOscillatorOptions> implements Omit<ToneOscillatorInterface, "type"> {
45 readonly name: string;
46 readonly frequency: Signal<"frequency">;
47 readonly detune: Signal<"cents">;
48 /**
49 * The oscillator that can switch types
50 */
51 private _oscillator;
52 /**
53 * the type of the oscillator source
54 */
55 private _sourceType;
56 /**
57 * @param frequency The initial frequency of the oscillator.
58 * @param type The type of the oscillator.
59 */
60 constructor(frequency?: Frequency, type?: OmniOscillatorType);
61 constructor(options?: Partial<OmniOscillatorOptions>);
62 static getDefaults(): OmniOscillatorOptions;
63 /**
64 * start the oscillator
65 */
66 protected _start(time: Time): void;
67 /**
68 * start the oscillator
69 */
70 protected _stop(time: Time): void;
71 protected _restart(time: Seconds): this;
72 /**
73 * The type of the oscillator. Can be any of the basic types: sine, square, triangle, sawtooth. Or
74 * prefix the basic types with "fm", "am", or "fat" to use the FMOscillator, AMOscillator or FatOscillator
75 * types. The oscillator could also be set to "pwm" or "pulse". All of the parameters of the
76 * oscillator's class are accessible when the oscillator is set to that type, but throws an error
77 * when it's not.
78 * @example
79 * const omniOsc = new Tone.OmniOscillator().toDestination().start();
80 * omniOsc.type = "pwm";
81 * // modulationFrequency is parameter which is available
82 * // only when the type is "pwm".
83 * omniOsc.modulationFrequency.value = 0.5;
84 */
85 get type(): OmniOscillatorType;
86 set type(type: OmniOscillatorType);
87 /**
88 * The value is an empty array when the type is not "custom".
89 * This is not available on "pwm" and "pulse" oscillator types.
90 * @see {@link Oscillator.partials}
91 */
92 get partials(): number[];
93 set partials(partials: number[]);
94 get partialCount(): number;
95 set partialCount(partialCount: number);
96 set(props: Partial<OmniOscillatorOptions>): this;
97 /**
98 * connect the oscillator to the frequency and detune signals
99 */
100 private _createNewOscillator;
101 get phase(): Degrees;
102 set phase(phase: Degrees);
103 /**
104 * The source type of the oscillator.
105 * @example
106 * const omniOsc = new Tone.OmniOscillator(440, "fmsquare");
107 * console.log(omniOsc.sourceType); // 'fm'
108 */
109 get sourceType(): OmniOscSourceType;
110 set sourceType(sType: OmniOscSourceType);
111 private _getOscType;
112 /**
113 * The base type of the oscillator.
114 * @see {@link Oscillator.baseType}
115 * @example
116 * const omniOsc = new Tone.OmniOscillator(440, "fmsquare4");
117 * console.log(omniOsc.sourceType, omniOsc.baseType, omniOsc.partialCount);
118 */
119 get baseType(): OscillatorType | "pwm" | "pulse";
120 set baseType(baseType: OscillatorType | "pwm" | "pulse");
121 /**
122 * The width of the oscillator when sourceType === "pulse".
123 * @see {@link PWMOscillator}
124 */
125 get width(): IsPulseOscillator<OscType, Signal<"audioRange">>;
126 /**
127 * The number of detuned oscillators when sourceType === "fat".
128 * @see {@link FatOscillator.count}
129 */
130 get count(): IsFatOscillator<OscType, number>;
131 set count(count: IsFatOscillator<OscType, number>);
132 /**
133 * The detune spread between the oscillators when sourceType === "fat".
134 * @see {@link FatOscillator.count}
135 */
136 get spread(): IsFatOscillator<OscType, Cents>;
137 set spread(spread: IsFatOscillator<OscType, Cents>);
138 /**
139 * The type of the modulator oscillator. Only if the oscillator is set to "am" or "fm" types.
140 * @see {@link AMOscillator} or {@link FMOscillator}
141 */
142 get modulationType(): IsAmOrFmOscillator<OscType, ToneOscillatorType>;
143 set modulationType(mType: IsAmOrFmOscillator<OscType, ToneOscillatorType>);
144 /**
145 * The modulation index when the sourceType === "fm"
146 * @see {@link FMOscillator}.
147 */
148 get modulationIndex(): IsFMOscillator<OscType, Signal<"positive">>;
149 /**
150 * Harmonicity is the frequency ratio between the carrier and the modulator oscillators.
151 * @see {@link AMOscillator} or {@link FMOscillator}
152 */
153 get harmonicity(): IsAmOrFmOscillator<OscType, Signal<"positive">>;
154 /**
155 * The modulationFrequency Signal of the oscillator when sourceType === "pwm"
156 * see {@link PWMOscillator}
157 * @min 0.1
158 * @max 5
159 */
160 get modulationFrequency(): IsPWMOscillator<OscType, Signal<"frequency">>;
161 asArray(length?: number): Promise<Float32Array>;
162 dispose(): this;
163}