2019-06-17 18:03:52 +00:00
|
|
|
// import {Offline} from "./Offline";
|
|
|
|
import { Compare } from "@tonejs/plot";
|
|
|
|
import { OfflineContext } from "Tone/core/context/OfflineContext";
|
2019-06-23 19:02:38 +00:00
|
|
|
import { getContext, setContext } from "Tone/core/Global";
|
2019-06-17 18:03:52 +00:00
|
|
|
import "./ToneAudioBuffer";
|
|
|
|
|
|
|
|
export async function CompareToFile(
|
|
|
|
callback, url: string,
|
|
|
|
threshold: number = 0.001,
|
|
|
|
RENDER_NEW: boolean = false,
|
|
|
|
duration: number = 0.1, channels: number = 1,
|
|
|
|
): Promise<void> {
|
|
|
|
// @ts-ignore
|
|
|
|
const prefix = window.__karma__ ? "/base/test/" : "../test/";
|
2019-06-23 19:02:38 +00:00
|
|
|
const origContext = getContext();
|
2019-06-17 18:03:52 +00:00
|
|
|
try {
|
2019-09-29 21:24:41 +00:00
|
|
|
await Compare.toFile(async context => {
|
2019-08-19 16:59:22 +00:00
|
|
|
const offlineContext = new OfflineContext(context);
|
2019-06-23 19:02:38 +00:00
|
|
|
setContext(offlineContext);
|
2019-09-29 21:24:41 +00:00
|
|
|
await callback(offlineContext);
|
|
|
|
// @ts-ignore
|
|
|
|
await offlineContext.workletsAreReady();
|
2019-09-19 20:55:09 +00:00
|
|
|
// @ts-ignore
|
2019-10-03 21:33:39 +00:00
|
|
|
await offlineContext._renderClock();
|
2019-07-15 19:36:03 +00:00
|
|
|
}, prefix + "audio/compare/" + url, threshold, RENDER_NEW, duration, channels, 44100);
|
2019-06-17 18:03:52 +00:00
|
|
|
} finally {
|
2019-06-23 19:02:38 +00:00
|
|
|
setContext(origContext);
|
2019-06-17 18:03:52 +00:00
|
|
|
}
|
|
|
|
}
|