@thi.ng/dsp-io-wav
Version:
WAV file format generation
48 lines • 1.59 kB
TypeScript
import type { BinStructItem } from "@thi.ng/transducers-binary";
import type { WavSpec } from "./api.js";
export declare const wavHeader: (spec: WavSpec) => BinStructItem[];
/**
* Takes a {@link WavSpec} and iterable of normalized float samples,
* creates WAV format header, converts samples to specified bit depth
* and returns `Uint8Array` of complete WAV file, ready for export.
*
* @remarks
* If using more than one channel, the source samples need to be already
* interleaved, i.e. for stereo: left, right, left, right etc.
*
* At most, only the number of samples specified in the given header
* spec are consumed & written. The source iterable does not need to be
* limited explicitly.
*
* @example
* ```ts tangle:../export/wav-byte-array.ts
* import { osc, sin } from "@thi.ng/dsp";
* import { wavByteArray } from "@thi.ng/dsp-io-wav";
* import { writeFileSync } from "node:fs";
*
* // sample rate
* const FS = 48000;
*
* // write 1 second 24bit mono WAV file, 440Hz sine
* writeFileSync(
* "sine-440.wav",
* wavByteArray(
* { sampleRate: FS, channels: 1, length: FS, bits: 24 },
* osc(sin, 440 / FS)
* )
* )
* ```
*
* @param spec -
* @param src -
*/
export declare const wavByteArray: (spec: WavSpec, src: Iterable<number>) => Uint8Array<ArrayBuffer>;
/**
* Similar to {@link wavByteArray}, but yields an iterator of the result
* bytes, not an actual byte array.
*
* @param spec -
* @param src -
*/
export declare const wavBytes: (spec: WavSpec, src: Iterable<number>) => Iterable<number>;
//# sourceMappingURL=write.d.ts.map