UNPKG

1.79 kBTypeScriptView Raw
1import { Seconds } from "../type/Units.js";
2import { OfflineContext } from "./OfflineContext.js";
3import { ToneAudioBuffer } from "./ToneAudioBuffer.js";
4import "./Destination.js";
5import "./Listener.js";
6/**
7 * Generate a buffer by rendering all of the Tone.js code within the callback using the OfflineAudioContext.
8 * The OfflineAudioContext is capable of rendering much faster than real time in many cases.
9 * The callback function also passes in an offline instance of {@link Context} which can be used
10 * to schedule events along the Transport.
11 * @param callback All Tone.js nodes which are created and scheduled within this callback are recorded into the output Buffer.
12 * @param duration the amount of time to record for.
13 * @return The promise which is invoked with the ToneAudioBuffer of the recorded output.
14 * @example
15 * // render 2 seconds of the oscillator
16 * Tone.Offline(() => {
17 * // only nodes created in this callback will be recorded
18 * const oscillator = new Tone.Oscillator().toDestination().start(0);
19 * }, 2).then((buffer) => {
20 * // do something with the output buffer
21 * console.log(buffer);
22 * });
23 * @example
24 * // can also schedule events along the Transport
25 * // using the passed in Offline Transport
26 * Tone.Offline(({ transport }) => {
27 * const osc = new Tone.Oscillator().toDestination();
28 * transport.schedule(time => {
29 * osc.start(time).stop(time + 0.1);
30 * }, 1);
31 * // make sure to start the transport
32 * transport.start(0.2);
33 * }, 4).then((buffer) => {
34 * // do something with the output buffer
35 * console.log(buffer);
36 * });
37 * @category Core
38 */
39export declare function Offline(callback: (context: OfflineContext) => Promise<void> | void, duration: Seconds, channels?: number, sampleRate?: number): Promise<ToneAudioBuffer>;