Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import { createWasmCodec } from "./wasm-base.js";
function mp3Magic(bytes: Uint8Array): boolean {
if (bytes.byteLength < 2) return false;
// MPEG audio sync word (11 bits) — 0xFFE mask on first two bytes
if (bytes[0] === 0xff && (bytes[1]! & 0xe0) === 0xe0) return true;
// ID3v2 prefix requires three bytes
if (
bytes.byteLength >= 3 &&
bytes[0] === 0x49 &&
bytes[1] === 0x44 &&
bytes[2] === 0x33
)
return true;
return false;
}
/** Lazy MP3 codec backed by `@audio/decode-mp3`. */
export const Mp3Codec = createWasmCodec({
name: "mp3",
extensions: ["mp3", "mpeg"],
mimeTypes: ["audio/mpeg", "audio/mp3"],
module: "@audio/decode-mp3",
magic: mp3Magic,
supportsEncode: true,
load: () =>
// @ts-expect-error optional dependency resolved at runtime
import("@audio/decode-mp3"),
});