UNPKG

4.08 kBTypeScriptView Raw
1import { AudioRange, Degrees, Frequency, Time } from "../../core/type/Units.js";
2import { Signal } from "../../signal/Signal.js";
3import { Source } from "../Source.js";
4import { ToneOscillatorConstructorOptions, ToneOscillatorInterface, ToneOscillatorOptions, ToneOscillatorType } from "./OscillatorInterface.js";
5export { ToneOscillatorOptions, ToneOscillatorType, } from "./OscillatorInterface.js";
6/**
7 * Oscillator supports a number of features including
8 * phase rotation, multiple oscillator types (see Oscillator.type),
9 * and Transport syncing (see Oscillator.syncFrequency).
10 *
11 * @example
12 * // make and start a 440hz sine tone
13 * const osc = new Tone.Oscillator(440, "sine").toDestination().start();
14 * @category Source
15 */
16export declare class Oscillator extends Source<ToneOscillatorOptions> implements ToneOscillatorInterface {
17 readonly name: string;
18 /**
19 * the main oscillator
20 */
21 private _oscillator;
22 /**
23 * The frequency control.
24 */
25 frequency: Signal<"frequency">;
26 /**
27 * The detune control signal.
28 */
29 detune: Signal<"cents">;
30 /**
31 * the periodic wave
32 */
33 private _wave?;
34 /**
35 * The partials of the oscillator
36 */
37 private _partials;
38 /**
39 * The number of partials to limit or extend the periodic wave by
40 */
41 private _partialCount;
42 /**
43 * the phase of the oscillator between 0 - 360
44 */
45 private _phase;
46 /**
47 * the type of the oscillator
48 */
49 private _type;
50 /**
51 * @param frequency Starting frequency
52 * @param type The oscillator type. Read more about type below.
53 */
54 constructor(frequency?: Frequency, type?: ToneOscillatorType);
55 constructor(options?: Partial<ToneOscillatorConstructorOptions>);
56 static getDefaults(): ToneOscillatorOptions;
57 /**
58 * start the oscillator
59 */
60 protected _start(time?: Time): void;
61 /**
62 * stop the oscillator
63 */
64 protected _stop(time?: Time): void;
65 /**
66 * Restart the oscillator. Does not stop the oscillator, but instead
67 * just cancels any scheduled 'stop' from being invoked.
68 */
69 protected _restart(time?: Time): this;
70 /**
71 * Sync the signal to the Transport's bpm. Any changes to the transports bpm,
72 * will also affect the oscillators frequency.
73 * @example
74 * const osc = new Tone.Oscillator().toDestination().start();
75 * osc.frequency.value = 440;
76 * // the ratio between the bpm and the frequency will be maintained
77 * osc.syncFrequency();
78 * // double the tempo
79 * Tone.Transport.bpm.value *= 2;
80 * // the frequency of the oscillator is doubled to 880
81 */
82 syncFrequency(): this;
83 /**
84 * Unsync the oscillator's frequency from the Transport.
85 * @see {@link syncFrequency}
86 */
87 unsyncFrequency(): this;
88 /**
89 * Cache the periodic waves to avoid having to redo computations
90 */
91 private static _periodicWaveCache;
92 /**
93 * Get a cached periodic wave. Avoids having to recompute
94 * the oscillator values when they have already been computed
95 * with the same values.
96 */
97 private _getCachedPeriodicWave;
98 get type(): ToneOscillatorType;
99 set type(type: ToneOscillatorType);
100 get baseType(): OscillatorType;
101 set baseType(baseType: OscillatorType);
102 get partialCount(): number;
103 set partialCount(p: number);
104 /**
105 * Returns the real and imaginary components based
106 * on the oscillator type.
107 * @returns [real: Float32Array, imaginary: Float32Array]
108 */
109 private _getRealImaginary;
110 /**
111 * Compute the inverse FFT for a given phase.
112 */
113 private _inverseFFT;
114 /**
115 * Returns the initial value of the oscillator when stopped.
116 * E.g. a "sine" oscillator with phase = 90 would return an initial value of -1.
117 */
118 getInitialValue(): AudioRange;
119 get partials(): number[];
120 set partials(partials: number[]);
121 get phase(): Degrees;
122 set phase(phase: Degrees);
123 asArray(length?: number): Promise<Float32Array>;
124 dispose(): this;
125}