From b02387341e34a9a08b013ab6bf1d1ff3dffdfced Mon Sep 17 00:00:00 2001 From: Richard Collins Date: Sun, 22 Jan 2023 22:29:07 -0800 Subject: [PATCH] Add Typescript types for fmt and data chunks --- index.d.ts | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index 74596ee..3424325 100644 --- a/index.d.ts +++ b/index.d.ts @@ -17,7 +17,7 @@ declare module wavefile { * 'RIFF', 'RIFX' and 'RF64' are supported. * @type {string} */ - container: string; + container: 'RIFF' | 'RIFX' | 'RF64'; /** * @type {number} */ @@ -27,12 +27,12 @@ declare module wavefile { * Always 'WAVE'. * @type {string} */ - format: string; + format: 'WAVE'; /** * The data of the 'fmt' chunk. * @type {!Object} */ - fmt: object; + fmt: WaveFileFmtChunk; /** * The data of the 'fact' chunk. * @type {!Object} @@ -78,7 +78,7 @@ declare module wavefile { * The data of the 'data' chunk. * @type {!Object} */ - data: object; + data: WaveFileDataChunk; /** * The data of the 'LIST' chunks. * Each item in this list look like this: @@ -390,4 +390,43 @@ declare module wavefile { */ get_PMX(): string; } + + type WaveFileDataChunk = { + /** @type {string} */ + chunkId: 'data'; + /** @type {number} */ + chunkSize: number; + /** @type {!Uint8Array} */ + samples: Uint8Array; + }; + + type WaveFileFmtChunk = { + /** @type {string} */ + chunkId: 'fmt '; + /** @type {number} */ + chunkSize: number; + /** @type {number} */ + audioFormat: number; + /** @type {number} */ + numChannels: number; + /** @type {number} */ + sampleRate: number; + /** @type {number} */ + byteRate: number; + /** @type {number} */ + blockAlign: number; + /** @type {number} */ + bitsPerSample: number; + /** @type {number} */ + cbSize: number; + /** @type {number} */ + validBitsPerSample: number; + /** @type {number} */ + dwChannelMask: number; + /** + * 4 32-bit values representing a 128-bit ID + * @type {!Array} + */ + subformat: readonly [number,number,number,number]; + }; }