1 | import { Tone } from "../Tone.js";
|
2 | import { Samples, Seconds } from "../type/Units.js";
|
3 | interface ToneAudioBufferOptions {
|
4 | url?: string | AudioBuffer | ToneAudioBuffer;
|
5 | reverse: boolean;
|
6 | onload: (buffer?: ToneAudioBuffer) => void;
|
7 | onerror: (error: Error) => void;
|
8 | }
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | export declare class ToneAudioBuffer extends Tone {
|
20 | readonly name: string;
|
21 | |
22 |
|
23 |
|
24 | private _buffer?;
|
25 | |
26 |
|
27 |
|
28 | private _reversed;
|
29 | |
30 |
|
31 |
|
32 | onload: (buffer: ToneAudioBuffer) => void;
|
33 | |
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | constructor(url?: string | ToneAudioBuffer | AudioBuffer, onload?: (buffer: ToneAudioBuffer) => void, onerror?: (error: Error) => void);
|
42 | constructor(options?: Partial<ToneAudioBufferOptions>);
|
43 | static getDefaults(): ToneAudioBufferOptions;
|
44 | /**
|
45 | * The sample rate of the AudioBuffer
|
46 | */
|
47 | get sampleRate(): number;
|
48 | /**
|
49 | * Pass in an AudioBuffer or ToneAudioBuffer to set the value of this buffer.
|
50 | */
|
51 | set(buffer: AudioBuffer | ToneAudioBuffer): this;
|
52 | /**
|
53 | * The audio buffer stored in the object.
|
54 | */
|
55 | get(): AudioBuffer | undefined;
|
56 | /**
|
57 | * Makes an fetch request for the selected url then decodes the file as an audio buffer.
|
58 | * Invokes the callback once the audio buffer loads.
|
59 | * @param url The url of the buffer to load. filetype support depends on the browser.
|
60 | * @returns A Promise which resolves with this ToneAudioBuffer
|
61 | */
|
62 | load(url: string): Promise<this>;
|
63 | /**
|
64 | * clean up
|
65 | */
|
66 | dispose(): this;
|
67 | /**
|
68 | * Set the audio buffer from the array.
|
69 | * To create a multichannel AudioBuffer, pass in a multidimensional array.
|
70 | * @param array The array to fill the audio buffer
|
71 | */
|
72 | fromArray(array: Float32Array | Float32Array[]): this;
|
73 | /**
|
74 | * Sums multiple channels into 1 channel
|
75 | * @param chanNum Optionally only copy a single channel from the array.
|
76 | */
|
77 | toMono(chanNum?: number): this;
|
78 | /**
|
79 | * Get the buffer as an array. Single channel buffers will return a 1-dimensional
|
80 | * Float32Array, and multichannel buffers will return multidimensional arrays.
|
81 | * @param channel Optionally only copy a single channel from the array.
|
82 | */
|
83 | toArray(channel?: number): Float32Array | Float32Array[];
|
84 | /**
|
85 | * Returns the Float32Array representing the PCM audio data for the specific channel.
|
86 | * @param channel The channel number to return
|
87 | * @return The audio as a TypedArray
|
88 | */
|
89 | getChannelData(channel: number): Float32Array;
|
90 | /**
|
91 | * Cut a subsection of the array and return a buffer of the
|
92 | * subsection. Does not modify the original buffer
|
93 | * @param start The time to start the slice
|
94 | * @param end The end time to slice. If none is given will default to the end of the buffer
|
95 | */
|
96 | slice(start: Seconds, end?: Seconds): ToneAudioBuffer;
|
97 | /**
|
98 | * Reverse the buffer.
|
99 | */
|
100 | private _reverse;
|
101 | /**
|
102 | * If the buffer is loaded or not
|
103 | */
|
104 | get loaded(): boolean;
|
105 | /**
|
106 | * The duration of the buffer in seconds.
|
107 | */
|
108 | get duration(): Seconds;
|
109 | /**
|
110 | * The length of the buffer in samples
|
111 | */
|
112 | get length(): Samples;
|
113 | /**
|
114 | * The number of discrete audio channels. Returns 0 if no buffer is loaded.
|
115 | */
|
116 | get numberOfChannels(): number;
|
117 | /**
|
118 | * Reverse the buffer.
|
119 | */
|
120 | get reverse(): boolean;
|
121 | set reverse(rev: boolean);
|
122 | /**
|
123 | * A path which is prefixed before every url.
|
124 | */
|
125 | static baseUrl: string;
|
126 | /**
|
127 | * Create a ToneAudioBuffer from the array. To create a multichannel AudioBuffer,
|
128 | * pass in a multidimensional array.
|
129 | * @param array The array to fill the audio buffer
|
130 | * @return A ToneAudioBuffer created from the array
|
131 | */
|
132 | static fromArray(array: Float32Array | Float32Array[]): ToneAudioBuffer;
|
133 | /**
|
134 | * Creates a ToneAudioBuffer from a URL, returns a promise which resolves to a ToneAudioBuffer
|
135 | * @param url The url to load.
|
136 | * @return A promise which resolves to a ToneAudioBuffer
|
137 | */
|
138 | static fromUrl(url: string): Promise<ToneAudioBuffer>;
|
139 | /**
|
140 | * All of the downloads
|
141 | */
|
142 | static downloads: Array<Promise<void>>;
|
143 | /**
|
144 | * Loads a url using fetch and returns the AudioBuffer.
|
145 | */
|
146 | static load(url: string): Promise<AudioBuffer>;
|
147 | /**
|
148 | * Checks a url's extension to see if the current browser can play that file type.
|
149 | * @param url The url/extension to test
|
150 | * @return If the file extension can be played
|
151 | * @static
|
152 | * @example
|
153 | * Tone.ToneAudioBuffer.supportsType("wav"); // returns true
|
154 | * Tone.ToneAudioBuffer.supportsType("path/to/file.wav"); // returns true
|
155 | */
|
156 | static supportsType(url: string): boolean;
|
157 | /**
|
158 | * Returns a Promise which resolves when all of the buffers have loaded
|
159 | */
|
160 | static loaded(): Promise<void>;
|
161 | }
|
162 | export {};
|