Tone.js/test/helper/Offline.ts

16 lines
468 B
TypeScript
Raw Normal View History

2019-04-12 14:37:47 +00:00
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;
}