From 41c51b8bdb9c8e9fa4a7d56f260d594739d4107e Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Mon, 30 Oct 2023 23:08:45 +0100 Subject: Updated 35 files and added 28 files (automated) --- assets/js/stella.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 assets/js/stella.js (limited to 'assets/js/stella.js') 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 -- cgit