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