summaryrefslogtreecommitdiff
path: root/assets/js/stella.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/js/stella.js')
-rw-r--r--assets/js/stella.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/assets/js/stella.js b/assets/js/stella.js
new file mode 100644
index 0000000..aa6bbaa
--- /dev/null
+++ b/assets/js/stella.js
@@ -0,0 +1,32 @@
+class Stella {
+ arrayBuffer;
+ metadata;
+ stems;
+
+ constructor(ab) {
+ this.arrayBuffer = ab;
+ this.metadata = JSON.parse(new TextDecoder("utf-8").decode(pako.inflateRaw(ab.slice(8, 512))).trim());
+ this.stems = {};
+ this.urls = {};
+
+ for (let stem of Object.keys(this.metadata.stems)) {
+ this.stems[stem] = pako.inflateRaw(ab.slice(this.metadata.stems[stem][0], this.metadata.stems[stem][0] + this.metadata.stems[stem][1]));
+ this.urls[stem] = URL.createObjectURL(new Blob([this.stems[stem]], { type: "audio/flac" }));
+ }
+ }
+
+ destroy() {
+ for (let url of Object.values(this.urls)) {
+ URL.revokeObjectURL(url);
+ }
+
+ this.urls = null;
+ this.stems = null;
+ this.arrayBuffer = null;
+ }
+
+ static async build(url) {
+ let buffer = await (await fetch(url)).arrayBuffer();
+ return new Stella(buffer);
+ }
+} \ No newline at end of file