UNPKG

1.8 kBTypeScriptView Raw
1import { Context } from "../context/Context.js";
2import { Seconds } from "../type/Units.js";
3import { ToneAudioBuffer } from "./ToneAudioBuffer.js";
4/**
5 * Wrapper around the OfflineAudioContext
6 * @category Core
7 * @example
8 * // generate a single channel, 0.5 second buffer
9 * const context = new Tone.OfflineContext(1, 0.5, 44100);
10 * const osc = new Tone.Oscillator({ context });
11 * context.render().then(buffer => {
12 * console.log(buffer.numberOfChannels, buffer.duration);
13 * });
14 */
15export declare class OfflineContext extends Context {
16 readonly name: string;
17 /**
18 * A private reference to the duration
19 */
20 private readonly _duration;
21 /**
22 * An artificial clock source
23 */
24 private _currentTime;
25 /**
26 * Private reference to the OfflineAudioContext.
27 */
28 protected _context: OfflineAudioContext;
29 readonly isOffline: boolean;
30 /**
31 * @param channels The number of channels to render
32 * @param duration The duration to render in seconds
33 * @param sampleRate the sample rate to render at
34 */
35 constructor(channels: number, duration: Seconds, sampleRate: number);
36 constructor(context: OfflineAudioContext);
37 /**
38 * Override the now method to point to the internal clock time
39 */
40 now(): Seconds;
41 /**
42 * Same as this.now()
43 */
44 get currentTime(): Seconds;
45 /**
46 * Render just the clock portion of the audio context.
47 */
48 private _renderClock;
49 /**
50 * Render the output of the OfflineContext
51 * @param asynchronous If the clock should be rendered asynchronously, which will not block the main thread, but be slightly slower.
52 */
53 render(asynchronous?: boolean): Promise<ToneAudioBuffer>;
54 /**
55 * Close the context
56 */
57 close(): Promise<void>;
58}