@flo-audio/libflo-audio 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.
@@ -0,0 +1,449 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class AudioInfo {
5
+ private constructor();
6
+ free(): void;
7
+ [Symbol.dispose](): void;
8
+ /**
9
+ * Sample rate in Hz
10
+ */
11
+ sample_rate: number;
12
+ /**
13
+ * Number of channels
14
+ */
15
+ channels: number;
16
+ /**
17
+ * Bits per sample
18
+ */
19
+ bit_depth: number;
20
+ /**
21
+ * Total number of frames
22
+ */
23
+ total_frames: bigint;
24
+ /**
25
+ * Duration in seconds
26
+ */
27
+ duration_secs: number;
28
+ /**
29
+ * File size in bytes
30
+ */
31
+ file_size: number;
32
+ /**
33
+ * Compression ratio (original / compressed)
34
+ */
35
+ compression_ratio: number;
36
+ /**
37
+ * Is CRC valid?
38
+ */
39
+ crc_valid: boolean;
40
+ /**
41
+ * Is lossy compression mode?
42
+ */
43
+ is_lossy: boolean;
44
+ /**
45
+ * Lossy quality 0-4 (only valid if is_lossy)
46
+ */
47
+ lossy_quality: number;
48
+ readonly version: string;
49
+ }
50
+
51
+ export class WasmStreamingDecoder {
52
+ free(): void;
53
+ [Symbol.dispose](): void;
54
+ /**
55
+ * Decode the next available frame
56
+ *
57
+ * Returns interleaved f32 samples for one frame, or null if no frame is ready.
58
+ * This enables true streaming: decode and play frames as they arrive.
59
+ *
60
+ * Usage pattern:
61
+ * ```js
62
+ * while (true) {
63
+ * const samples = decoder.next_frame();
64
+ * if (samples === null) break; // No more frames ready
65
+ * playAudio(samples);
66
+ * }
67
+ * ```
68
+ */
69
+ next_frame(): any;
70
+ /**
71
+ * stream done?
72
+ */
73
+ is_finished(): boolean;
74
+ /**
75
+ * bytes currently buffered
76
+ */
77
+ buffered_bytes(): number;
78
+ /**
79
+ * how many frames ready to decode
80
+ */
81
+ available_frames(): number;
82
+ /**
83
+ * decode all currently available samples
84
+ */
85
+ decode_available(): Float32Array;
86
+ /**
87
+ * current frame index
88
+ */
89
+ current_frame_index(): number;
90
+ /**
91
+ * new streaming decoder
92
+ */
93
+ constructor();
94
+ /**
95
+ * feed data to the decoder, call as bytes come in from network
96
+ */
97
+ feed(data: Uint8Array): boolean;
98
+ /**
99
+ * Reset the decoder to initial state
100
+ *
101
+ * Use this to start decoding a new stream.
102
+ */
103
+ reset(): void;
104
+ /**
105
+ * Get the current state as a string
106
+ */
107
+ state(): string;
108
+ /**
109
+ * Get audio information (available after header is parsed)
110
+ *
111
+ * Returns null if header hasn't been parsed yet.
112
+ */
113
+ get_info(): any;
114
+ /**
115
+ * Check if the decoder is ready to produce audio
116
+ */
117
+ is_ready(): boolean;
118
+ /**
119
+ * Check if there was an error
120
+ */
121
+ has_error(): boolean;
122
+ }
123
+
124
+ /**
125
+ * Create metadata from basic fields and serialize to MessagePack
126
+ *
127
+ * # Arguments
128
+ * * `title` - Optional title
129
+ * * `artist` - Optional artist
130
+ * * `album` - Optional album
131
+ *
132
+ * # Returns
133
+ * MessagePack bytes containing metadata
134
+ */
135
+ export function create_metadata(title?: string | null, artist?: string | null, album?: string | null): Uint8Array;
136
+
137
+ /**
138
+ * Create metadata from a JavaScript object
139
+ *
140
+ * Accepts an object with any of the supported metadata fields.
141
+ * See FloMetadata for available fields.
142
+ *
143
+ * # Returns
144
+ * MessagePack bytes containing metadata
145
+ */
146
+ export function create_metadata_from_object(obj: any): Uint8Array;
147
+
148
+ /**
149
+ * decode flo file to samples
150
+ *
151
+ * This automatically detects whether the file uses lossless or lossy encoding
152
+ * and dispatches to the appropriate decoder.
153
+ *
154
+ * # Arguments
155
+ * * `data` - flo™ file bytes
156
+ *
157
+ * # Returns
158
+ * Interleaved audio samples (f32, -1.0 to 1.0)
159
+ */
160
+ export function decode(data: Uint8Array): Float32Array;
161
+
162
+ /**
163
+ * encode samples to flo lossless
164
+ *
165
+ * # Arguments
166
+ * * `samples` - Interleaved audio samples (f32, -1.0 to 1.0)
167
+ * * `sample_rate` - Sample rate in Hz (e.g., 44100)
168
+ * * `channels` - Number of channels (1 or 2)
169
+ * * `bit_depth` - Bits per sample (16, 24, or 32)
170
+ * * `metadata` - Optional MessagePack metadata
171
+ *
172
+ * # Returns
173
+ * flo™ file as byte array
174
+ *
175
+ * # Note
176
+ * For advanced usage with custom compression levels (0-9),
177
+ * use the `Encoder` builder pattern directly.
178
+ */
179
+ export function encode(samples: Float32Array, sample_rate: number, channels: number, bit_depth: number, metadata?: Uint8Array | null): Uint8Array;
180
+
181
+ /**
182
+ * encode samples to flo lossy
183
+ *
184
+ * # Arguments
185
+ * * `samples` - Interleaved audio samples (f32, -1.0 to 1.0)
186
+ * * `sample_rate` - Sample rate in Hz (e.g., 44100)
187
+ * * `channels` - Number of audio channels (1 or 2)
188
+ * * `bit_depth` - Bits per sample (typically 16)
189
+ * * `quality` - Quality level 0-4 (0=low/~64kbps, 4=transparent/~320kbps)
190
+ * * `metadata` - Optional MessagePack metadata
191
+ *
192
+ * # Returns
193
+ * flo™ file as byte array
194
+ *
195
+ * # Note
196
+ * For advanced usage with continuous quality control (0.0-1.0) or custom settings,
197
+ * use the `LossyEncoder` builder pattern directly.
198
+ */
199
+ export function encode_lossy(samples: Float32Array, sample_rate: number, channels: number, _bit_depth: number, quality: number, metadata?: Uint8Array | null): Uint8Array;
200
+
201
+ /**
202
+ * encode to flo lossy with target bitrate
203
+ *
204
+ * # Arguments
205
+ * * `samples` - Interleaved audio samples (f32, -1.0 to 1.0)
206
+ * * `sample_rate` - Sample rate in Hz (e.g., 44100)
207
+ * * `channels` - Number of audio channels
208
+ * * `bit_depth` - Bits per sample (16, 24, or 32)
209
+ * * `target_bitrate_kbps` - Target bitrate in kbps (e.g., 128, 192, 256, 320)
210
+ * * `metadata` - Optional MessagePack metadata
211
+ *
212
+ * # Returns
213
+ * flo™ file as byte array
214
+ */
215
+ export function encode_with_bitrate(samples: Float32Array, sample_rate: number, channels: number, _bit_depth: number, target_bitrate_kbps: number, metadata?: Uint8Array | null): Uint8Array;
216
+
217
+ /**
218
+ * Get cover art from a flo™ file
219
+ *
220
+ * # Arguments
221
+ * * `data` - flo™ file bytes
222
+ *
223
+ * # Returns
224
+ * Object with `mime_type` and `data` (Uint8Array) or null if no cover
225
+ */
226
+ export function get_cover_art(data: Uint8Array): any;
227
+
228
+ /**
229
+ * Extract metadata from a flo™ file
230
+ *
231
+ * # Arguments
232
+ * * `data` - flo™ file bytes
233
+ *
234
+ * # Returns
235
+ * JavaScript object with metadata fields (or null if no metadata)
236
+ */
237
+ export function get_metadata(data: Uint8Array): any;
238
+
239
+ /**
240
+ * Get just the metadata bytes from a flo™ file
241
+ *
242
+ * # Arguments
243
+ * * `flo_data` - flo™ file bytes
244
+ *
245
+ * # Returns
246
+ * Raw MessagePack metadata bytes (or empty array)
247
+ */
248
+ export function get_metadata_bytes(flo_data: Uint8Array): Uint8Array;
249
+
250
+ /**
251
+ * Get section markers from a flo™ file
252
+ *
253
+ * # Returns
254
+ * Array of section markers or null if none
255
+ */
256
+ export function get_section_markers(data: Uint8Array): any;
257
+
258
+ /**
259
+ * Get synced lyrics from a flo™ file
260
+ *
261
+ * # Returns
262
+ * Array of synced lyrics objects or null if none
263
+ */
264
+ export function get_synced_lyrics(data: Uint8Array): any;
265
+
266
+ /**
267
+ * Get waveform data from a flo™ file for instant visualization
268
+ *
269
+ * # Returns
270
+ * WaveformData object or null if not present
271
+ */
272
+ export function get_waveform_data(data: Uint8Array): any;
273
+
274
+ /**
275
+ * does the file have metadata?
276
+ */
277
+ export function has_metadata(flo_data: Uint8Array): boolean;
278
+
279
+ /**
280
+ * Get information about a flo™ file
281
+ *
282
+ * # Arguments
283
+ * * `data` - flo™ file bytes
284
+ *
285
+ * # Returns
286
+ * AudioInfo struct with file details
287
+ */
288
+ export function info(data: Uint8Array): AudioInfo;
289
+
290
+ /**
291
+ * Replace just the metadata in a flo™ file (convenience function)
292
+ *
293
+ * Takes a metadata object directly instead of MessagePack bytes.
294
+ *
295
+ * # Arguments
296
+ * * `flo_data` - Original flo™ file bytes
297
+ * * `metadata` - JavaScript metadata object
298
+ *
299
+ * # Returns
300
+ * New flo™ file with updated metadata
301
+ */
302
+ export function set_metadata(flo_data: Uint8Array, metadata: any): Uint8Array;
303
+
304
+ /**
305
+ * Set a single field in existing metadata bytes
306
+ *
307
+ * Uses serde to dynamically set fields - field names match FloMetadata struct.
308
+ * For complex fields (pictures, synced_lyrics, etc.) use create_metadata_from_object.
309
+ *
310
+ * # Arguments
311
+ * * `metadata` - Existing MessagePack metadata bytes (or empty for new)
312
+ * * `field` - Field name (e.g., "title", "artist", "bpm")
313
+ * * `value` - Field value (string, number, or null)
314
+ *
315
+ * # Returns
316
+ * Updated MessagePack metadata bytes
317
+ */
318
+ export function set_metadata_field(metadata: Uint8Array | null | undefined, field: string, value: any): Uint8Array;
319
+
320
+ /**
321
+ * Remove all metadata from a flo™ file
322
+ *
323
+ * # Arguments
324
+ * * `flo_data` - Original flo™ file bytes
325
+ *
326
+ * # Returns
327
+ * New flo™ file with no metadata
328
+ */
329
+ export function strip_metadata(flo_data: Uint8Array): Uint8Array;
330
+
331
+ /**
332
+ * update metadata without re-encoding audio
333
+ *
334
+ * # Arguments
335
+ * * `flo_data` - Original flo™ file bytes
336
+ * * `new_metadata` - New MessagePack metadata bytes (use create_metadata_*)
337
+ *
338
+ * # Returns
339
+ * New flo™ file with updated metadata
340
+ */
341
+ export function update_metadata(flo_data: Uint8Array, new_metadata: Uint8Array): Uint8Array;
342
+
343
+ /**
344
+ * Validate flo™ file integrity
345
+ *
346
+ * # Arguments
347
+ * * `data` - flo™ file bytes
348
+ *
349
+ * # Returns
350
+ * true if file is valid and CRC matches
351
+ */
352
+ export function validate(data: Uint8Array): boolean;
353
+
354
+ /**
355
+ * get lib version
356
+ */
357
+ export function version(): string;
358
+
359
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
360
+
361
+ export interface InitOutput {
362
+ readonly memory: WebAssembly.Memory;
363
+ readonly __wbg_audioinfo_free: (a: number, b: number) => void;
364
+ readonly __wbg_get_audioinfo_bit_depth: (a: number) => number;
365
+ readonly __wbg_get_audioinfo_channels: (a: number) => number;
366
+ readonly __wbg_get_audioinfo_compression_ratio: (a: number) => number;
367
+ readonly __wbg_get_audioinfo_crc_valid: (a: number) => number;
368
+ readonly __wbg_get_audioinfo_duration_secs: (a: number) => number;
369
+ readonly __wbg_get_audioinfo_file_size: (a: number) => number;
370
+ readonly __wbg_get_audioinfo_is_lossy: (a: number) => number;
371
+ readonly __wbg_get_audioinfo_lossy_quality: (a: number) => number;
372
+ readonly __wbg_get_audioinfo_sample_rate: (a: number) => number;
373
+ readonly __wbg_get_audioinfo_total_frames: (a: number) => bigint;
374
+ readonly __wbg_set_audioinfo_bit_depth: (a: number, b: number) => void;
375
+ readonly __wbg_set_audioinfo_channels: (a: number, b: number) => void;
376
+ readonly __wbg_set_audioinfo_compression_ratio: (a: number, b: number) => void;
377
+ readonly __wbg_set_audioinfo_crc_valid: (a: number, b: number) => void;
378
+ readonly __wbg_set_audioinfo_duration_secs: (a: number, b: number) => void;
379
+ readonly __wbg_set_audioinfo_file_size: (a: number, b: number) => void;
380
+ readonly __wbg_set_audioinfo_is_lossy: (a: number, b: number) => void;
381
+ readonly __wbg_set_audioinfo_lossy_quality: (a: number, b: number) => void;
382
+ readonly __wbg_set_audioinfo_sample_rate: (a: number, b: number) => void;
383
+ readonly __wbg_set_audioinfo_total_frames: (a: number, b: bigint) => void;
384
+ readonly __wbg_wasmstreamingdecoder_free: (a: number, b: number) => void;
385
+ readonly audioinfo_version: (a: number) => [number, number];
386
+ readonly create_metadata: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
387
+ readonly create_metadata_from_object: (a: any) => [number, number, number, number];
388
+ readonly decode: (a: number, b: number) => [number, number, number, number];
389
+ readonly encode: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
390
+ readonly encode_lossy: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number, number, number];
391
+ readonly encode_with_bitrate: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number, number, number];
392
+ readonly get_cover_art: (a: number, b: number) => [number, number, number];
393
+ readonly get_metadata: (a: number, b: number) => [number, number, number];
394
+ readonly get_metadata_bytes: (a: number, b: number) => [number, number, number, number];
395
+ readonly get_section_markers: (a: number, b: number) => [number, number, number];
396
+ readonly get_synced_lyrics: (a: number, b: number) => [number, number, number];
397
+ readonly get_waveform_data: (a: number, b: number) => [number, number, number];
398
+ readonly has_metadata: (a: number, b: number) => number;
399
+ readonly info: (a: number, b: number) => [number, number, number];
400
+ readonly set_metadata: (a: number, b: number, c: any) => [number, number, number, number];
401
+ readonly set_metadata_field: (a: number, b: number, c: number, d: number, e: any) => [number, number, number, number];
402
+ readonly strip_metadata: (a: number, b: number) => [number, number, number, number];
403
+ readonly update_metadata: (a: number, b: number, c: number, d: number) => [number, number, number, number];
404
+ readonly validate: (a: number, b: number) => [number, number, number];
405
+ readonly version: () => [number, number];
406
+ readonly wasmstreamingdecoder_available_frames: (a: number) => number;
407
+ readonly wasmstreamingdecoder_buffered_bytes: (a: number) => number;
408
+ readonly wasmstreamingdecoder_current_frame_index: (a: number) => number;
409
+ readonly wasmstreamingdecoder_decode_available: (a: number) => [number, number, number, number];
410
+ readonly wasmstreamingdecoder_feed: (a: number, b: number, c: number) => [number, number, number];
411
+ readonly wasmstreamingdecoder_get_info: (a: number) => [number, number, number];
412
+ readonly wasmstreamingdecoder_has_error: (a: number) => number;
413
+ readonly wasmstreamingdecoder_is_finished: (a: number) => number;
414
+ readonly wasmstreamingdecoder_is_ready: (a: number) => number;
415
+ readonly wasmstreamingdecoder_new: () => number;
416
+ readonly wasmstreamingdecoder_next_frame: (a: number) => [number, number, number];
417
+ readonly wasmstreamingdecoder_reset: (a: number) => void;
418
+ readonly wasmstreamingdecoder_state: (a: number) => [number, number];
419
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
420
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
421
+ readonly __wbindgen_exn_store: (a: number) => void;
422
+ readonly __externref_table_alloc: () => number;
423
+ readonly __wbindgen_externrefs: WebAssembly.Table;
424
+ readonly __externref_table_dealloc: (a: number) => void;
425
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
426
+ readonly __wbindgen_start: () => void;
427
+ }
428
+
429
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
430
+
431
+ /**
432
+ * Instantiates the given `module`, which can either be bytes or
433
+ * a precompiled `WebAssembly.Module`.
434
+ *
435
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
436
+ *
437
+ * @returns {InitOutput}
438
+ */
439
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
440
+
441
+ /**
442
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
443
+ * for everything else, calls `WebAssembly.instantiate` directly.
444
+ *
445
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
446
+ *
447
+ * @returns {Promise<InitOutput>}
448
+ */
449
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;