UNPKG

3.16 kBTypeScriptView Raw
1import { Param } from "../../core/context/Param.js";
2import { ToneAudioBuffer } from "../../core/context/ToneAudioBuffer.js";
3import { GainFactor, Positive, Seconds, Time } from "../../core/type/Units.js";
4import { OneShotSource, OneShotSourceCurve, OneShotSourceOptions } from "../OneShotSource.js";
5export type ToneBufferSourceCurve = OneShotSourceCurve;
6export interface ToneBufferSourceOptions extends OneShotSourceOptions {
7 url: string | AudioBuffer | ToneAudioBuffer;
8 curve: ToneBufferSourceCurve;
9 playbackRate: Positive;
10 fadeIn: Time;
11 fadeOut: Time;
12 loopStart: Time;
13 loopEnd: Time;
14 loop: boolean;
15 onload: () => void;
16 onerror: (error: Error) => void;
17}
18/**
19 * Wrapper around the native BufferSourceNode.
20 * @category Source
21 */
22export declare class ToneBufferSource extends OneShotSource<ToneBufferSourceOptions> {
23 readonly name: string;
24 /**
25 * The oscillator
26 */
27 private _source;
28 protected _internalChannels: AudioBufferSourceNode[];
29 /**
30 * The frequency of the oscillator
31 */
32 readonly playbackRate: Param<"positive">;
33 /**
34 * The private instance of the buffer object
35 */
36 private _buffer;
37 /**
38 * indicators if the source has started/stopped
39 */
40 private _sourceStarted;
41 private _sourceStopped;
42 /**
43 * @param url The buffer to play or url to load
44 * @param onload The callback to invoke when the buffer is done playing.
45 */
46 constructor(url?: ToneAudioBuffer | AudioBuffer | string, onload?: () => void);
47 constructor(options?: Partial<ToneBufferSourceOptions>);
48 static getDefaults(): ToneBufferSourceOptions;
49 /**
50 * The fadeIn time of the amplitude envelope.
51 */
52 get fadeIn(): Time;
53 set fadeIn(t: Time);
54 /**
55 * The fadeOut time of the amplitude envelope.
56 */
57 get fadeOut(): Time;
58 set fadeOut(t: Time);
59 /**
60 * The curve applied to the fades, either "linear" or "exponential"
61 */
62 get curve(): ToneBufferSourceCurve;
63 set curve(t: ToneBufferSourceCurve);
64 /**
65 * Start the buffer
66 * @param time When the player should start.
67 * @param offset The offset from the beginning of the sample to start at.
68 * @param duration How long the sample should play. If no duration is given, it will default to the full length of the sample (minus any offset)
69 * @param gain The gain to play the buffer back at.
70 */
71 start(time?: Time, offset?: Time, duration?: Time, gain?: GainFactor): this;
72 protected _stopSource(time?: Seconds): void;
73 /**
74 * If loop is true, the loop will start at this position.
75 */
76 get loopStart(): Time;
77 set loopStart(loopStart: Time);
78 /**
79 * If loop is true, the loop will end at this position.
80 */
81 get loopEnd(): Time;
82 set loopEnd(loopEnd: Time);
83 /**
84 * The audio buffer belonging to the player.
85 */
86 get buffer(): ToneAudioBuffer;
87 set buffer(buffer: ToneAudioBuffer);
88 /**
89 * If the buffer should loop once it's over.
90 */
91 get loop(): boolean;
92 set loop(loop: boolean);
93 /**
94 * Clean up.
95 */
96 dispose(): this;
97}