UNPKG

3.88 kBTypeScriptView Raw
1import { AudioRange, Degrees, Frequency, Seconds, Time } from "../../core/type/Units.js";
2import { Signal } from "../../signal/Signal.js";
3import { Source } from "../Source.js";
4import { PulseOscillatorOptions, ToneOscillatorInterface } from "./OscillatorInterface.js";
5export { PulseOscillatorOptions } from "./OscillatorInterface.js";
6/**
7 * PulseOscillator is an oscillator with control over pulse width,
8 * also known as the duty cycle. At 50% duty cycle (width = 0) the wave is
9 * a square wave.
10 * [Read more](https://wigglewave.wordpress.com/2014/08/16/pulse-waveforms-and-harmonics/).
11 * ```
12 * width = -0.25 width = 0.0 width = 0.25
13 *
14 * +-----+ +-------+ + +-------+ +-+
15 * | | | | | | |
16 * | | | | | | |
17 * +-+ +-------+ + +-------+ +-----+
18 *
19 *
20 * width = -0.5 width = 0.5
21 *
22 * +---+ +-------+ +---+
23 * | | | |
24 * | | | |
25 * +---+ +-------+ +---+
26 *
27 *
28 * width = -0.75 width = 0.75
29 *
30 * +-+ +-------+ +-----+
31 * | | | |
32 * | | | |
33 * +-----+ +-------+ +-+
34 * ```
35 * @example
36 * return Tone.Offline(() => {
37 * const pulse = new Tone.PulseOscillator(50, 0.4).toDestination().start();
38 * }, 0.1, 1);
39 * @category Source
40 */
41export declare class PulseOscillator extends Source<PulseOscillatorOptions> implements ToneOscillatorInterface {
42 readonly name: string;
43 /**
44 * The width of the pulse.
45 * @example
46 * return Tone.Offline(() => {
47 * const pulse = new Tone.PulseOscillator(20, 0.8).toDestination().start();
48 * }, 0.1, 1);
49 */
50 readonly width: Signal<"audioRange">;
51 /**
52 * gate the width amount
53 */
54 private _widthGate;
55 /**
56 * the sawtooth oscillator
57 */
58 private _triangle;
59 /**
60 * The frequency control.
61 */
62 readonly frequency: Signal<"frequency">;
63 /**
64 * The detune in cents.
65 */
66 readonly detune: Signal<"cents">;
67 /**
68 * Threshold the signal to turn it into a square
69 */
70 private _thresh;
71 /**
72 * @param frequency The frequency of the oscillator
73 * @param width The width of the pulse
74 */
75 constructor(frequency?: Frequency, width?: AudioRange);
76 constructor(options?: Partial<PulseOscillatorOptions>);
77 static getDefaults(): PulseOscillatorOptions;
78 /**
79 * start the oscillator
80 */
81 protected _start(time: Time): void;
82 /**
83 * stop the oscillator
84 */
85 protected _stop(time: Time): void;
86 protected _restart(time: Seconds): void;
87 /**
88 * The phase of the oscillator in degrees.
89 */
90 get phase(): Degrees;
91 set phase(phase: Degrees);
92 /**
93 * The type of the oscillator. Always returns "pulse".
94 */
95 get type(): "pulse";
96 /**
97 * The baseType of the oscillator. Always returns "pulse".
98 */
99 get baseType(): "pulse";
100 /**
101 * The partials of the waveform. Cannot set partials for this waveform type
102 */
103 get partials(): number[];
104 /**
105 * No partials for this waveform type.
106 */
107 get partialCount(): number;
108 /**
109 * *Internal use* The carrier oscillator type is fed through the
110 * waveshaper node to create the pulse. Using different carrier oscillators
111 * changes oscillator's behavior.
112 */
113 set carrierType(type: "triangle" | "sine");
114 asArray(length?: number): Promise<Float32Array>;
115 /**
116 * Clean up method.
117 */
118 dispose(): this;
119}