Add WAVE demuxer

This commit is contained in:
Vanilagy
2025-01-07 20:57:16 +01:00
parent 48c9a225e2
commit 3041989cf3
5 changed files with 378 additions and 8 deletions
+40
View File
@@ -0,0 +1,40 @@
import { Reader } from '../reader';
export class RiffReader {
pos = 0;
littleEndian = true;
constructor(public reader: Reader) {}
readBytes(length: number) {
const { view, offset } = this.reader.getViewAndOffset(this.pos, this.pos + length);
this.pos += length;
return new Uint8Array(view.buffer, offset, length);
}
readU16() {
const { view, offset } = this.reader.getViewAndOffset(this.pos, this.pos + 2);
this.pos += 2;
return view.getUint16(offset, this.littleEndian);
}
readU32() {
const { view, offset } = this.reader.getViewAndOffset(this.pos, this.pos + 4);
this.pos += 4;
return view.getUint32(offset, this.littleEndian);
}
readAscii(length: number) {
const { view, offset } = this.reader.getViewAndOffset(this.pos, this.pos + length);
this.pos += length;
let str = '';
for (let i = 0; i < length; i++) {
str += String.fromCharCode(view.getUint8(offset + i));
}
return str;
}
}