/** * MSB-first bit-level I/O. * * MP3 and FLAC are bitstream formats: fields are not byte-aligned and Huffman * codes are read one bit at a time. Both read most-significant-bit first, so * that is the only order implemented here. * * {@link BitReader} is on the hot path of MP3 decoding — it is called millions of * times for a single track — so it keeps a small integer cache instead of * recomputing byte/bit offsets per call, and it reads past-the-end as zero bits * rather than throwing. That last choice is deliberate: Layer III's bit * reservoir legitimately lets a frame's Huffman data run slightly past the * declared part2_3_length, and real encoders emit files that rely on it. Callers * detect overrun via {@link BitReader.overran} once a granule is finished, rather * than failing mid-symbol on a file every other decoder plays. */ export declare class BitReader { private readonly data; private bytePos; private bitPos; private readonly end; private didOverrun; constructor(data: Uint8Array, startByte?: number); /** True if any read has gone past the end of the buffer. */ get overran(): boolean; /** Total bits consumed since construction. */ get bitsRead(): number; /** Bits remaining before the end of the buffer. */ get bitsRemaining(): number; /** Reads a single bit. Returns 0 past the end. */ bit(): number; /** * Reads `n` bits (0–32) as an unsigned integer. * * `n` above 25 is handled in two steps because a JS bitwise shift operates on * 32-bit signed values — accumulating 32 bits in one `<<` chain would flip the * sign and silently corrupt the result. */ bits(n: number): number; /** Reads `n` bits as a two's-complement signed integer. */ signedBits(n: number): number; /** Peeks `n` bits without consuming them. */ peek(n: number): number; /** Skips `n` bits. */ skip(n: number): void; /** Moves to an absolute bit position. */ seekBits(bitOffset: number): void; /** Advances to the next byte boundary. */ align(): void; /** * Reads a unary-coded value: the count of zero bits before the next one bit. * * FLAC's Rice coding is built on this. `limit` bounds the scan so a corrupt * stream of zeros cannot spin forever — returning -1 signals "no terminator * found", which the caller must treat as a decode error. */ unary(limit?: number): number; } /** MSB-first bit sink. Used by the MP3 and FLAC encoders. */ export declare class BitWriter { private buf; private len; private acc; private accBits; constructor(initialCapacity?: number); /** Bytes written, including the partial byte currently being assembled. */ get length(): number; /** Total bits written. */ get bitLength(): number; private grow; /** Writes the low `n` bits of `value`, most-significant first. */ bits(value: number, n: number): void; bit(value: number): void; /** Pads with zero bits to the next byte boundary. */ align(): void; /** Appends whole bytes. Requires byte alignment. */ writeBytes(data: Uint8Array): void; /** Flushes any partial byte and returns an exact-length copy. */ finish(): Uint8Array; /** * Discards everything written and reuses the buffer. * * For callers that emit many independent blocks — one per MP3 frame, say — and * would otherwise allocate a writer and let it grow again for each one. */ reset(): void; }