@ac-kit/format-wav 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/LICENSE +28 -0
- package/README.md +146 -2
- package/dist/decode/decode-wav-stream.d.ts +29 -0
- package/dist/decode/decode-wav-stream.d.ts.map +1 -0
- package/dist/decode/decode-wav-stream.js +70 -0
- package/dist/decode/decode-wav-stream.js.map +1 -0
- package/dist/decode/parse-wav.d.ts +58 -0
- package/dist/decode/parse-wav.d.ts.map +1 -0
- package/dist/decode/parse-wav.js +91 -0
- package/dist/decode/parse-wav.js.map +1 -0
- package/dist/decode/wav-decoder.d.ts +189 -0
- package/dist/decode/wav-decoder.d.ts.map +1 -0
- package/dist/decode/wav-decoder.js +709 -0
- package/dist/decode/wav-decoder.js.map +1 -0
- package/dist/decode/wav-warning.d.ts +46 -0
- package/dist/decode/wav-warning.d.ts.map +1 -0
- package/dist/decode/wav-warning.js +2 -0
- package/dist/decode/wav-warning.js.map +1 -0
- package/dist/encode/_sample-block.d.ts +12 -0
- package/dist/encode/_sample-block.d.ts.map +1 -0
- package/dist/encode/_sample-block.js +50 -0
- package/dist/encode/_sample-block.js.map +1 -0
- package/dist/encode/_wav-layout.d.ts +69 -0
- package/dist/encode/_wav-layout.d.ts.map +1 -0
- package/dist/encode/_wav-layout.js +272 -0
- package/dist/encode/_wav-layout.js.map +1 -0
- package/dist/encode/create-wav-writable-stream.d.ts +31 -0
- package/dist/encode/create-wav-writable-stream.d.ts.map +1 -0
- package/dist/encode/create-wav-writable-stream.js +82 -0
- package/dist/encode/create-wav-writable-stream.js.map +1 -0
- package/dist/encode/encode-wav.d.ts +21 -0
- package/dist/encode/encode-wav.d.ts.map +1 -0
- package/dist/encode/encode-wav.js +26 -0
- package/dist/encode/encode-wav.js.map +1 -0
- package/dist/encode/wav-encode-stream.d.ts +28 -0
- package/dist/encode/wav-encode-stream.d.ts.map +1 -0
- package/dist/encode/wav-encode-stream.js +46 -0
- package/dist/encode/wav-encode-stream.js.map +1 -0
- package/dist/encode/wav-encoder.d.ts +128 -0
- package/dist/encode/wav-encoder.d.ts.map +1 -0
- package/dist/encode/wav-encoder.js +125 -0
- package/dist/encode/wav-encoder.js.map +1 -0
- package/dist/errors.d.ts +39 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +50 -0
- package/dist/errors.js.map +1 -0
- package/dist/format/_fmt-chunk.d.ts +36 -0
- package/dist/format/_fmt-chunk.d.ts.map +1 -0
- package/dist/format/_fmt-chunk.js +191 -0
- package/dist/format/_fmt-chunk.js.map +1 -0
- package/dist/format/wav-format-chunk.d.ts +34 -0
- package/dist/format/wav-format-chunk.d.ts.map +1 -0
- package/dist/format/wav-format-chunk.js +2 -0
- package/dist/format/wav-format-chunk.js.map +1 -0
- package/dist/format/wav-format.d.ts +113 -0
- package/dist/format/wav-format.d.ts.map +1 -0
- package/dist/format/wav-format.js +125 -0
- package/dist/format/wav-format.js.map +1 -0
- package/dist/format/wav-speaker.d.ts +52 -0
- package/dist/format/wav-speaker.d.ts.map +1 -0
- package/dist/format/wav-speaker.js +99 -0
- package/dist/format/wav-speaker.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/riff/_info.d.ts +24 -0
- package/dist/riff/_info.d.ts.map +1 -0
- package/dist/riff/_info.js +98 -0
- package/dist/riff/_info.js.map +1 -0
- package/dist/riff/_riff.d.ts +28 -0
- package/dist/riff/_riff.d.ts.map +1 -0
- package/dist/riff/_riff.js +63 -0
- package/dist/riff/_riff.js.map +1 -0
- package/dist/riff/wav-chunk.d.ts +27 -0
- package/dist/riff/wav-chunk.d.ts.map +1 -0
- package/dist/riff/wav-chunk.js +2 -0
- package/dist/riff/wav-chunk.js.map +1 -0
- package/dist/samples/wav-samples.d.ts +77 -0
- package/dist/samples/wav-samples.d.ts.map +1 -0
- package/dist/samples/wav-samples.js +268 -0
- package/dist/samples/wav-samples.js.map +1 -0
- package/package.json +66 -3
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type { Predicate } from "@ac-kit/core";
|
|
2
|
+
import type { WavFormatChunk } from "../format/wav-format-chunk.js";
|
|
3
|
+
import type { WavFormat } from "../format/wav-format.js";
|
|
4
|
+
import type { WavChunk, WavInfoEntry } from "../riff/wav-chunk.js";
|
|
5
|
+
import type { WavWarning } from "./wav-warning.js";
|
|
6
|
+
/**
|
|
7
|
+
* The container a file uses: `RIFF`, or one of the 64-bit ones whose sizes are
|
|
8
|
+
* in a `ds64` chunk — `RF64` (EBU Tech 3306) and `BW64` (ITU-R BS.2088).
|
|
9
|
+
*/
|
|
10
|
+
export type WavContainer = "RIFF" | "RF64" | "BW64";
|
|
11
|
+
/**
|
|
12
|
+
* What a {@link WavDecoder} reads, in file order:
|
|
13
|
+
*
|
|
14
|
+
* - `format` — the `fmt ` chunk: the container, the sample format when this
|
|
15
|
+
* package converts it (else `null`), and the chunk's fields as written.
|
|
16
|
+
* - `fact` — the `fact` chunk's frame count (RF64's from `ds64` when the chunk's
|
|
17
|
+
* is a placeholder), which formats with compressed blocks need.
|
|
18
|
+
* - `data` — the start of the `data` chunk, with the frames it declares, or
|
|
19
|
+
* `null` when its size is unknown (see `dataSizeUnknown`).
|
|
20
|
+
* - `samples` — whole frames of the `data` chunk, as many as the input holds:
|
|
21
|
+
* `frameCount × blockAlign` bytes. For a format this package does not
|
|
22
|
+
* convert, whole blocks of `blockAlign` bytes.
|
|
23
|
+
* - `info` — the entries of a `LIST` chunk of type `INFO`.
|
|
24
|
+
* - `chunk` — a chunk the `keepChunk` option asked for.
|
|
25
|
+
* - `warning` — a defect read past; never in strict mode, which throws instead.
|
|
26
|
+
* - `end` — the end of the input, with the frames read in all.
|
|
27
|
+
*
|
|
28
|
+
* Byte arrays may be views over the arrays given to {@link WavDecoder.write}
|
|
29
|
+
* (the decoder copies only what straddles two of them), so a caller that reuses
|
|
30
|
+
* its input buffers copies what it keeps.
|
|
31
|
+
*/
|
|
32
|
+
export type WavItem = {
|
|
33
|
+
readonly type: "format";
|
|
34
|
+
readonly container: WavContainer;
|
|
35
|
+
readonly format: WavFormat | null;
|
|
36
|
+
readonly formatChunk: WavFormatChunk;
|
|
37
|
+
} | {
|
|
38
|
+
readonly type: "fact";
|
|
39
|
+
readonly frameCount: number;
|
|
40
|
+
} | {
|
|
41
|
+
readonly type: "data";
|
|
42
|
+
readonly frameCount: number | null;
|
|
43
|
+
} | {
|
|
44
|
+
readonly type: "samples";
|
|
45
|
+
readonly bytes: Uint8Array;
|
|
46
|
+
readonly frameCount: number;
|
|
47
|
+
} | {
|
|
48
|
+
readonly type: "info";
|
|
49
|
+
readonly entries: readonly WavInfoEntry[];
|
|
50
|
+
} | {
|
|
51
|
+
readonly type: "chunk";
|
|
52
|
+
readonly chunk: WavChunk;
|
|
53
|
+
} | {
|
|
54
|
+
readonly type: "warning";
|
|
55
|
+
readonly warning: WavWarning;
|
|
56
|
+
} | {
|
|
57
|
+
readonly type: "end";
|
|
58
|
+
readonly frameCount: number;
|
|
59
|
+
};
|
|
60
|
+
/** Options of {@link WavDecoder}. */
|
|
61
|
+
export interface WavDecoderOptions {
|
|
62
|
+
/**
|
|
63
|
+
* Refuse every defect a {@link WavWarning} would report, with a
|
|
64
|
+
* {@link WavFormatError} (a {@link WavLimitError} for `chunkTooLarge`). Default
|
|
65
|
+
* `false`.
|
|
66
|
+
*/
|
|
67
|
+
readonly strict?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Which chunks to hand over as `chunk` items, by identifier and payload size;
|
|
70
|
+
* the others are skipped without being held. Never asked about `fmt `,
|
|
71
|
+
* `data`, `fact`, `ds64` or a `LIST`/`INFO` chunk, which the decoder reads
|
|
72
|
+
* itself. Default: none.
|
|
73
|
+
*/
|
|
74
|
+
readonly keepChunk?: Predicate<[id: string, byteLength: number]>;
|
|
75
|
+
/**
|
|
76
|
+
* The largest chunk payload the decoder holds in memory: a kept chunk, a
|
|
77
|
+
* `LIST`/`INFO` or a `ds64` chunk. A larger kept or `LIST`/`INFO` chunk is
|
|
78
|
+
* skipped with a `chunkTooLarge` warning; a larger `ds64` chunk is a
|
|
79
|
+
* {@link WavLimitError}. Samples are never held, whatever this is. Default 1
|
|
80
|
+
* MiB.
|
|
81
|
+
*/
|
|
82
|
+
readonly maxChunkByteLength?: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A WAV reader fed the file in arrays of any size, as they arrive, holding
|
|
86
|
+
* nothing but headers, a partial frame and the chunks it is asked to keep: the
|
|
87
|
+
* samples of the `data` chunk are handed over as views of the input, whole
|
|
88
|
+
* frames at a time. Reads `RIFF`, `RF64` and `BW64` containers, every `fmt `
|
|
89
|
+
* chunk (converting PCM of 8 to 32 bits, IEEE float of 32 and 64 bits and their
|
|
90
|
+
* `WAVE_FORMAT_EXTENSIBLE` forms), `fact` and `LIST`/`INFO`, and skips the rest
|
|
91
|
+
* unless `keepChunk` asks for it.
|
|
92
|
+
*
|
|
93
|
+
* It reads past the defects real files carry — placeholder sizes left by
|
|
94
|
+
* streaming writers, odd chunks without their pad byte, a truncated `data`
|
|
95
|
+
* chunk — reporting each as a `warning` item; `strict` refuses them. Malformed
|
|
96
|
+
* structure is a {@link WavFormatError}, after which the decoder takes no more
|
|
97
|
+
* input.
|
|
98
|
+
*
|
|
99
|
+
* Every call is linear in the bytes given; only kept chunks, headers and frames
|
|
100
|
+
* split between two arrays are copied.
|
|
101
|
+
*/
|
|
102
|
+
export declare class WavDecoder {
|
|
103
|
+
private readonly strict;
|
|
104
|
+
private readonly keepChunk;
|
|
105
|
+
private readonly maxChunkBytes;
|
|
106
|
+
private state;
|
|
107
|
+
private items;
|
|
108
|
+
private input;
|
|
109
|
+
private offset;
|
|
110
|
+
private position;
|
|
111
|
+
private gathered;
|
|
112
|
+
private gatheredLength;
|
|
113
|
+
private container;
|
|
114
|
+
private riffEnd;
|
|
115
|
+
private riffSizePlaceholder;
|
|
116
|
+
private riffSizeReported;
|
|
117
|
+
private trailingReported;
|
|
118
|
+
private expectDs64;
|
|
119
|
+
private ds64DataBytes;
|
|
120
|
+
private ds64FrameCount;
|
|
121
|
+
private readonly ds64Sizes;
|
|
122
|
+
private formatChunk;
|
|
123
|
+
private dataSeen;
|
|
124
|
+
private dataRemaining;
|
|
125
|
+
private frameCount;
|
|
126
|
+
private residue;
|
|
127
|
+
private residueLength;
|
|
128
|
+
private chunkId;
|
|
129
|
+
private chunkStart;
|
|
130
|
+
private chunkPayloadBytes;
|
|
131
|
+
private remaining;
|
|
132
|
+
private bodyKind;
|
|
133
|
+
private listType;
|
|
134
|
+
private padByte;
|
|
135
|
+
private padPosition;
|
|
136
|
+
constructor(options?: WavDecoderOptions);
|
|
137
|
+
/**
|
|
138
|
+
* Reads the next bytes of the file.
|
|
139
|
+
*
|
|
140
|
+
* @returns The items they complete, in file order; often none.
|
|
141
|
+
* @throws {WavFormatError} When the file is malformed, or, in strict mode,
|
|
142
|
+
* has a defect.
|
|
143
|
+
* @throws {WavLimitError} When a size is past a limit.
|
|
144
|
+
* @throws {TypeError} After {@link end}, or after an error.
|
|
145
|
+
*/
|
|
146
|
+
write(bytes: Uint8Array): WavItem[];
|
|
147
|
+
/**
|
|
148
|
+
* Ends the input: reports what it cut short, checks that a `data` chunk was
|
|
149
|
+
* found, and returns the last items, `end` included.
|
|
150
|
+
*
|
|
151
|
+
* @throws {WavFormatError} When no `data` chunk was found, the input ends
|
|
152
|
+
* inside the RIFF header or a `fmt ` or `ds64` chunk, or, in strict mode,
|
|
153
|
+
* ends early anywhere.
|
|
154
|
+
* @throws {TypeError} After a first call, or after an error.
|
|
155
|
+
*/
|
|
156
|
+
end(): WavItem[];
|
|
157
|
+
private begin_;
|
|
158
|
+
private complete_;
|
|
159
|
+
private emit_;
|
|
160
|
+
private warn_;
|
|
161
|
+
private available_;
|
|
162
|
+
private consume_;
|
|
163
|
+
private read_;
|
|
164
|
+
private run_;
|
|
165
|
+
private reportTrailing_;
|
|
166
|
+
private readRiffHeader_;
|
|
167
|
+
private readPad_;
|
|
168
|
+
private checkPad_;
|
|
169
|
+
private startChunk_;
|
|
170
|
+
private checkRiffOverrun_;
|
|
171
|
+
private distrustRiffSize_;
|
|
172
|
+
private startDs64_;
|
|
173
|
+
private startFormat_;
|
|
174
|
+
private startKeptOrSkipped_;
|
|
175
|
+
private reportTooLarge_;
|
|
176
|
+
private startList_;
|
|
177
|
+
private startBody_;
|
|
178
|
+
private startSkip_;
|
|
179
|
+
private endChunk_;
|
|
180
|
+
private readBody_;
|
|
181
|
+
private readFormat_;
|
|
182
|
+
private readDs64_;
|
|
183
|
+
private isDataSizeUnknown_;
|
|
184
|
+
private startData_;
|
|
185
|
+
private readData_;
|
|
186
|
+
private dropResidue_;
|
|
187
|
+
private end_;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=wav-decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wav-decoder.d.ts","sourceRoot":"","sources":["../../src/decode/wav-decoder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAQ9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAuBzD,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,kBAAkB,CAAC;AAEnE;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,OAAO,GAChB;IACA,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,YAAY,CA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