export as namespace Flac;
/**
* @property {"FLAC__STREAM_DECODER_INIT_STATUS_OK"} 0 Initialization was successful.
* @property {"FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER"} 1 The library was not compiled with support for the given container format.
* @property {"FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS"} 2 A required callback was not supplied.
* @property {"FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR"} 3 An error occurred allocating memory.
* @property {"FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE"} 4 fopen() failed in FLAC__stream_decoder_init_file() or FLAC__stream_decoder_init_ogg_file().
* @property {"FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"} 5 FLAC__stream_decoder_init_*() was called when the decoder was already initialized, usually because FLAC__stream_decoder_finish() was not called.
*/
export type FLAC__StreamDecoderInitStatus = 0 | 1 | 2 | 3 | 4 | 5;
/**
* @property {"FLAC__STREAM_ENCODER_INIT_STATUS_OK"} 0 Initialization was successful.
* @property {"FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR"} 1 General failure to set up encoder; call FLAC__stream_encoder_get_state() for cause.
* @property {"FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER"} 2 The library was not compiled with support for the given container format.
* @property {"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS"} 3 A required callback was not supplied.
* @property {"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS"} 4 The encoder has an invalid setting for number of channels.
* @property {"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE"} 5 The encoder has an invalid setting for bits-per-sample. FLAC supports 4-32 bps but the reference encoder currently supports only up to 24 bps.
* @property {"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE"} 6 The encoder has an invalid setting for the input sample rate.
* @property {"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE"} 7 The encoder has an invalid setting for the block size.
* @property {"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER"} 8 The encoder has an invalid setting for the maximum LPC order.
* @property {"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION"} 9 The encoder has an invalid setting for the precision of the quantized linear predictor coefficients.
* @property {"FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER"} 10 The specified block size is less than the maximum LPC order.
* @property {"FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE"} 11 The encoder is bound to the Subset but other settings violate it.
* @property {"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA"} 12 The metadata input to the encoder is invalid, in one of the following ways:
* FLAC__stream_encoder_set_metadata() was called with a null pointer but a block count > 0
* One of the metadata blocks contains an undefined type
* It contains an illegal CUESHEET as checked by FLAC__format_cuesheet_is_legal()
* It contains an illegal SEEKTABLE as checked by FLAC__format_seektable_is_legal()
* It contains more than one SEEKTABLE block or more than one VORBIS_COMMENT block
* @property {"FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"} 13 FLAC__stream_encoder_init_*() was called when the encoder was already initialized, usually because FLAC__stream_encoder_finish() was not called.
*/
export type FLAC__StreamEncoderInitStatus = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13;
/**
* Decoding error codes.
*
*
* If the error code is not known, value FLAC__STREAM_DECODER_ERROR__UNKNOWN__ is used.
*
* @property {"FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC"} 0 An error in the stream caused the decoder to lose synchronization.
* @property {"FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER"} 1 The decoder encountered a corrupted frame header.
* @property {"FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH"} 2 The frame's data did not match the CRC in the footer.
* @property {"FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"} 3 The decoder encountered reserved fields in use in the stream.
*/
export type FLAC__StreamDecoderErrorStatus = 0 | 1 | 2 | 3;
/**
* Additional options for encoding or decoding
*
* @property {boolean} [analyseSubframes] for decoding: include subframes metadata in write-callback metadata, DEFAULT: false
* @property {boolean} [analyseResiduals] for decoding: include residual data in subframes metadata in write-callback metadata, NOTE {@link #analyseSubframes} muste also be enabled, DEFAULT: false
* @property {boolean} [enableRawMetadata] DEBUG option for decoding: enable receiving raw metadata for unknown metadata types in second argument in the metadata-callback, DEFAULT: false
* @see Flac#setOptions
* @see Flac~metadata_callback_fn
* @see Flac#FLAC__stream_decoder_set_metadata_respond_all
*/
export interface CodingOptions {
/**
* for decoding: include subframes metadata in write-callback metadata, DEFAULT: false
*/
analyseSubframes?: boolean;
/**
* for decoding: include residual data in subframes metadata in write-callback metadata, NOTE {@link #analyseSubframes} muste also be enabled, DEFAULT: false
*/
analyseResiduals?: boolean;
/**
* DEBUG option for decoding: enable receiving raw metadata for unknown metadata types in second argument in the metadata-callback, DEFAULT: false
*/
enableRawMetadata?: boolean;
}
/**
* FLAC raw metadata
*
* @property {FLAC__MetadataType} type the type of the metadata
* @property {boolean} isLast if it is the last block of metadata
* @property {number} length the length of the metadata block (bytes)
* @property {StreamMetadata | PaddingMetadata | ApplicationMetadata | SeekTableMetadata | CueSheetMetadata | PictureMetadata} [data] the metadata (omitted for unknown metadata types)
* @property {Uint8Array} [raw] raw metadata (for debugging: enable via {@link Flac#setOptions})
*/
export interface MetadataBlock {
/**
* the type of the metadata
*/
type: FLAC__MetadataType;
/**
* if it is the last block of metadata
*/
isLast: boolean;
/**
* the length of the metadata block (bytes)
*/
length: number;
/**
* the metadata (omitted for unknown metadata types)
*/
data?: StreamMetadata | PaddingMetadata | ApplicationMetadata | SeekTableMetadata | CueSheetMetadata | PictureMetadata;
/**
* raw metadata (for debugging: enable via {@link Flac#setOptions})
*/
raw?: Uint8Array;
}
/**
* FLAC padding metadata block
*
* @property {number} dummy Conceptually this is an empty struct since we don't store the padding bytes. Empty structs are not allowed by some C compilers, hence the dummy.
* @see Flac.FLAC__MetadataType#FLAC__METADATA_TYPE_PADDING
*/
export interface PaddingMetadata {
/**
* Conceptually this is an empty struct since we don't store the padding bytes. Empty structs are not allowed by some C compilers, hence the dummy.
*/
dummy: number;
}
/**
* FLAC application metadata block
*
* NOTE the application meta data type is not really supported, i.e. the
* (binary) data is only a pointer to the memory heap.
*
* @property {number} id the application ID
* @property {number} data (pointer)
* @see Flac.FLAC__MetadataType#FLAC__METADATA_TYPE_APPLICATION
* @see {@link https://xiph.org/flac/format.html#metadata_block_application|application block format specification}
*/
export interface ApplicationMetadata {
/**
* the application ID
*/
id: number;
/**
* (pointer)
*/
data: number;
}
/**
* FLAC seek table metadata block
*
*
* From the format specification:
*
* The seek points must be sorted by ascending sample number.
*
* Each seek point's sample number must be the first sample of the target frame.
*
* Each seek point's sample number must be unique within the table
*
* Existence of a SEEKTABLE block implies a correct setting of total_samples in the stream_info block.
*
* Behavior is undefined when more than one SEEKTABLE block is present in a stream.
*
* @property {number} num_points the number of seek points
* @property {Array
* NOTE: only use on un-initilized encoder instances!
*
* @param {number} encoder the ID of the encoder instance
* @param {boolean} is_verify enable/disable checksum verification during encoding
* @returns {boolean}
* NOTE: only use on un-initilized encoder instances!
*
* @param {number} encoder the ID of the encoder instance
* @param {CompressionLevel} compression_level the desired Flac compression level: [0, 8]
* @returns {boolean}
* NOTE: only use on un-initilized encoder instances!
*
* @param {number} encoder the ID of the encoder instance
* @param {number} block_size the number of samples to use per frame
* @returns {boolean}
* NOTE: only use on un-initilized decoder instances!
*
* @param {number} decoder the ID of the decoder instance
* @param {FLAC__MetadataType} type the metadata type to be enabled
* @returns {boolean}
* NOTE: only use on un-initilized decoder instances!
*
* @param {number} decoder the ID of the decoder instance
* @param {number} id the ID of application metadata
* @returns {boolean}
* NOTE: only use on un-initilized decoder instances!
*
* @param {number} decoder the ID of the decoder instance
* @returns {boolean}
* NOTE: only use on un-initilized decoder instances!
*
* @param {number} decoder the ID of the decoder instance
* @param {FLAC__MetadataType} type the metadata type to be ignored
* @returns {boolean}
* NOTE: only use on un-initilized decoder instances!
*
* @param {number} decoder the ID of the decoder instance
* @param {number} id the ID of application metadata
* @returns {boolean}
* NOTE: only use on un-initilized decoder instances!
*
* @param {number} decoder the ID of the decoder instance
* @returns {boolean}
* The encoder stores only copies of the pointers in the metadata array; the metadata blocks themselves must survive at least until after FLAC__stream_encoder_finish() returns.
* Do not free the blocks until then.
*
* The STREAMINFO block is always written and no STREAMINFO block may occur in the supplied array.
*
* By default the encoder does not create a SEEKTABLE. If one is supplied in the metadata array, but the client has specified that it does not support seeking,
* then the SEEKTABLE will be written verbatim. However by itself this is not very useful as the client will not know the stream offsets for the seekpoints ahead of time.
* In order to get a proper seektable the client must support seeking. See next note.
*
* SEEKTABLE blocks are handled specially. Since you will not know the values for the seek point stream offsets, you should pass in a SEEKTABLE 'template', that is,
* a SEEKTABLE object with the required sample numbers (or placeholder points), with 0 for the frame_samples and stream_offset fields for each point.
* If the client has specified that it supports seeking by providing a seek callback to FLAC__stream_encoder_init_stream() or both seek AND read callback to
* FLAC__stream_encoder_init_ogg_stream() (or by using FLAC__stream_encoder_init*_file() or FLAC__stream_encoder_init*_FILE()), then while it is encoding the encoder will
* fill the stream offsets in for you and when encoding is finished, it will seek back and write the real values into the SEEKTABLE block in the stream. There are helper
* routines for manipulating seektable template blocks; see metadata.h: FLAC__metadata_object_seektable_template_*(). If the client does not support seeking,
* the SEEKTABLE will have inaccurate offsets which will slow down or remove the ability to seek in the FLAC stream.
*
* The encoder instance will modify the first SEEKTABLE block as it transforms the template to a valid seektable while encoding, but it is still up to the caller to free
* all metadata blocks after encoding.
*
* A VORBIS_COMMENT block may be supplied. The vendor string in it will be ignored. libFLAC will use it's own vendor string. libFLAC will not modify the passed-in
* VORBIS_COMMENT's vendor string, it will simply write it's own into the stream. If no VORBIS_COMMENT block is present in the metadata array, libFLAC will write an
* empty one, containing only the vendor string.
*
* The Ogg FLAC mapping requires that the VORBIS_COMMENT block be the second metadata block of the stream. The encoder already supplies the STREAMINFO block automatically.
*
* If metadata does not contain a VORBIS_COMMENT block, the encoder will supply that too. Otherwise, if metadata does contain a VORBIS_COMMENT block and it is not the first,
* the init function will reorder metadata by moving the VORBIS_COMMENT block to the front; the relative ordering of the other blocks will remain as they were.
*
* The Ogg FLAC mapping limits the number of metadata blocks per stream to 65535. If num_blocks exceeds this the function will return false.
*
* @param {number} encoder the ID of the encoder instance
* @param {PointerInfo} metadataBuffersPointer
* @param {number} num_blocks
* @returns {boolean}
* NOTE: Needs to be re-initialized, before it can be used again
*
* @param {number} decoder the ID of the decoder instance
* @returns {boolean} true if successful
* @see {@link Flac#init_decoder_stream|init_decoder_stream}
* @see {@link Flac#init_decoder_ogg_stream|init_decoder_ogg_stream}
*/
export function FLAC__stream_decoder_reset(decoder: number): boolean;
/**
* Delete the encoder instance, and free up its resources.
*
* @param {number} encoder the ID of the encoder instance
*/
export function FLAC__stream_encoder_delete(encoder: number): void;
/**
* Delete the decoder instance, and free up its resources.
*
* @param {number} decoder the ID of the decoder instance
*/
export function FLAC__stream_decoder_delete(decoder: number): void;
export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;-1 for a placeholder point.
* @property {number} stream_offset The offset, in bytes, of the target frame with respect to beginning of the first frame.
* @property {number} frame_samples The number of samples in the target frame.
* @see Flac.SeekTableMetadata
*/
export interface SeekPoint {
/**
* The sample number of the target frame. NOTE -1 for a placeholder point.
*/
sample_number: number;
/**
* The offset, in bytes, of the target frame with respect to beginning of the first frame.
*/
stream_offset: number;
/**
* The number of samples in the target frame.
*/
frame_samples: number;
}
/**
* FLAC vorbis comment metadata block
*
* @property {string} vendor_string the vendor string
* @property {number} num_comments the number of comments
* @property {Arraytrue, if Flac is ready to be used
* @see {@link Flac#onready|onready}
* @see {@link Flac#on|on}
*/
export function isReady(): boolean;
/**
* Hook for handler function that gets called, when asynchronous initialization has finished.
*
* NOTE that if the execution environment does not support Object#defineProperty, then
* this function is not called, after {@link Flac#isReady|isReady} is true.
* In this case, {@link Flac#isReady|isReady} should be checked, before setting onready
* and if it is true, handler should be executed immediately instead of setting onready.
*
* @param {ReadyEvent} event the ready-event object
* @see {@link Flac#isReady|isReady}
* @see {@link Flac#on|on}
* @example
* // [1] if Object.defineProperty() IS supported:
* Flac.onready = function(event){
* //gets executed when library becomes ready, or immediately, if it already is ready...
* doSomethingWithFlac();
* };
*
* // [2] if Object.defineProperty() is NOT supported:
* // do check Flac.isReady(), and only set handler, if not ready yet
* // (otherwise immediately excute handler code)
* if(!Flac.isReady()){
* Flac.onready = function(event){
* //gets executed when library becomes ready...
* doSomethingWithFlac();
* };
* } else {
* // Flac is already ready: immediately start processing
* doSomethingWithFlac();
* }
*/
export var onready: ((event: ReadyEvent) => void)|undefined;
/**
* Ready event: is fired when the library has been initialized and is ready to be used
* (e.g. asynchronous loading of binary / WASM modules has been completed).
*
* Before this event is fired, use of functions related to encoding and decoding may
* cause errors.
*
* @property {"ready"} type the type of the event "ready"
* @property {any} target the initalized FLAC library instance
* @see {@link Flac#isReady|isReady}
* @see {@link Flac#on|on}
*/
export interface ReadyEvent {
/**
* the type of the event "ready"
*/
type: "ready";
/**
* the initalized FLAC library instance
*/
target: any;
}
/**
* Created event: is fired when an encoder or decoder was created.
*
* @property {"created"} type the type of the event "created"
* @property {CoderChangedEventData} target the information for the created encoder or decoder
* @see {@link Flac#on|on}
*/
export interface CreatedEvent {
/**
* the type of the event "created"
*/
type: "created";
/**
* the information for the created encoder or decoder
*/
target: CoderChangedEventData;
}
/**
* Destroyed event: is fired when an encoder or decoder was destroyed.
*
* @property {"destroyed"} type the type of the event "destroyed"
* @property {CoderChangedEventData} target the information for the destroyed encoder or decoder
* @see {@link Flac#on|on}
*/
export interface DestroyedEvent {
/**
* the type of the event "destroyed"
*/
type: "destroyed";
/**
* the information for the destroyed encoder or decoder
*/
target: CoderChangedEventData;
}
/**
* Life cycle event data for signaling life cycle changes of encoder or decoder instances
*
* @property {number} id the ID for the encoder or decoder instance
* @property {"encoder" | "decoder"} type signifies whether the event is for an encoder or decoder instance
* @property {any} [data] specific data for the life cycle change
* @see Flac.event:CreatedEvent
* @see Flac.event:DestroyedEvent
*/
export interface CoderChangedEventData {
/**
* the ID for the encoder or decoder instance
*/
id: number;
/**
* signifies whether the event is for an encoder or decoder instance
*/
type: "encoder" | "decoder";
/**
* specific data for the life cycle change
*/
data?: any;
}
/**
* Add an event listener for module-events.
* Supported events:
*
*
*
* @param {string} eventName
* @param {Function} listener
* @see {@link Flac#off|off}
* @see {@link Flac#onready|onready}
* @see Flac.event:ReadyEvent
* @see Flac.event:CreatedEvent
* @see Flac.event:DestroyedEvent
* @example
* Flac.on('ready', function(event){
* //gets executed when library is ready, or becomes ready...
* });
*/
export function on(eventName: string, listener: Function): void;
/**
* Remove an event listener for module-events.
*
* @param {string} eventName
* @param {Function} listener
* @see {@link Flac#on|on}
*/
export function off(eventName: string, listener: Function): void;
/**
* Set the "verify" flag. If true, the encoder will verify it's own encoded output by feeding it through an internal decoder and comparing the original signal against the decoded signal. If a mismatch occurs, the process call will return false. Note that this will slow the encoding process by the extra time required for decoding and comparison.
*
* "ready" → {@link Flac.event:ReadyEvent}: emitted when module is ready for usage (i.e. {@link Flac#isReady|isReady} is true)
* NOTE listener will get immediately triggered if module is already "ready"
* "created" → {@link Flac.event:CreatedEvent}: emitted when an encoder or decoder instance was created
* "destroyed" → {@link Flac.event:DestroyedEvent}: emitted when an encoder or decoder instance was destroyed
* false if the encoder is already initialized, else true
* @see {@link Flac#create_libflac_encoder|create_libflac_encoder}
* @see {@link Flac#FLAC__stream_encoder_get_verify|FLAC__stream_encoder_get_verify}
*/
export function FLAC__stream_encoder_set_verify(encoder: number, is_verify: boolean): boolean;
/**
* Set the compression level
*
* The compression level is roughly proportional to the amount of effort the encoder expends to compress the file. A higher level usually means more computation but higher compression. The default level is suitable for most applications.
*
* Currently the levels range from 0 (fastest, least compression) to 8 (slowest, most compression). A value larger than 8 will be treated as 8.
*
*
* false if the encoder is already initialized, else true
* @see {@link Flac#create_libflac_encoder|create_libflac_encoder}
* @see Flac.CompressionLevel
* @see {@link https://xiph.org/flac/api/group__flac__stream__encoder.html#gae49cf32f5256cb47eecd33779493ac85|FLAC API for FLAC__stream_encoder_set_compression_level()}
*/
export function FLAC__stream_encoder_set_compression_level(encoder: number, compression_level: CompressionLevel): boolean;
/**
* Set the blocksize to use while encoding.
* The number of samples to use per frame. Use 0 to let the encoder estimate a blocksize; this is usually best.
*
* false if the encoder is already initialized, else true
* @see {@link Flac#create_libflac_encoder|create_libflac_encoder}
*/
export function FLAC__stream_encoder_set_blocksize(encoder: number, block_size: number): boolean;
/**
* Get the state of the verify stream decoder. Useful when the stream encoder state is FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR.
*
* @param {number} encoder the ID of the encoder instance
* @returns {FLAC__StreamDecoderState} the verify stream decoder state
*/
export function FLAC__stream_encoder_get_verify_decoder_state(encoder: number): FLAC__StreamDecoderState;
/**
* Get the "verify" flag for the encoder.
*
* @param {number} encoder the ID of the encoder instance
* @returns {boolean} the verify flag for the encoder
* @see {@link Flac#FLAC__stream_encoder_set_verify|FLAC__stream_encoder_set_verify}
*/
export function FLAC__stream_encoder_get_verify(encoder: number): boolean;
/**
* Set the compression level
*
* The compression level is roughly proportional to the amount of effort the encoder expends to compress the file. A higher level usually means more computation but higher compression. The default level is suitable for most applications.
*
* Currently the levels range from 0 (fastest, least compression) to 8 (slowest, most compression). A value larger than 8 will be treated as 8.
*
* This function automatically calls the following other set functions with appropriate values, so the client does not need to unless it specifically wants to override them:
*
* FLAC__stream_encoder_set_do_mid_side_stereo()
* FLAC__stream_encoder_set_loose_mid_side_stereo()
* FLAC__stream_encoder_set_apodization()
* FLAC__stream_encoder_set_max_lpc_order()
* FLAC__stream_encoder_set_qlp_coeff_precision()
* FLAC__stream_encoder_set_do_qlp_coeff_prec_search()
* FLAC__stream_encoder_set_do_escape_coding()
* FLAC__stream_encoder_set_do_exhaustive_model_search()
* FLAC__stream_encoder_set_min_residual_partition_order()
* FLAC__stream_encoder_set_max_residual_partition_order()
* FLAC__stream_encoder_set_rice_parameter_search_dist()
*
* The actual values set for each level are:
* | level | do mid-side stereo | loose mid-side stereo | apodization | max lpc order | qlp coeff precision | qlp coeff prec search | escape coding | exhaustive model search | min residual partition order | max residual partition order | rice parameter search dist |
* |--------|---------------------|------------------------|------------------------------------------------|----------------|----------------------|------------------------|----------------|--------------------------|-------------------------------|-------------------------------|------------------------------|
* | 0 | false | false | tukey(0.5) | 0 | 0 | false | false | false | 0 | 3 | 0 |
* | 1 | true | true | tukey(0.5) | 0 | 0 | false | false | false | 0 | 3 | 0 |
* | 2 | true | false | tukey(0.5) | 0 | 0 | false | false | false | 0 | 3 | 0 |
* | 3 | false | false | tukey(0.5) | 6 | 0 | false | false | false | 0 | 4 | 0 |
* | 4 | true | true | tukey(0.5) | 8 | 0 | false | false | false | 0 | 4 | 0 |
* | 5 | true | false | tukey(0.5) | 8 | 0 | false | false | false | 0 | 5 | 0 |
* | 6 | true | false | tukey(0.5);partial_tukey(2) | 8 | 0 | false | false | false | 0 | 6 | 0 |
* | 7 | true | false | tukey(0.5);partial_tukey(2) | 12 | 0 | false | false | false | 0 | 6 | 0 |
* | 8 | true | false | tukey(0.5);partial_tukey(2);punchout_tukey(3) | 12 | 0 | false | false | false | 0 | 6 | 0 |
*
* @property {"FLAC__COMPRESSION_LEVEL_0"} 0 compression level 0
* @property {"FLAC__COMPRESSION_LEVEL_1"} 1 compression level 1
* @property {"FLAC__COMPRESSION_LEVEL_2"} 2 compression level 2
* @property {"FLAC__COMPRESSION_LEVEL_3"} 3 compression level 3
* @property {"FLAC__COMPRESSION_LEVEL_4"} 4 compression level 4
* @property {"FLAC__COMPRESSION_LEVEL_5"} 5 compression level 5
* @property {"FLAC__COMPRESSION_LEVEL_6"} 6 compression level 6
* @property {"FLAC__COMPRESSION_LEVEL_7"} 7 compression level 7
* @property {"FLAC__COMPRESSION_LEVEL_8"} 8 compression level 8
*/
export type CompressionLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
/**
* Create an encoder.
*
* @param {number} sample_rate the sample rate of the input PCM data
* @param {number} channels the number of channels of the input PCM data
* @param {number} bps bits per sample of the input PCM data
* @param {CompressionLevel} compression_level the desired Flac compression level: [0, 8]
* @param {number} [total_samples] OPTIONAL
* the number of total samples of the input PCM data:
* Sets an estimate of the total samples that will be encoded.
* This is merely an estimate and may be set to 0 if unknown.
* This value will be written to the STREAMINFO block before encoding,
* and can remove the need for the caller to rewrite the value later if
* the value is known before encoding.
* If specified, the it will be written into metadata of the FLAC header.
* DEFAULT: 0 (i.e. unknown number of samples)
* @param {boolean} [is_verify] OPTIONAL
* enable/disable checksum verification during encoding
* DEFAULT: true
* NOTE: this argument is positional (i.e. total_samples must also be given)
* @param {number} [block_size] OPTIONAL
* the number of samples to use per frame.
* DEFAULT: 0 (i.e. encoder sets block size automatically)
* NOTE: this argument is positional (i.e. total_samples and is_verify must also be given)
* @returns {number} the ID of the created encoder instance (or 0, if there was an error)
*/
export function create_libflac_encoder(sample_rate: number, channels: number, bps: number, compression_level: CompressionLevel, total_samples?: number, is_verify?: boolean, block_size?: number): number;
/**
* @use {@link Flac#create_libflac_encoder|create_libflac_encoder} instead
*/
export function init_libflac_encoder(): void;
/**
* Create a decoder.
*
* @param {boolean} [is_verify] enable/disable checksum verification during decoding
* DEFAULT: true
* @returns {number} the ID of the created decoder instance (or 0, if there was an error)
*/
export function create_libflac_decoder(is_verify?: boolean): number;
/**
* @use {@link Flac#create_libflac_decoder|create_libflac_decoder} instead
*/
export function init_libflac_decoder(): void;
/**
* The callback for writing the encoded FLAC data.
*
* @param {Uint8Array} data the encoded FLAC data
* @param {number} numberOfBytes the number of bytes in data
* @param {number} samples the number of samples encoded in data
* @param {number} currentFrame the number of the (current) encoded frame in data
* @returns {void | false} returning false indicates that an
* unrecoverable error occurred and decoding should be aborted
*/
export type encoder_write_callback_fn = (data: Uint8Array, numberOfBytes: number, samples: number, currentFrame: number) => void | false;
/**
* The callback for the metadata of the encoded/decoded Flac data.
*
* By default, only the STREAMINFO metadata is enabled.
*
* For other metadata types {@link Flac.FLAC__MetadataType} they need to be enabled,
* see e.g. {@link Flac#FLAC__stream_decoder_set_metadata_respond}
*
* @param {StreamMetadata | undefined} metadata the FLAC meta data, NOTE only STREAMINFO is returned in first argument, for other types use 2nd argument's metadataBlock.data
* @param {MetadataBlock} metadataBlock the detailed meta data block
* @see Flac#init_decoder_stream
* @see Flac#init_encoder_stream
* @see Flac.CodingOptions
* @see Flac#FLAC__stream_decoder_set_metadata_respond_all
*/
export type metadata_callback_fn = (metadata: StreamMetadata | undefined, metadataBlock: MetadataBlock) => void;
/**
* FLAC meta data
*
* @property {number} sampleRate the sample rate (Hz)
* @property {number} channels the number of channels
* @property {number} bitsPerSample bits per sample
*/
export interface Metadata {
/**
* the sample rate (Hz)
*/
sampleRate: number;
/**
* the number of channels
*/
channels: number;
/**
* bits per sample
*/
bitsPerSample: number;
}
/**
* FLAC stream meta data
*
* @augments Flac.Metadata
* @property {number} min_blocksize the minimal block size (bytes)
* @property {number} max_blocksize the maximal block size (bytes)
* @property {number} min_framesize the minimal frame size (bytes)
* @property {number} max_framesize the maximal frame size (bytes)
* @property {number} total_samples the total number of (encoded/decoded) samples
* @property {string} md5sum the MD5 checksum for the decoded data (if validation is active)
* @property {number} sampleRate the sample rate (Hz)
* @property {number} channels the number of channels
* @property {number} bitsPerSample bits per sample
*/
export interface StreamMetadata {
/**
* the minimal block size (bytes)
*/
min_blocksize: number;
/**
* the maximal block size (bytes)
*/
max_blocksize: number;
/**
* the minimal frame size (bytes)
*/
min_framesize: number;
/**
* the maximal frame size (bytes)
*/
max_framesize: number;
/**
* the total number of (encoded/decoded) samples
*/
total_samples: number;
/**
* the MD5 checksum for the decoded data (if validation is active)
*/
md5sum: string;
/**
* the sample rate (Hz)
*/
sampleRate: number;
/**
* the number of channels
*/
channels: number;
/**
* bits per sample
*/
bitsPerSample: number;
}
/**
* Initialize the encoder.
*
* @param {number} encoder the ID of the encoder instance that has not been initialized (or has been reset)
* @param {encoder_write_callback_fn} write_callback_fn the callback for writing the encoded Flac data:
* write_callback_fn(data: Uint8Array, numberOfBytes: Number, samples: Number, currentFrame: Number)
* @param {metadata_callback_fn} [metadata_callback_fn] OPTIONAL
* the callback for the metadata of the encoded Flac data:
* metadata_callback_fn(metadata: StreamMetadata)
* @param {number | boolean} [ogg_serial_number] OPTIONAL
* if number or true is specified, the encoder will be initialized to
* write to an OGG container, see {@link Flac.init_encoder_ogg_stream}:
* true will set a default serial number (1),
* if specified as number, it will be used as the stream's serial number within the ogg container.
* @returns {FLAC__StreamEncoderInitStatus} the encoder status (0 for FLAC__STREAM_ENCODER_INIT_STATUS_OK)
*/
export function init_encoder_stream(encoder: number, write_callback_fn: encoder_write_callback_fn, metadata_callback_fn?: metadata_callback_fn, ogg_serial_number?: number | boolean): FLAC__StreamEncoderInitStatus;
/**
* Initialize the encoder for writing to an OGG container.
*
* @param {number} encoder the ID of the encoder instance that has not been initialized (or has been reset)
* @param {encoder_write_callback_fn} write_callback_fn the callback for writing the encoded Flac data:
* write_callback_fn(data: Uint8Array, numberOfBytes: Number, samples: Number, currentFrame: Number)
* @param {metadata_callback_fn} [metadata_callback_fn] OPTIONAL
* the callback for the metadata of the encoded Flac data:
* metadata_callback_fn(metadata: StreamMetadata)
* @param {number} [ogg_serial_number] OPTIONAL
* the serial number for the stream in the OGG container
* DEFAULT: 1
* @returns {FLAC__StreamEncoderInitStatus} the encoder status (0 for FLAC__STREAM_ENCODER_INIT_STATUS_OK)
*/
export function init_encoder_ogg_stream(encoder: number, write_callback_fn: encoder_write_callback_fn, metadata_callback_fn?: metadata_callback_fn, ogg_serial_number?: number): FLAC__StreamEncoderInitStatus;
/**
* Result / return value for {@link Flac~decoder_read_callback_fn} callback function
*
* @property {TypedArray} buffer a TypedArray (e.g. Uint8Array) with the read data
* @property {number} readDataLength the number of read data bytes. A number of 0 (zero) indicates that the end-of-stream is reached.
* @property {boolean} [error] OPTIONAL value of true indicates that an error occured (decoding will be aborted)
*/
export interface ReadResult {
/**
* a TypedArray (e.g. Uint8Array) with the read data
*/
buffer: TypedArray;
/**
* the number of read data bytes. A number of 0 (zero) indicates that the end-of-stream is reached.
*/
readDataLength: number;
/**
* OPTIONAL value of true indicates that an error occured (decoding will be aborted)
*/
error?: boolean;
}
/**
* Result / return value for {@link Flac~decoder_read_callback_fn} callback function for signifying that there is no more data to read
*
* @augments Flac.ReadResult
* @property {TypedArray | undefined} buffer a TypedArray (e.g. Uint8Array) with the read data (will be ignored in case readDataLength is 0)
* @property {0} readDataLength the number of read data bytes: The number of 0 (zero) indicates that the end-of-stream is reached.
* @property {boolean} [error] OPTIONAL value of true indicates that an error occured (decoding will be aborted)
*/
export interface CompletedReadResult {
/**
* a TypedArray (e.g. Uint8Array) with the read data (will be ignored in case readDataLength is 0)
*/
buffer: TypedArray | undefined;
/**
* the number of read data bytes: The number of 0 (zero) indicates that the end-of-stream is reached.
*/
readDataLength: 0;
/**
* OPTIONAL value of true indicates that an error occured (decoding will be aborted)
*/
error?: boolean;
}
/**
* The callback for reading the FLAC data that will be decoded.
*
* @param {number} numberOfBytes the maximal number of bytes that the read callback can return
* @returns {ReadResult | CompletedReadResult} the result of the reading action/request
*/
export type decoder_read_callback_fn = (numberOfBytes: number) => ReadResult | CompletedReadResult;
/**
* The callback for writing the decoded FLAC data.
*
* @param {ArrayUint8Arrays
* @param {BlockMetadata} frameInfo the metadata information for the decoded data
*/
export type decoder_write_callback_fn = (data: Arraynumber refers to: either "frames" or "samples"
* @property {FLAC__ChannelAssignment} channelAssignment the channel assignment
* @property {string} crc the MD5 checksum for the decoded data, if validation is enabled
* @property {Arraynumber refers to: either "frames" or "samples"
*/
numberType: string;
/**
* the channel assignment
*/
channelAssignment: FLAC__ChannelAssignment;
/**
* the MD5 checksum for the decoded data, if validation is enabled
*/
crc: string;
/**
* the metadata of the subframes. The array length corresponds to the number of channels. NOTE will only be included if {@link Flac.CodingOptions CodingOptions.analyseSubframes} is enabled for the decoder.
*/
subframes?: Arrayread_callback_fn(numberOfBytes: Number) : {buffer: ArrayBuffer, readDataLength: number, error: boolean}
* @param {decoder_write_callback_fn} write_callback_fn the callback for writing the decoded data:
* write_callback_fn(data: Uint8Array[], frameInfo: Metadata)
* @param {decoder_error_callback_fn} error_callback_fn the error callback:
* error_callback_fn(errorCode: Number, errorDescription: String)
* @param {metadata_callback_fn} [metadata_callback_fn] OPTIONAL
* callback for receiving the metadata of FLAC data that will be decoded:
* metadata_callback_fn(metadata: StreamMetadata)
* @param {number | boolean} [ogg_serial_number] OPTIONAL
* if number or true is specified, the decoder will be initilized to
* read from an OGG container, see {@link Flac.init_decoder_ogg_stream}:
* true will use the default serial number, if specified as number the
* corresponding stream with the serial number from the ogg container will be used.
* @returns {FLAC__StreamDecoderInitStatus} the decoder status(0 for FLAC__STREAM_DECODER_INIT_STATUS_OK)
*/
export function init_decoder_stream(decoder: number, read_callback_fn: decoder_read_callback_fn, write_callback_fn: decoder_write_callback_fn, error_callback_fn: decoder_error_callback_fn, metadata_callback_fn?: metadata_callback_fn, ogg_serial_number?: number | boolean): FLAC__StreamDecoderInitStatus;
/**
* Initialize the decoder for writing to an OGG container.
*
* @param {number} decoder the ID of the decoder instance that has not been initialized (or has been reset)
* @param {decoder_read_callback_fn} read_callback_fn the callback for reading the Flac data that should get decoded:
* read_callback_fn(numberOfBytes: Number) : {buffer: ArrayBuffer, readDataLength: number, error: boolean}
* @param {decoder_write_callback_fn} write_callback_fn the callback for writing the decoded data:
* write_callback_fn(data: Uint8Array[], frameInfo: Metadata)
* @param {decoder_error_callback_fn} error_callback_fn the error callback:
* error_callback_fn(errorCode: Number, errorDescription: String)
* @param {metadata_callback_fn} [metadata_callback_fn] OPTIONAL
* callback for receiving the metadata of FLAC data that will be decoded:
* metadata_callback_fn(metadata: StreamMetadata)
* @param {number} [ogg_serial_number] OPTIONAL
* the serial number for the stream in the OGG container that should be decoded.
* The default behavior is to use the serial number of the first Ogg page. Setting a serial number here will explicitly specify which stream is to be decoded.
* @returns {FLAC__StreamDecoderInitStatus} the decoder status(0 for FLAC__STREAM_DECODER_INIT_STATUS_OK)
*/
export function init_decoder_ogg_stream(decoder: number, read_callback_fn: decoder_read_callback_fn, write_callback_fn: decoder_write_callback_fn, error_callback_fn: decoder_error_callback_fn, metadata_callback_fn?: metadata_callback_fn, ogg_serial_number?: number): FLAC__StreamDecoderInitStatus;
/**
* Encode / submit data for encoding.
*
* This version allows you to supply the input data where the channels are interleaved into a
* single array (i.e. channel0_sample0, channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
*
* The samples need not be block-aligned but they must be sample-aligned, i.e. the first value should be
* channel0_sample0 and the last value channelN_sampleM.
*
* Each sample should be a signed integer, right-justified to the resolution set by bits-per-sample.
*
* For example, if the resolution is 16 bits per sample, the samples should all be in the range [-32768,32767].
*
*
* For applications where channel order is important, channels must follow the order as described in the frame header.
*
* @param {number} encoder the ID of the encoder instance
* @param {TypedArray} buffer the audio data in a typed array with signed integers (and size according to the set bits-per-sample setting)
* @param {number} num_of_samples the number of samples in buffer
* @returns {boolean} true if successful, else false; in this case, check the encoder state with FLAC__stream_encoder_get_state() to see what went wrong.
*/
export function FLAC__stream_encoder_process_interleaved(encoder: number, buffer: TypedArray, num_of_samples: number): boolean;
/**
* Encode / submit data for encoding.
*
* Submit data for encoding. This version allows you to supply the input data via an array of pointers,
* each pointer pointing to an array of samples samples representing one channel.
* The samples need not be block-aligned, but each channel should have the same number of samples.
*
* Each sample should be a signed integer, right-justified to the resolution set by FLAC__stream_encoder_set_bits_per_sample().
* For example, if the resolution is 16 bits per sample, the samples should all be in the range [-32768,32767].
*
*
* For applications where channel order is important, channels must follow the order as described in the frame header.
*
* @param {number} encoder the ID of the encoder instance
* @param {Arrayfalse if the decoder is already initialized, else true
* @see Flac#FLAC__stream_decoder_set_metadata_respond_all
*/
export function FLAC__stream_decoder_set_metadata_respond(decoder: number, type: FLAC__MetadataType): boolean;
/**
* Direct the decoder to pass on all APPLICATION metadata blocks of the given id.
*
* By default, only the STREAMINFO block is returned via the metadata callback.
*
* false if the decoder is already initialized, else true
* @see Flac#FLAC__stream_decoder_set_metadata_respond_all
*/
export function FLAC__stream_decoder_set_metadata_respond_application(decoder: number, id: number): boolean;
/**
* Direct the decoder to pass on all metadata blocks of any type.
*
* By default, only the STREAMINFO block is returned via the metadata callback.
*
* false if the decoder is already initialized, else true
* @see Flac#FLAC__stream_decoder_set_metadata_ignore_all
* @see Flac#FLAC__stream_decoder_set_metadata_respond_application
* @see Flac#FLAC__stream_decoder_set_metadata_respond
*/
export function FLAC__stream_decoder_set_metadata_respond_all(decoder: number): boolean;
/**
* Direct the decoder to filter out all metadata blocks of type type.
*
* By default, only the STREAMINFO block is returned via the metadata callback.
*
* false if the decoder is already initialized, else true
* @see Flac#FLAC__stream_decoder_set_metadata_ignore_all
*/
export function FLAC__stream_decoder_set_metadata_ignore(decoder: number, type: FLAC__MetadataType): boolean;
/**
* Direct the decoder to filter out all APPLICATION metadata blocks of the given id.
*
* By default, only the STREAMINFO block is returned via the metadata callback.
*
* false if the decoder is already initialized, else true
* @see Flac#FLAC__stream_decoder_set_metadata_ignore_all
*/
export function FLAC__stream_decoder_set_metadata_ignore_application(decoder: number, id: number): boolean;
/**
* Direct the decoder to filter out all metadata blocks of any type.
*
* By default, only the STREAMINFO block is returned via the metadata callback.
*
* false if the decoder is already initialized, else true
* @see Flac#FLAC__stream_decoder_set_metadata_respond_all
* @see Flac#FLAC__stream_decoder_set_metadata_ignore
* @see Flac#FLAC__stream_decoder_set_metadata_ignore_application
*/
export function FLAC__stream_decoder_set_metadata_ignore_all(decoder: number): boolean;
/**
* Set the metadata blocks to be emitted to the stream before encoding. A value of NULL, 0 implies no metadata; otherwise, supply an array of pointers to metadata blocks.
* The array is non-const since the encoder may need to change the is_last flag inside them, and in some cases update seek point offsets. Otherwise, the encoder
* will not modify or free the blocks. It is up to the caller to free the metadata blocks after encoding finishes.
*
* false if the encoder is already initialized, else true. false if the encoder is already initialized, or if num_blocks > 65535 if encoding to Ogg FLAC, else true.
* @see Flac.FLAC__MetadataType
* @see Flac#_create_pointer_array
* @see Flac#_destroy_pointer_array
*/
export function FLAC__stream_encoder_set_metadata(encoder: number, metadataBuffersPointer: PointerInfo, num_blocks: number): boolean;
/**
* Helper object for allocating an array of buffers on the (memory) heap.
*
* @property {number} pointerPointer pointer to the array of (pointer) buffers
* @property {ArrayPointerInfo.dataPointer as argument, where the array-pointer is required.
*
* NOTE: afer use, the allocated buffers on the heap need be freed, see {@link Flac#_destroy_pointer_array|_destroy_pointer_array}.
*
* @param {Arrayfalse if the decoder is already initialized, else true
* @see Flac#_destroy_pointer_array
*/
export function _create_pointer_array(bufferArray: Arraytrue if MD5 verification is enabled
* @see {@link Flac#FLAC__stream_decoder_set_md5_checking|FLAC__stream_decoder_set_md5_checking}
*/
export function FLAC__stream_decoder_get_md5_checking(decoder: number): boolean;
/**
* Set the "MD5 signature checking" flag. If true, the decoder will compute the MD5 signature of the unencoded audio data while decoding and compare it to the signature from the STREAMINFO block,
* if it exists, during {@link Flac.FLAC__stream_decoder_finish FLAC__stream_decoder_finish()}.
*
* MD5 signature checking will be turned off (until the next {@link Flac.FLAC__stream_decoder_reset FLAC__stream_decoder_reset()}) if there is no signature in the STREAMINFO block or when a seek is attempted.
*
* Clients that do not use the MD5 check should leave this off to speed up decoding.
*
* @param {number} decoder the ID of the decoder instance
* @param {boolean} is_verify enable/disable checksum verification during decoding
* @returns {boolean} FALSE if the decoder is already initialized, else TRUE.
* @see {@link Flac#FLAC__stream_decoder_get_md5_checking|FLAC__stream_decoder_get_md5_checking}
*/
export function FLAC__stream_decoder_set_md5_checking(decoder: number, is_verify: boolean): boolean;
/**
* Finish the encoding process.
*
* @param {number} encoder the ID of the encoder instance
* @returns {boolean} false if an error occurred processing the last frame;
* or if verify mode is set, there was a verify mismatch; else true.
* If false, caller should check the state with {@link Flac#FLAC__stream_encoder_get_state}
* for more information about the error.
*/
export function FLAC__stream_encoder_finish(encoder: number): boolean;
/**
* Finish the decoding process.
*
* The decoder can be reused, after initializing it again.
*
* @param {number} decoder the ID of the decoder instance
* @returns {boolean} false if MD5 checking is on AND a STREAMINFO block was available AND the MD5 signature in
* the STREAMINFO block was non-zero AND the signature does not match the one computed by the decoder;
* else true.
*/
export function FLAC__stream_decoder_finish(decoder: number): boolean;
/**
* Reset the decoder for reuse.
*
*