2
0
Fork 0
mirror of https://github.com/Tonejs/Tone.js synced 2025-01-19 15:23:55 +00:00
Tone.js/test/helper/Offline.ts
2019-04-12 10:37:47 -04:00

15 lines
468 B
TypeScript

import { Offline as PlotOffline } from "@tonejs/plot";
import { getContext, setContext } from "../../Tone/core/Global";
export async function Offline(
callback: (context: BaseAudioContext) => Promise<void> | void,
duration = 0.1, channels = 1,
) {
const buffer = await PlotOffline(async context => {
const originalContext = getContext();
setContext(context);
await callback(context);
setContext(originalContext);
}, duration, channels);
return buffer;
}