/** * Conversion between packed container bytes and planar `Float32Array` samples. * * ## Why float32, and what it costs * * Decoded audio is held as `Float32Array` in the range [-1, 1] โ€” the same * representation as Web Audio's `AudioBuffer`, so handing data to and from the * browser is a straight copy rather than a conversion pass. * * A float32 has a 24-bit mantissa. That makes round-trips through 8-, 16-, and * 24-bit integer formats **exactly** reversible, which covers essentially all * real-world audio. It cannot hold all 32 bits of a `s32` sample or all 53 of an * `f64` one, so those two formats round-trip to roughly 24-bit precision โ€” about * -145 dBFS of error, far below the noise floor of any microphone or converter, * but not bit-exact. This is the same trade Web Audio makes. It is documented * rather than hidden because a silent precision loss is worse than a known one. * * ## Scaling convention * * Integer to float divides by 2^(bits-1); float to integer multiplies by the * same figure and clamps. The asymmetry (`-32768` maps to `-1.0`, while `+1.0` * clamps to `+32767`) is deliberate and standard โ€” it is the only convention * under which every integer value survives a round-trip unchanged. */ import type { SampleFormat } from '../types.js'; /** Bytes occupied by one sample of `format`. ADPCM is block-based and has no per-sample size. */ export declare function bytesPerSample(format: SampleFormat): number; /** Bit depth as stored on disk. */ export declare function bitDepthOf(format: SampleFormat): number; /** True when `format` stores floating-point samples. */ export declare function isFloatFormat(format: SampleFormat): boolean; /** * Encodes a 16-bit linear sample to A-law. * * Ported from the ITU-T G.711 reference implementation rather than derived, so * that output is byte-identical to every other conforming encoder. */ export declare function linearToALaw(sample: number): number; /** Encodes a 16-bit linear sample to ยต-law. Ported from the G.711 reference. */ export declare function linearToULaw(sample: number): number; export interface DitherOptions { /** * `'none'` for bit-exact output, `'tpdf'` for triangular-PDF dither. * * Reducing bit depth without dither produces *correlated* quantization error, * heard as harmonic distortion on quiet passages rather than as hiss. TPDF * dither trades a tiny, constant noise floor for the removal of that * distortion, which is why mastering practice always applies it. Default is * `'none'` so that round-trips stay reversible unless a caller opts in. */ type?: 'none' | 'tpdf'; /** Seed for reproducible output. */ seed?: number; } /** * Decodes interleaved packed samples into one `Float32Array` per channel. * * @param bytes Packed sample data, starting at sample 0. * @param format Storage format of each sample. * @param littleEndian Byte order for multi-byte formats. * @param channels Channel count; samples are interleaved by frame. * @param frames Number of frames to decode. */ export declare function decodeInterleaved(bytes: Uint8Array, format: SampleFormat, littleEndian: boolean, channels: number, frames: number): Float32Array[]; /** * Encodes planar float channels into interleaved packed samples. * * @param channelData One `Float32Array` per channel; all must be the same length. */ export declare function encodeInterleaved(channelData: readonly Float32Array[], format: SampleFormat, littleEndian: boolean, dither?: DitherOptions): Uint8Array; //# sourceMappingURL=convert.d.ts.map