UNPKG

4.01 kBTypeScriptView Raw
1import { Source, SourceOptions } from "../Source.js";
2import { ToneAudioBuffer } from "../../core/context/ToneAudioBuffer.js";
3import { Cents, Positive, Seconds, Time } from "../../core/type/Units.js";
4interface GrainPlayerOptions extends SourceOptions {
5 onload: () => void;
6 onerror: (error: Error) => void;
7 reverse: boolean;
8 url?: ToneAudioBuffer | string | AudioBuffer;
9 overlap: Seconds;
10 grainSize: Seconds;
11 playbackRate: Positive;
12 detune: Cents;
13 loop: boolean;
14 loopStart: Time;
15 loopEnd: Time;
16}
17/**
18 * GrainPlayer implements [granular synthesis](https://en.wikipedia.org/wiki/Granular_synthesis).
19 * Granular Synthesis enables you to adjust pitch and playback rate independently. The grainSize is the
20 * amount of time each small chunk of audio is played for and the overlap is the
21 * amount of crossfading transition time between successive grains.
22 * @category Source
23 */
24export declare class GrainPlayer extends Source<GrainPlayerOptions> {
25 readonly name: string;
26 /**
27 * The audio buffer belonging to the player.
28 */
29 buffer: ToneAudioBuffer;
30 /**
31 * Create a repeating tick to schedule the grains.
32 */
33 private _clock;
34 /**
35 * Internal loopStart value
36 */
37 private _loopStart;
38 /**
39 * Internal loopStart value
40 */
41 private _loopEnd;
42 /**
43 * All of the currently playing BufferSources
44 */
45 private _activeSources;
46 /**
47 * Internal reference to the playback rate
48 */
49 private _playbackRate;
50 /**
51 * Internal grain size reference;
52 */
53 private _grainSize;
54 /**
55 * Internal overlap reference;
56 */
57 private _overlap;
58 /**
59 * Adjust the pitch independently of the playbackRate.
60 */
61 detune: Cents;
62 /**
63 * If the buffer should loop back to the loopStart when completed
64 */
65 loop: boolean;
66 /**
67 * @param url Either the AudioBuffer or the url from which to load the AudioBuffer
68 * @param onload The function to invoke when the buffer is loaded.
69 */
70 constructor(url?: string | AudioBuffer | ToneAudioBuffer, onload?: () => void);
71 constructor(options?: Partial<GrainPlayerOptions>);
72 static getDefaults(): GrainPlayerOptions;
73 /**
74 * Internal start method
75 */
76 protected _start(time?: Time, offset?: Time, duration?: Time): void;
77 /**
78 * Stop and then restart the player from the beginning (or offset)
79 * @param time When the player should start.
80 * @param offset The offset from the beginning of the sample to start at.
81 * @param duration How long the sample should play. If no duration is given,
82 * it will default to the full length of the sample (minus any offset)
83 */
84 restart(time?: Seconds, offset?: Time, duration?: Time): this;
85 protected _restart(time?: Seconds, offset?: Time, duration?: Time): void;
86 /**
87 * Internal stop method
88 */
89 protected _stop(time?: Time): void;
90 /**
91 * Invoked when the clock is stopped
92 */
93 private _onstop;
94 /**
95 * Invoked on each clock tick. scheduled a new grain at this time.
96 */
97 private _tick;
98 /**
99 * The playback rate of the sample
100 */
101 get playbackRate(): Positive;
102 set playbackRate(rate: Positive);
103 /**
104 * The loop start time.
105 */
106 get loopStart(): Time;
107 set loopStart(time: Time);
108 /**
109 * The loop end time.
110 */
111 get loopEnd(): Time;
112 set loopEnd(time: Time);
113 /**
114 * The direction the buffer should play in
115 */
116 get reverse(): boolean;
117 set reverse(rev: boolean);
118 /**
119 * The size of each chunk of audio that the
120 * buffer is chopped into and played back at.
121 */
122 get grainSize(): Time;
123 set grainSize(size: Time);
124 /**
125 * The duration of the cross-fade between successive grains.
126 */
127 get overlap(): Time;
128 set overlap(time: Time);
129 /**
130 * If all the buffer is loaded
131 */
132 get loaded(): boolean;
133 dispose(): this;
134}
135export {};