47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
import { AudioDocument } from "../src/document/document.js";
|
|
|
|
describe("integration", () => {
|
|
it("full round-trip: construct, run edits, stream, read, clone, toJSON", {
|
|
timeout: 30000,
|
|
}, async () => {
|
|
const doc = new AudioDocument({
|
|
sampleRate: 48000,
|
|
channels: 2,
|
|
sourceLength: 2048,
|
|
pages: [
|
|
{
|
|
channelData: [
|
|
new Float32Array(2048).fill(0.5),
|
|
new Float32Array(2048).fill(0.25),
|
|
],
|
|
startSample: 0,
|
|
},
|
|
],
|
|
});
|
|
|
|
doc.run({ type: "trim", opts: { start: 0, end: 1024 } });
|
|
doc.run({ type: "gain", opts: { gain: 2 } });
|
|
|
|
expect(doc.length).toBe(1024);
|
|
|
|
const readResult = await doc.read(0, 512);
|
|
expect(readResult[0].length).toBe(512);
|
|
|
|
let streamTotal = 0;
|
|
for await (const block of doc.stream({ blockSize: 256 })) {
|
|
streamTotal += block[0].length;
|
|
}
|
|
expect(streamTotal).toBe(1024);
|
|
|
|
const cloned = doc.clone();
|
|
expect(cloned.length).toBe(doc.length);
|
|
expect(cloned.id).not.toBe(doc.id);
|
|
|
|
const json = doc.toJSON();
|
|
const restored = AudioDocument.fromJSON(json);
|
|
expect(restored.sampleRate).toBe(doc.sampleRate);
|
|
expect(restored.edits.length).toBe(doc.edits.length);
|
|
});
|
|
});
|