Skip to content

Commit

Permalink
Add Typescript types for fmt and data chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
rejc2 committed Jan 23, 2023
1 parent f9311ad commit 141d3d6
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,45 @@ export = wavefile;

declare module wavefile {

type FormatChunk = {
/** @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<number>}
*/
subformat: readonly [number,number,number,number];
};

type DataChunk = {
/** @type {string} */
chunkId: 'data';
/** @type {number} */
chunkSize: number;
/** @type {!Uint8Array} */
samples: Uint8Array;
};

class WaveFile {

/**
Expand All @@ -19,7 +58,7 @@ declare module wavefile {
* 'RIFF', 'RIFX' and 'RF64' are supported.
* @type {string}
*/
container: string;
container: 'RIFF' | 'RIFX' | 'RF64';
/**
* @type {number}
*/
Expand All @@ -29,12 +68,12 @@ declare module wavefile {
* Always 'WAVE'.
* @type {string}
*/
format: string;
format: 'WAVE';
/**
* The data of the 'fmt' chunk.
* @type {!Object<string, *>}
*/
fmt: object;
fmt: FormatChunk;
/**
* The data of the 'fact' chunk.
* @type {!Object<string, *>}
Expand Down Expand Up @@ -70,7 +109,7 @@ declare module wavefile {
* The data of the 'data' chunk.
* @type {!Object<string, *>}
*/
data: object;
data: DataChunk;
/**
* The data of the 'LIST' chunks.
* Each item in this list look like this:
Expand Down

0 comments on commit 141d3d6

Please sign in to comment.