function mp3FrameHeader
mp3FrameHeader(): Coder<Mp3FrameHeader>

Creates a coder for a 4-byte MP3 (MPEG audio) frame header.

Nothing is validated on encode or decode — frameSync, bitrate/sample-rate indices, and every other field are written and read exactly as given. Resolving bitrateIndex / samplingRateIndex to real values, computing frame length, and locating the next frame are all out of scope for v0.0.1.

Examples

Decode a known MPEG-1 Layer III header

import { assertEquals } from "@std/assert";
import {
  MP3_CHANNEL_MODE,
  MP3_FRAME_SYNC,
  MP3_LAYER,
  MP3_MPEG_VERSION,
  mp3FrameHeader,
} from "@binstruct/mp3";

// deno-fmt-ignore
const wire = new Uint8Array([0xff, 0xfb, 0x90, 0x00]);

const [decoded, read] = mp3FrameHeader().decode(wire);

assertEquals(read, 4);
assertEquals(decoded.frameSync, MP3_FRAME_SYNC);
assertEquals(decoded.mpegVersion, MP3_MPEG_VERSION.MPEG_1);
assertEquals(decoded.layer, MP3_LAYER.LAYER_3);
assertEquals(decoded.protectionAbsent, 1);
assertEquals(decoded.bitrateIndex, 9);
assertEquals(decoded.samplingRateIndex, 0);
assertEquals(decoded.channelMode, MP3_CHANNEL_MODE.STEREO);

Return Type

A coder for Mp3FrameHeader values.

Usage

import { mp3FrameHeader } from ".";