import type { IOStream } from "../toolkit/ioStream.js"; import type { offset_t } from "../toolkit/types.js"; /** * MPEG audio version as indicated by bits 19-20 of the frame header. */ export declare enum MpegVersion { /** MPEG Version 1 (ISO/IEC 11172-3). */ Version1 = 0, /** MPEG Version 2 (ISO/IEC 13818-3). */ Version2 = 1, /** MPEG Version 2.5 (unofficial extension for very low bitrates). */ Version2_5 = 2, /** MPEG Version 4 / ADTS (AAC). */ Version4 = 3 } /** * MPEG channel mode as indicated by bits 6-7 of the third header byte. */ export declare enum ChannelMode { /** Stereo (two independent audio channels). */ Stereo = 0, /** Joint Stereo (stereo with side-information coding). */ JointStereo = 1, /** Dual Channel (two independent mono channels). */ DualChannel = 2, /** Single Channel (mono). */ SingleChannel = 3 } /** * Parser for a single MPEG audio frame header (4 bytes). * * When `checkLength` is true the parser also verifies that a second valid * frame header with matching version / layer / sample-rate exists at the * expected position (`offset + frameLength`). */ export declare class MpegHeader { /** Whether the parsed header represents a valid MPEG frame. */ private _isValid; /** MPEG version extracted from the frame header. */ private _version; /** MPEG layer number (1, 2, or 3); 0 for ADTS streams. */ private _layer; /** Whether CRC protection is enabled (bit 0 of second header byte, inverted). */ private _protectionEnabled; /** Audio bitrate in kbps as looked up from the bitrate table. */ private _bitrate; /** Sample rate in Hz as looked up from the sample-rate table. */ private _sampleRate; /** Whether the frame includes a padding slot to align to byte boundaries. */ private _isPadded; /** Channel mode as encoded in bits 7-6 of the fourth header byte. */ private _channelMode; /** Whether the audio is copyrighted. */ private _isCopyrighted; /** Whether the audio is an original recording (not a copy). */ private _isOriginal; /** Total byte length of this frame including the header. */ private _frameLength; /** Number of PCM samples encoded in this frame. */ private _samplesPerFrame; /** Whether the frame is an ADTS (AAC) frame rather than a standard MPEG frame. */ private _isADTS; /** Number of audio channels (1 for mono, 2 for all stereo modes). */ private _channels; /** * Private constructor — use the static {@link MpegHeader.fromStream} factory method. */ private constructor(); /** * Reads and parses an MPEG frame header from the stream at the given offset. * * @param stream - The I/O stream to read from. * @param offset - Byte offset within the stream at which the frame header starts. * @param checkLength - When `true`, the next frame is also validated to confirm this is real audio. * @returns A fully parsed `MpegHeader`; check {@link isValid} before using the result. */ static fromStream(stream: IOStream, offset: offset_t, checkLength?: boolean): Promise; /** Gets whether the header represents a valid MPEG audio frame. */ get isValid(): boolean; /** Gets the MPEG version of this frame. */ get version(): MpegVersion; /** Gets the MPEG layer (1, 2, or 3); 0 for ADTS. */ get layer(): number; /** Gets whether CRC protection is enabled for this frame. */ get protectionEnabled(): boolean; /** Gets the audio bitrate in kbps. */ get bitrate(): number; /** Gets the sample rate in Hz. */ get sampleRate(): number; /** Gets whether this frame includes a padding slot. */ get isPadded(): boolean; /** Gets the channel mode of this frame. */ get channelMode(): ChannelMode; /** Gets whether the audio is flagged as copyrighted. */ get isCopyrighted(): boolean; /** Gets whether the audio is flagged as an original recording. */ get isOriginal(): boolean; /** Gets the total byte length of this frame (header + payload). */ get frameLength(): number; /** Gets the number of PCM samples encoded in this frame. */ get samplesPerFrame(): number; /** Gets whether this is an ADTS (AAC) frame rather than a standard MPEG frame. */ get isADTS(): boolean; /** Gets the number of audio channels (1 for mono, 2 for all stereo modes). */ get channels(): number; /** * Reads 4 bytes from the stream at `offset` and populates all header fields. * Sets `_isValid` to `true` only if a complete, coherent header is found. * * @param stream - The I/O stream to read from. * @param offset - Byte offset within the stream. * @param checkLength - When `true`, also validates the next frame header. */ private parse; /** * Parses an ADTS (AAC) frame header from the given data, reading additional * bytes from the stream when needed. * * @param data - The first 4 bytes already read from the stream. * @param stream - The I/O stream (for reading bytes 4-5 of the ADTS header). * @param offset - Byte offset in the stream where the frame starts. * @param checkLength - When `true`, also validates the next frame header. */ private parseADTS; /** * Verifies that a valid matching frame header exists at `offset + frameLength`. * The version, layer, and sample-rate fields must match those of the current header. * * @param stream - The I/O stream used to read the next frame header. * @param offset - Byte offset of the current frame. * @param data - The current frame's 4-byte header data (used for masking comparison). * @returns `true` if the next frame header is valid and consistent. */ private validateNextFrame; /** * Looks up the bitrate (kbps) for the given bitrate index using the current * version and layer. * * @param index - The 4-bit bitrate index from the frame header. * @returns The bitrate in kbps, or `0` for invalid/free-format indices. */ private lookupBitrate; /** * Looks up the sample rate (Hz) for the given index using the current version. * * @param index - The 2-bit sample-rate index from the frame header. * @returns The sample rate in Hz, or `0` for invalid indices. */ private lookupSampleRate; /** * Returns the number of PCM samples per frame for the current version and layer. * @returns Sample count per frame (384 for Layer 1, 576 or 1152 for Layer 3, 1152 for Layer 2). */ private computeSamplesPerFrame; } //# sourceMappingURL=mpegHeader.d.ts.map