-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModWorkletProcessor.ts
68 lines (62 loc) · 1.44 KB
/
ModWorkletProcessor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Protracker } from "./Protracker";
export class ModWorkletProcessor
extends AudioWorkletProcessor
implements AudioWorkletProcessorImpl
{
player: Protracker;
constructor({
numberOfInputs,
numberOfOutputs,
processorOptions,
}: {
numberOfInputs: number;
numberOfOutputs: number;
processorOptions: {
buffer: Uint8Array;
ext: string;
options?: {
autoplay?: boolean;
repeat?: boolean;
};
};
}) {
super();
const { buffer, ext, options } = processorOptions;
switch (ext) {
case "mod":
this.player = new Protracker();
break;
// case "s3m":
// player = new Screamtracker();
// break;
// case "xm":
// player = new Fasttracker();
// break;
default:
throw new Error(`Unsupported file extension ${ext}`);
}
if (this.player.parse(buffer)) {
this.player.initialize();
this.player.flags = 1 + 2;
if (options?.repeat) {
this.player.repeat = true;
}
if (options?.autoplay) {
this.player.play();
}
} else {
throw new Error("Unable to parse buffer");
}
}
process(
inputs: Float32Array[][],
outputs: Float32Array[][],
parameters: Record<string, Float32Array>
) {
this.player.mix(outputs[0]);
return true;
}
}
export function register() {
registerProcessor("ModWorkletProcessor", ModWorkletProcessor);
}