Commit 00e53874 authored by Josh Coalson's avatar Josh Coalson
Browse files

revamp encoder/decoder interface to use set methods instead on args to init

parent c84e95b6
......@@ -800,6 +800,7 @@
<P>
The file decoder is a wrapper around the stream decoder meant to simplfy the process of decoding from a file. The instance type is <TT>FLAC__FileDecoder</TT>. The flow and callbacks are similar to that of the stream decoder. However, a file path replaces the read callback argument during initialization. The program needs only to provide the path to the file and the file decoder handles the read callbacks. The remaining callbacks and process functions are analogous to their stream decoder counterparts.
</P>
@@@MD5 checking
<P>
Since the file decoder manages the input automatically, it also can provide seeking. This is exposed through the <TT>FLAC__file_decoder_seek_absolute()</TT> method. At any point after the file decoder has been initialized, the program can call this function to seek to an exact sample within the file. Subsequently, the first time the write callback is called it will contain a (possibly partial) block starting at that sample.
</P>
......
......@@ -33,6 +33,7 @@ typedef enum {
FLAC__FILE_DECODER_MD5_ERROR,
FLAC__FILE_DECODER_STREAM_DECODER_ERROR,
FLAC__FILE_DECODER_ALREADY_INITIALIZED,
FLAC__FILE_DECODER_INVALID_CALLBACK,
FLAC__FILE_DECODER_UNINITIALIZED
} FLAC__FileDecoderState;
extern const char *FLAC__FileDecoderStateString[];
......@@ -56,6 +57,17 @@ typedef struct {
*
***********************************************************************/
/*
* Any parameters that are not set before FLAC__file_decoder_init()
* will take on the defaults from the constructor, shown below.
* For more on what the parameters mean, see the documentation.
*
* bool md5_checking (DEFAULT: false) MD5 checking will be turned off if a seek is requested
* (*write_callback)() (DEFAULT: NULL ) The callbacks are the only values that MUST be set before FLAC__file_decoder_init()
* (*metadata_callback)() (DEFAULT: NULL )
* (*error_callback)() (DEFAULT: NULL )
* void* client_data (DEFAULT: NULL ) passed back through the callbacks
*/
FLAC__FileDecoder *FLAC__file_decoder_new();
void FLAC__file_decoder_delete(FLAC__FileDecoder *);
......@@ -66,34 +78,53 @@ void FLAC__file_decoder_delete(FLAC__FileDecoder *);
***********************************************************************/
/*
* Initialize the instance; should be called after construction and
* before any other calls. Will set and return the decoder state,
* which will be FLAC__FILE_DECODER_OK if initialization succeeded.
* Various "set" methods. These may only be called when the decoder
* is in the state FLAC__FILE_DECODER_UNINITIALIZED, i.e. after
* FLAC__file_decoder_new() or FLAC__file_decoder_finish(), but
* before FLAC__file_decoder_init(). If this is the case they will
* return true, otherwise false.
*
* NOTE that these functions do not validate the values as many are
* interdependent. The FLAC__file_decoder_init() function will do
* this, so make sure to pay attention to the state returned by
* FLAC__file_decoder_init().
*
* Any parameters that are not set before FLAC__file_decoder_init()
* will take on the defaults from the constructor. NOTE that
* FLAC__file_decoder_flush() or FLAC__file_decoder_reset() do
* NOT reset the values to the constructor defaults.
*/
FLAC__FileDecoderState FLAC__file_decoder_init(
FLAC__FileDecoder *decoder,
bool check_md5,
const char *filename,
FLAC__StreamDecoderWriteStatus (*write_callback)(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data),
void (*metadata_callback)(const FLAC__FileDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data),
void (*error_callback)(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data),
void *client_data
);
bool FLAC__file_decoder_set_md5_checking(const FLAC__FileDecoder *decoder, bool value);
bool FLAC__file_decoder_set_filename(const FLAC__FileDecoder *decoder, const char *value);
bool FLAC__file_decoder_set_write_callback(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderWriteStatus (*value)(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data));
bool FLAC__file_decoder_set_metadata_callback(const FLAC__FileDecoder *decoder, void (*value)(const FLAC__FileDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data));
bool FLAC__file_decoder_set_error_callback(const FLAC__FileDecoder *decoder, void (*value)(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data));
bool FLAC__file_decoder_set_client_data(const FLAC__FileDecoder *decoder, void *value);
/*
* only returns false if check_md5 is set AND the stored MD5 sum
* is non-zero AND the stored MD5 sum and computed MD5 sum do not
* match
* Various "get" methods
*/
bool FLAC__file_decoder_finish(FLAC__FileDecoder *decoder);
FLAC__FileDecoderState FLAC__file_decoder_get_state(const FLAC__FileDecoder *decoder);
bool FLAC__file_decoder_get_md5_checking(const FLAC__FileDecoder *decoder);
/*
* Initialize the instance; should be called after construction and
* 'set' calls but before any of the 'process' or 'seek' calls. Will
* set and return the decoder state, which will be FLAC__FILE_DECODER_OK
* if initializationsucceeded.
*/
FLAC__FileDecoderState FLAC__file_decoder_init(FLAC__FileDecoder *decoder);
/*
* methods to return the file decoder state and check_md5 flag
* Flush the decoding buffer, release resources, and return the decoder
* state to FLAC__FILE_DECODER_UNINITIALIZED. Only returns false if
* md5_checking is set AND the stored MD5 sum is non-zero AND the stored
* MD5 sum and computed MD5 sum do not match.
*/
FLAC__FileDecoderState FLAC__file_decoder_state(const FLAC__FileDecoder *decoder);
bool FLAC__file_decoder_check_md5(const FLAC__FileDecoder *decoder);
bool FLAC__file_decoder_finish(FLAC__FileDecoder *decoder);
/*
* methods for decoding the data
* Methods for decoding the data
*/
bool FLAC__file_decoder_process_whole_file(FLAC__FileDecoder *decoder);
bool FLAC__file_decoder_process_metadata(FLAC__FileDecoder *decoder);
......
......@@ -32,6 +32,7 @@ typedef enum {
FLAC__STREAM_DECODER_UNPARSEABLE_STREAM,
FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
FLAC__STREAM_DECODER_ALREADY_INITIALIZED,
FLAC__STREAM_DECODER_INVALID_CALLBACK,
FLAC__STREAM_DECODER_UNINITIALIZED
} FLAC__StreamDecoderState;
extern const char *FLAC__StreamDecoderStateString[];
......@@ -75,6 +76,17 @@ typedef struct {
*
***********************************************************************/
/*
* Any parameters that are not set before FLAC__stream_decoder_init()
* will take on the defaults from the constructor, shown below.
* For more on what the parameters mean, see the documentation.
*
* (*read_callback)() (DEFAULT: NULL ) The callbacks are the only values that MUST be set before FLAC__stream_decoder_init()
* (*write_callback)() (DEFAULT: NULL )
* (*metadata_callback)() (DEFAULT: NULL )
* (*error_callback)() (DEFAULT: NULL )
* void* client_data (DEFAULT: NULL ) passed back through the callbacks
*/
FLAC__StreamDecoder *FLAC__stream_decoder_new();
void FLAC__stream_decoder_delete(FLAC__StreamDecoder *);
......@@ -84,33 +96,56 @@ void FLAC__stream_decoder_delete(FLAC__StreamDecoder *);
*
***********************************************************************/
/*
* Various "set" methods. These may only be called when the decoder
* is in the state FLAC__STREAM_DECODER_UNINITIALIZED, i.e. after
* FLAC__stream_decoder_new() or FLAC__stream_decoder_finish(), but
* before FLAC__stream_decoder_init(). If this is the case they will
* return true, otherwise false.
*
* NOTE that these functions do not validate the values as many are
* interdependent. The FLAC__stream_decoder_init() function will do
* this, so make sure to pay attention to the state returned by
* FLAC__stream_decoder_init().
*
* Any parameters that are not set before FLAC__stream_decoder_init()
* will take on the defaults from the constructor. NOTE that
* FLAC__stream_decoder_flush() or FLAC__stream_decoder_reset() do
* NOT reset the values to the constructor defaults.
*/
bool FLAC__stream_decoder_set_read_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderReadStatus (*value)(const FLAC__StreamDecoder *decoder, byte buffer[], unsigned *bytes, void *client_data));
bool FLAC__stream_decoder_set_write_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderWriteStatus (*value)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data));
bool FLAC__stream_decoder_set_metadata_callback(const FLAC__StreamDecoder *decoder, void (*value)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data));
bool FLAC__stream_decoder_set_error_callback(const FLAC__StreamDecoder *decoder, void (*value)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data));
bool FLAC__stream_decoder_set_client_data(const FLAC__StreamDecoder *decoder, void *value);
/*
* Methods to return the current stream decoder state, number
* of channels, channel assignment, bits-per-sample, sample
* rate in Hz, and blocksize in samples. All but the decoder
* state will only be valid after decoding has started.
*/
FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
/*
* Initialize the instance; should be called after construction and
* before any other calls. Will set and return the decoder state which
* will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA if initialization
* 'set' calls but before any of the 'process' calls. Will set and
* return the decoder state, which will be
* FLAC__STREAM_DECODER_SEARCH_FOR_METADATA if initialization
* succeeded.
*/
FLAC__StreamDecoderState FLAC__stream_decoder_init(
FLAC__StreamDecoder *decoder,
FLAC__StreamDecoderReadStatus (*read_callback)(const FLAC__StreamDecoder *decoder, byte buffer[], unsigned *bytes, void *client_data),
FLAC__StreamDecoderWriteStatus (*write_callback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data),
void (*metadata_callback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data),
void (*error_callback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data),
void *client_data
);
void FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
FLAC__StreamDecoderState FLAC__stream_decoder_init(FLAC__StreamDecoder *decoder);
/*
* methods to return the stream decoder state, number of channels,
* channel assignment, bits-per-sample, sample rate in Hz, and
* blocksize in samples.
* Flush the decoding buffer, release resources, and return the decoder
* state to FLAC__STREAM_DECODER_UNINITIALIZED.
*/
FLAC__StreamDecoderState FLAC__stream_decoder_state(const FLAC__StreamDecoder *decoder);
unsigned FLAC__stream_decoder_channels(const FLAC__StreamDecoder *decoder);
FLAC__ChannelAssignment FLAC__stream_decoder_channel_assignment(const FLAC__StreamDecoder *decoder);
unsigned FLAC__stream_decoder_bits_per_sample(const FLAC__StreamDecoder *decoder);
unsigned FLAC__stream_decoder_sample_rate(const FLAC__StreamDecoder *decoder);
unsigned FLAC__stream_decoder_blocksize(const FLAC__StreamDecoder *decoder);
void FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
/*
* state control methods
......@@ -119,7 +154,7 @@ bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
/*
* methods for decoding the data
* Methods for decoding the data
*/
bool FLAC__stream_decoder_process_whole_stream(FLAC__StreamDecoder *decoder);
bool FLAC__stream_decoder_process_metadata(FLAC__StreamDecoder *decoder);
......
......@@ -24,6 +24,7 @@
typedef enum {
FLAC__STREAM_ENCODER_OK = 0,
FLAC__STREAM_ENCODER_INVALID_CALLBACK,
FLAC__STREAM_ENCODER_INVALID_NUMBER_OF_CHANNELS,
FLAC__STREAM_ENCODER_INVALID_BITS_PER_SAMPLE,
FLAC__STREAM_ENCODER_INVALID_SAMPLE_RATE,
......@@ -69,6 +70,35 @@ typedef struct {
*
***********************************************************************/
/*
* Any parameters that are not set before FLAC__stream_encoder_init()
* will take on the defaults from the constructor, shown below.
* For more on what the parameters mean, see the documentation.
*
* bool streamable_subset (DEFAULT: true ) true to limit encoder to generating a Subset stream, else false
* bool do_mid_side_stereo (DEFAULT: false) if true then channels must be 2
* bool loose_mid_side_stereo (DEFAULT: false) if true then do_mid_side_stereo must be true
* unsigned channels (DEFAULT: 2 ) must be <= FLAC__MAX_CHANNELS
* unsigned bits_per_sample (DEFAULT: 16 ) do not give the encoder wider data than what you specify here or bad things will happen!
* unsigned sample_rate (DEFAULT: 44100)
* unsigned blocksize (DEFAULT: 1152 )
* unsigned max_lpc_order (DEFAULT: 0 ) 0 => encoder will not try general LPC, only fixed predictors; must be <= FLAC__MAX_LPC_ORDER
* unsigned qlp_coeff_precision (DEFAULT: 0 ) >= FLAC__MIN_QLP_COEFF_PRECISION, or 0 to let encoder select based on blocksize;
* qlp_coeff_precision+bits_per_sample must be < 32
* bool do_qlp_coeff_prec_search (DEFAULT: false) false => use qlp_coeff_precision, true => search around qlp_coeff_precision, take best
* bool do_exhaustive_model_search (DEFAULT: false) false => use estimated bits per residual for scoring, true => generate all, take shortest
* unsigned min_residual_partition_order (DEFAULT: 0 ) 0 => estimate Rice parameter based on residual variance; >0 => partition residual, use parameter
* unsigned max_residual_partition_order (DEFAULT: 0 ) for each based on mean; min_ and max_ specify the min and max Rice partition order
* unsigned rice_parameter_search_dist (DEFAULT: 0 ) 0 => try only calc'd parameter k; else try all [k-dist..k+dist] parameters, use best
* uint64 total_samples_estimate (DEFAULT: 0 ) may be 0 if unknown. acts as a placeholder in the STREAMINFO until the actual total is calculated
* const FLAC__StreamMetaData_SeekTable *seek_table (DEFAULT: NULL) optional seek_table to prepend, NULL => no seek table
* unsigned padding (DEFAULT: 0 ) size of PADDING block to add (goes after seek table); 0 => do not add a PADDING block
* bool last_metadata_is_last (DEFAULT: true ) the value the encoder will use for the 'is_last' flag of the last metadata block it writes; set
* this to false if you will be adding more metadata blocks before the audio frames, else true
* (*write_callback)() (DEFAULT: NULL ) The callbacks are the only values that MUST be set before FLAC__stream_encoder_init()
* (*metadata_callback)() (DEFAULT: NULL )
* void* client_data (DEFAULT: NULL ) passed back through the callbacks
*/
FLAC__StreamEncoder *FLAC__stream_encoder_new();
void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
......@@ -78,60 +108,81 @@ void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
*
***********************************************************************/
/*
* Various "set" methods. These may only be called when the encoder
* is in the state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after
* FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but
* before FLAC__stream_encoder_init(). If this is the case they will
* return true, otherwise false.
*
* NOTE that these functions do not validate the values as many are
* interdependent. The FLAC__stream_encoder_init() function will do
* this, so make sure to pay attention to the state returned by
* FLAC__stream_encoder_init().
*
* Any parameters that are not set before FLAC__stream_encoder_init()
* will take on the defaults from the constructor. NOTE that
* FLAC__stream_encoder_finish() does NOT reset the values to the
* constructor defaults.
*/
bool FLAC__stream_encoder_set_streamable_subset(const FLAC__StreamEncoder *encoder, bool value);
bool FLAC__stream_encoder_set_do_mid_side_stereo(const FLAC__StreamEncoder *encoder, bool value);
bool FLAC__stream_encoder_set_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder, bool value);
bool FLAC__stream_encoder_set_channels(const FLAC__StreamEncoder *encoder, unsigned value);
bool FLAC__stream_encoder_set_bits_per_sample(const FLAC__StreamEncoder *encoder, unsigned value);
bool FLAC__stream_encoder_set_sample_rate(const FLAC__StreamEncoder *encoder, unsigned value);
bool FLAC__stream_encoder_set_blocksize(const FLAC__StreamEncoder *encoder, unsigned value);
bool FLAC__stream_encoder_set_max_lpc_order(const FLAC__StreamEncoder *encoder, unsigned value);
bool FLAC__stream_encoder_set_qlp_coeff_precision(const FLAC__StreamEncoder *encoder, unsigned value);
bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder, bool value);
bool FLAC__stream_encoder_set_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder, bool value);
bool FLAC__stream_encoder_set_min_residual_partition_order(const FLAC__StreamEncoder *encoder, unsigned value);
bool FLAC__stream_encoder_set_max_residual_partition_order(const FLAC__StreamEncoder *encoder, unsigned value);
bool FLAC__stream_encoder_set_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder, unsigned value);
bool FLAC__stream_encoder_set_total_samples_estimate(const FLAC__StreamEncoder *encoder, uint64 value);
bool FLAC__stream_encoder_set_seek_table(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData_SeekTable *value);
bool FLAC__stream_encoder_set_padding(const FLAC__StreamEncoder *encoder, unsigned value);
bool FLAC__stream_encoder_set_last_metadata_is_last(const FLAC__StreamEncoder *encoder, bool value);
bool FLAC__stream_encoder_set_write_callback(const FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteStatus (*value)(const FLAC__StreamEncoder *encoder, const byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data));
bool FLAC__stream_encoder_set_metadata_callback(const FLAC__StreamEncoder *encoder, void (*value)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData *metadata, void *client_data));
bool FLAC__stream_encoder_set_client_data(const FLAC__StreamEncoder *encoder, void *value);
/*
* Various "get" methods
*/
FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
/*
* Initialize the instance; should be called after construction and
* before any other calls. Will set and return the encoder state,
* which will be FLAC__STREAM_ENCODER_OK if initialization succeeded.
* 'set' calls but before any of the 'process' calls. Will set and
* return the encoder state, which will be FLAC__STREAM_ENCODER_OK
* if initialization succeeded.
*/
FLAC__StreamEncoderState FLAC__stream_encoder_init(
FLAC__StreamEncoder *encoder,
bool streamable_subset,
bool do_mid_side_stereo, /* 0 or 1; 1 only if channels==2 */
bool loose_mid_side_stereo, /* 0 or 1; 1 only if channels==2 and do_mid_side_stereo==true */
unsigned channels, /* must be <= FLAC__MAX_CHANNELS */
unsigned bits_per_sample, /* do not give the encoder wider data than what you specify here or bad things will happen! */
unsigned sample_rate,
unsigned blocksize,
unsigned max_lpc_order, /* 0 => encoder will not try general LPC, only fixed predictors; must be <= FLAC__MAX_LPC_ORDER */
unsigned qlp_coeff_precision, /* >= FLAC__MIN_QLP_COEFF_PRECISION, or 0 to let encoder select based on blocksize; */
/* qlp_coeff_precision+bits_per_sample must be < 32 */
bool do_qlp_coeff_prec_search, /* 0 => use qlp_coeff_precision, 1 => search around qlp_coeff_precision, take best */
bool do_exhaustive_model_search, /* 0 => use estimated bits per residual for scoring, 1 => generate all, take shortest */
unsigned min_residual_partition_order, /* 0 => estimate Rice parameter based on residual variance; >0 => partition residual, use parameter for each */
unsigned max_residual_partition_order, /* based on mean; min_ and max_ specify the min and max Rice partition order */
unsigned rice_parameter_search_dist, /* 0 => try only calc'd parameter k; else try all [k-dist..k+dist] parameters, use best */
uint64 total_samples_estimate, /* may be 0 if unknown. this will be a placeholder in the metadata block until the actual total is calculated */
const FLAC__StreamMetaData_SeekTable *seek_table, /* optional seek_table to prepend, 0 => no seek table */
unsigned padding, /* size of PADDING block to add (goes after seek table); 0 => do not add a PADDING block */
bool last_metadata_is_last, /* the value the encoder will use for the 'is_last' flag of the last metadata block it writes; set this to false */
/* if you will be adding more metadata blocks before the audio frames, else true */
FLAC__StreamEncoderWriteStatus (*write_callback)(const FLAC__StreamEncoder *encoder, const byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data),
void (*metadata_callback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData *metadata, void *client_data),
void *client_data
);
void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
FLAC__StreamEncoderState FLAC__stream_encoder_init(FLAC__StreamEncoder *encoder);
/*
* various "get" methods
* Flush the encoding buffer, release resources, and return the encoder
* state to FLAC__STREAM_ENCODER_UNINITIALIZED. Note that this can
* generate one or more write_callback()s before returning.
*/
FLAC__StreamEncoderState FLAC__stream_encoder_state(const FLAC__StreamEncoder *encoder);
bool FLAC__stream_encoder_streamable_subset(const FLAC__StreamEncoder *encoder);
bool FLAC__stream_encoder_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
bool FLAC__stream_encoder_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_channels(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_bits_per_sample(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_sample_rate(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_blocksize(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_max_lpc_order(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
bool FLAC__stream_encoder_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
bool FLAC__stream_encoder_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
unsigned FLAC__stream_encoder_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
/*
* methods for encoding the data
* Methods for encoding the data
*/
bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const int32 *buf[], unsigned samples);
bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const int32 buf[], unsigned samples);
......
......@@ -54,7 +54,7 @@ static FLAC__FileDecoder *decoder;
static bool is_big_endian_host;
/* local routines */
static bool init(const char *infile, stream_info_struct *stream_info);
static bool init(const char *infilename, stream_info_struct *stream_info);
static bool write_little_endian_uint16(FILE *f, uint16 val);
static bool write_little_endian_uint32(FILE *f, uint32 val);
static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data);
......@@ -103,7 +103,7 @@ int flac__decode_wav(const char *infile, const char *outfile, bool analysis_mode
if(skip > 0) {
if(!FLAC__file_decoder_process_metadata(decoder)) {
fprintf(stderr, "%s: ERROR while decoding metadata, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]);
fprintf(stderr, "%s: ERROR while decoding metadata, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]);
goto wav_abort_;
}
if(stream_info.skip_count_too_high) {
......@@ -111,35 +111,35 @@ int flac__decode_wav(const char *infile, const char *outfile, bool analysis_mode
goto wav_abort_;
}
if(!FLAC__file_decoder_seek_absolute(decoder, skip)) {
fprintf(stderr, "%s: ERROR seeking while skipping bytes, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]);
fprintf(stderr, "%s: ERROR seeking while skipping bytes, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]);
goto wav_abort_;
}
if(!FLAC__file_decoder_process_remaining_frames(decoder)) {
if(verbose) fprintf(stderr, "\n");
fprintf(stderr, "%s: ERROR while decoding frames, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]);
fprintf(stderr, "%s: ERROR while decoding frames, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]);
goto wav_abort_;
}
if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) {
if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) {
if(verbose) fprintf(stderr, "\n");
fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]);
fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]);
goto wav_abort_;
}
}
else {
if(!FLAC__file_decoder_process_whole_file(decoder)) {
if(verbose) fprintf(stderr, "\n");
fprintf(stderr, "%s: ERROR while decoding data, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]);
fprintf(stderr, "%s: ERROR while decoding data, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]);
goto wav_abort_;
}
if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) {
if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) {
if(verbose) fprintf(stderr, "\n");
fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]);
fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]);
goto wav_abort_;
}
}
if(decoder) {
if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
md5_failure = !FLAC__file_decoder_finish(decoder);
print_stats(&stream_info);
FLAC__file_decoder_delete(decoder);
......@@ -158,7 +158,7 @@ int flac__decode_wav(const char *infile, const char *outfile, bool analysis_mode
return 0;
wav_abort_:
if(decoder) {
if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
FLAC__file_decoder_finish(decoder);
FLAC__file_decoder_delete(decoder);
}
......@@ -214,7 +214,7 @@ int flac__decode_raw(const char *infile, const char *outfile, bool analysis_mode
if(skip > 0) {
if(!FLAC__file_decoder_process_metadata(decoder)) {
fprintf(stderr, "%s: ERROR while decoding metadata, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]);
fprintf(stderr, "%s: ERROR while decoding metadata, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]);
goto raw_abort_;
}
if(stream_info.skip_count_too_high) {
......@@ -222,35 +222,35 @@ int flac__decode_raw(const char *infile, const char *outfile, bool analysis_mode
goto raw_abort_;
}
if(!FLAC__file_decoder_seek_absolute(decoder, skip)) {
fprintf(stderr, "%s: ERROR seeking while skipping bytes, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]);
fprintf(stderr, "%s: ERROR seeking while skipping bytes, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]);
goto raw_abort_;
}
if(!FLAC__file_decoder_process_remaining_frames(decoder)) {
if(verbose) fprintf(stderr, "\n");
fprintf(stderr, "%s: ERROR while decoding frames, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]);
fprintf(stderr, "%s: ERROR while decoding frames, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]);
goto raw_abort_;
}
if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) {
if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) {
if(verbose) fprintf(stderr, "\n");
fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]);
fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]);
goto raw_abort_;
}
}
else {
if(!FLAC__file_decoder_process_whole_file(decoder)) {
if(verbose) fprintf(stderr, "\n");
fprintf(stderr, "%s: ERROR while decoding data, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]);
fprintf(stderr, "%s: ERROR while decoding data, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]);
goto raw_abort_;
}
if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) {
if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_OK && FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_END_OF_FILE) {
if(verbose) fprintf(stderr, "\n");
fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]);
fprintf(stderr, "%s: ERROR during decoding, state=%d:%s\n", stream_info.inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]);
goto raw_abort_;
}
}
if(decoder) {
if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
md5_failure = !FLAC__file_decoder_finish(decoder);
print_stats(&stream_info);
FLAC__file_decoder_delete(decoder);
......@@ -269,7 +269,7 @@ int flac__decode_raw(const char *infile, const char *outfile, bool analysis_mode
return 0;
raw_abort_:
if(decoder) {
if(FLAC__file_decoder_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
if(FLAC__file_decoder_get_state(decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
FLAC__file_decoder_finish(decoder);
FLAC__file_decoder_delete(decoder);
}
......@@ -282,7 +282,7 @@ raw_abort_:
return 1;
}
bool init(const char *infile, stream_info_struct *stream_info)
bool init(const char *infilename, stream_info_struct *stream_info)
{
uint32 test = 1;
......@@ -294,8 +294,15 @@ bool init(const char *infile, stream_info_struct *stream_info)
return false;
}
if(FLAC__file_decoder_init(decoder, true /*check_md5*/, infile, write_callback, metadata_callback, error_callback, stream_info) != FLAC__FILE_DECODER_OK) {
fprintf(stderr, "%s: ERROR initializing decoder, state=%d:%s\n", stream_info->inbasefilename, FLAC__file_decoder_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_state(decoder)]);
FLAC__file_decoder_set_md5_checking(decoder, true);
FLAC__file_decoder_set_filename(decoder, infilename);
FLAC__file_decoder_set_write_callback(decoder, write_callback);
FLAC__file_decoder_set_metadata_callback(decoder, metadata_callback);
FLAC__file_decoder_set_error_callback(decoder, error_callback);
FLAC__file_decoder_set_client_data(decoder, stream_info);
if(FLAC__file_decoder_init(decoder) != FLAC__FILE_DECODER_OK) {
fprintf(stderr, "%s: ERROR initializing decoder, state=%d:%s\n", stream_info->inbasefilename, FLAC__file_decoder_get_state(decoder), FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]);
return false;
}
......
......@@ -276,7 +276,7 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
/* NOTE: some versions of GCC can't figure out const-ness right and will give you an 'incompatible pointer type' warning on arg 2 here: */
if(!FLAC__stream_encoder_process(encoder_wrapper.encoder, input, wide_samples)) {
fprintf(stderr, "%s: ERROR during encoding, state = %d:%s\n", encoder_wrapper.inbasefilename, FLAC__stream_encoder_state(encoder_wrapper.encoder), FLAC__StreamEncoderStateString[FLAC__stream_encoder_state(encoder_wrapper.encoder)]);
fprintf(stderr, "%s: ERROR during encoding, state = %d:%s\n", encoder_wrapper.inbasefilename, FLAC__stream_encoder_get_state(encoder_wrapper.encoder), FLAC__StreamEncoderStateString[FLAC__stream_encoder_get_state(encoder_wrapper.encoder)]);
goto wav_abort_;
}
data_bytes -= bytes_read;
......@@ -313,7 +313,7 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
}
if(encoder_wrapper.encoder) {
if(FLAC__stream_encoder_state(encoder_wrapper.encoder) == FLAC__STREAM_ENCODER_OK)
if(FLAC__stream_encoder_get_state(encoder_wrapper.encoder) == FLAC__STREAM_ENCODER_OK)
FLAC__stream_encoder_finish(encoder_wrapper.encoder);
FLAC__stream_encoder_delete(encoder_wrapper.encoder);
}
......@@ -338,7 +338,7 @@ wav_abort_:
if(encoder_wrapper.verbose && encoder_wrapper.total_samples_to_encode > 0)
fprintf(stderr, "\n");
if(encoder_wrapper.encoder) {
if(FLAC__stream_encoder_state(encoder_wrapper.encoder) == FLAC__STREAM_ENCODER_OK)
if(FLAC__stream_encoder_get_state(encoder_wrapper.encoder) == FLAC__STREAM_ENCODER_OK)
FLAC__stream_encoder_finish(encoder_wrapper.encoder);
FLAC__stream_encoder_delete(encoder_wrapper.encoder);
}
......@@ -469,14 +469,14 @@ int flac__encode_raw(FILE *infile, long infilesize, const char *infilename, cons
/* NOTE: some versions of GCC can't figure out const-ness right and will give you an 'incompatible pointer type' warning on arg 2 here: */
if(!FLAC__stream_encoder_process(encoder_wrapper.encoder, input, wide_samples)) {
fprintf(stderr, "%s: ERROR during encoding, state = %d:%s\n", encoder_wrapper.inbasefilename, FLAC__stream_encoder_state(encoder_wrapper.encoder), FLAC__StreamEncoderStateString[FLAC__stream_encoder_state(encoder_wrapper.encoder)]);
fprintf(stderr, "%s: ERROR during encoding, state = %d:%s\n", encoder_wrapper.inbasefilename, FLAC__stream_encoder_get_state(encoder_wrapper.encoder), FLAC__StreamEncoderStateString[FLAC__stream_encoder_get_state(encoder_wrapper.encoder)]);
goto raw_abort_;
}
}
}
if(encoder_wrapper.encoder) {
if(FLAC__stream_encoder_state(encoder_wrapper.encoder) == FLAC__STREAM_ENCODER_OK)
if(FLAC__stream_encoder_get_state(encoder_wrapper.encoder) == FLAC__STREAM_ENCODER_OK)
FLAC__stream_encoder_finish(encoder_wrapper.encoder);
FLAC__stream_encoder_delete(encoder_wrapper.encoder);
}
......@@ -501,7 +501,7 @@ raw_abort_:
if(encoder_wrapper.verbose && encoder_wrapper.total_samples_to_encode > 0)
fprintf(stderr, "\n");