revamp encoder/decoder interface to use set methods instead on args to init
authorJosh Coalson <jcoalson@users.sourceforce.net>
Sat, 16 Jun 2001 07:32:25 +0000 (07:32 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Sat, 16 Jun 2001 07:32:25 +0000 (07:32 +0000)
15 files changed:
doc/documentation.html
include/FLAC/file_decoder.h
include/FLAC/stream_decoder.h
include/FLAC/stream_encoder.h
src/flac/decode.c
src/flac/encode.c
src/libFLAC/file_decoder.c
src/libFLAC/include/protected/file_decoder.h
src/libFLAC/include/protected/stream_decoder.h
src/libFLAC/include/protected/stream_encoder.h
src/libFLAC/stream_decoder.c
src/libFLAC/stream_encoder.c
src/plugin_winamp2/in_flac.c
src/plugin_winamp3/in_flac.cpp
src/plugin_xmms/plugin.c

index d73dac4..3316016 100644 (file)
        <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>
index e64507e..d234d68 100644 (file)
@@ -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);
index a34ba80..91cdf80 100644 (file)
@@ -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 *);
 
@@ -85,32 +97,55 @@ 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);
index bbc128b..aa714f2 100644 (file)
@@ -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);
 
@@ -79,59 +109,80 @@ 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);
index e6be552..f79aa95 100644 (file)
@@ -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;
        }
 
index c53a01a..0af5b4f 100644 (file)
@@ -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");
        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);
        }
@@ -566,8 +566,13 @@ bool init_encoder(bool lax, bool do_mid_side, bool loose_mid_side, bool do_exhau
                        fprintf(stderr, "%s: ERROR creating the verify decoder instance\n", encoder_wrapper->inbasefilename);
                        return false;
                }
-               if(FLAC__stream_decoder_init(encoder_wrapper->verify_fifo.decoder, verify_read_callback, verify_write_callback, verify_metadata_callback, verify_error_callback, encoder_wrapper) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA) {
-                       fprintf(stderr, "%s: ERROR initializing decoder, state = %d:%s\n", encoder_wrapper->inbasefilename, FLAC__stream_decoder_state(encoder_wrapper->verify_fifo.decoder), FLAC__StreamDecoderStateString[FLAC__stream_decoder_state(encoder_wrapper->verify_fifo.decoder)]);
+               FLAC__stream_decoder_set_read_callback(encoder_wrapper->verify_fifo.decoder, verify_read_callback);
+               FLAC__stream_decoder_set_write_callback(encoder_wrapper->verify_fifo.decoder, verify_write_callback);
+               FLAC__stream_decoder_set_metadata_callback(encoder_wrapper->verify_fifo.decoder, verify_metadata_callback);
+               FLAC__stream_decoder_set_error_callback(encoder_wrapper->verify_fifo.decoder, verify_error_callback);
+               FLAC__stream_decoder_set_client_data(encoder_wrapper->verify_fifo.decoder, encoder_wrapper);
+               if(FLAC__stream_decoder_init(encoder_wrapper->verify_fifo.decoder) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA) {
+                       fprintf(stderr, "%s: ERROR initializing decoder, state = %d:%s\n", encoder_wrapper->inbasefilename, FLAC__stream_decoder_get_state(encoder_wrapper->verify_fifo.decoder), FLAC__StreamDecoderStateString[FLAC__stream_decoder_get_state(encoder_wrapper->verify_fifo.decoder)]);
                        return false;
                }
        }
@@ -577,8 +582,30 @@ bool init_encoder(bool lax, bool do_mid_side, bool loose_mid_side, bool do_exhau
                return false;
        }
 
-       if(FLAC__stream_encoder_init(encoder_wrapper->encoder, !lax, do_mid_side, loose_mid_side, channels, bps, sample_rate, blocksize, max_lpc_order, qlp_coeff_precision, do_qlp_coeff_prec_search, do_exhaustive_model_search, min_residual_partition_order, max_residual_partition_order, rice_parameter_search_dist, encoder_wrapper->total_samples_to_encode, (encoder_wrapper->seek_table.num_points > 0)? &encoder_wrapper->seek_table : 0, padding, true /*last_metadata_is_last*/, write_callback, metadata_callback, encoder_wrapper) != FLAC__STREAM_ENCODER_OK) {
-               fprintf(stderr, "%s: ERROR initializing encoder, state = %d:%s\n", encoder_wrapper->inbasefilename, FLAC__stream_encoder_state(encoder_wrapper->encoder), FLAC__StreamEncoderStateString[FLAC__stream_encoder_state(encoder_wrapper->encoder)]);
+       FLAC__stream_encoder_set_streamable_subset(encoder_wrapper->encoder, !lax);
+       FLAC__stream_encoder_set_do_mid_side_stereo(encoder_wrapper->encoder, do_mid_side);
+       FLAC__stream_encoder_set_loose_mid_side_stereo(encoder_wrapper->encoder, loose_mid_side);
+       FLAC__stream_encoder_set_channels(encoder_wrapper->encoder, channels);
+       FLAC__stream_encoder_set_bits_per_sample(encoder_wrapper->encoder, bps);
+       FLAC__stream_encoder_set_sample_rate(encoder_wrapper->encoder, sample_rate);
+       FLAC__stream_encoder_set_blocksize(encoder_wrapper->encoder, blocksize);
+       FLAC__stream_encoder_set_max_lpc_order(encoder_wrapper->encoder, max_lpc_order);
+       FLAC__stream_encoder_set_qlp_coeff_precision(encoder_wrapper->encoder, qlp_coeff_precision);
+       FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder_wrapper->encoder, do_qlp_coeff_prec_search);
+       FLAC__stream_encoder_set_do_exhaustive_model_search(encoder_wrapper->encoder, do_exhaustive_model_search);
+       FLAC__stream_encoder_set_min_residual_partition_order(encoder_wrapper->encoder, min_residual_partition_order);
+       FLAC__stream_encoder_set_max_residual_partition_order(encoder_wrapper->encoder, max_residual_partition_order);
+       FLAC__stream_encoder_set_rice_parameter_search_dist(encoder_wrapper->encoder, rice_parameter_search_dist);
+       FLAC__stream_encoder_set_total_samples_estimate(encoder_wrapper->encoder, encoder_wrapper->total_samples_to_encode);
+       FLAC__stream_encoder_set_seek_table(encoder_wrapper->encoder, (encoder_wrapper->seek_table.num_points > 0)? &encoder_wrapper->seek_table : 0);
+       FLAC__stream_encoder_set_padding(encoder_wrapper->encoder, padding);
+       FLAC__stream_encoder_set_last_metadata_is_last(encoder_wrapper->encoder, true);
+       FLAC__stream_encoder_set_write_callback(encoder_wrapper->encoder, write_callback);
+       FLAC__stream_encoder_set_metadata_callback(encoder_wrapper->encoder, metadata_callback);
+       FLAC__stream_encoder_set_client_data(encoder_wrapper->encoder, encoder_wrapper);
+
+       if(FLAC__stream_encoder_init(encoder_wrapper->encoder) != FLAC__STREAM_ENCODER_OK) {
+               fprintf(stderr, "%s: ERROR initializing encoder, 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)]);
                return false;
        }
 
@@ -783,11 +810,11 @@ void format_input(unsigned wide_samples, bool is_big_endian, bool is_unsigned_sa
 FLAC__StreamEncoderWriteStatus write_callback(const FLAC__StreamEncoder *encoder, const byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
 {
        encoder_wrapper_struct *encoder_wrapper = (encoder_wrapper_struct *)client_data;
-       const unsigned mask = (FLAC__stream_encoder_do_exhaustive_model_search(encoder) || FLAC__stream_encoder_do_qlp_coeff_prec_search(encoder))? 0x1f : 0x7f;
+       const unsigned mask = (FLAC__stream_encoder_get_do_exhaustive_model_search(encoder) || FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder))? 0x1f : 0x7f;
 
        /* mark the current seek point if hit (if stream_offset == 0 that means we're still writing metadata and haven't hit the first frame yet) */
        if(encoder_wrapper->stream_offset > 0 && encoder_wrapper->seek_table.num_points > 0) {
-               uint64 current_sample = (uint64)current_frame * (uint64)FLAC__stream_encoder_blocksize(encoder), test_sample;
+               uint64 current_sample = (uint64)current_frame * (uint64)FLAC__stream_encoder_get_blocksize(encoder), test_sample;
                unsigned i;
                for(i = encoder_wrapper->first_seek_point_to_check; i < encoder_wrapper->seek_table.num_points; i++) {
                        test_sample = encoder_wrapper->seek_table.points[i].sample_number;
@@ -796,7 +823,7 @@ FLAC__StreamEncoderWriteStatus write_callback(const FLAC__StreamEncoder *encoder
                        }
                        else if(test_sample == current_sample) {
                                encoder_wrapper->seek_table.points[i].stream_offset = encoder_wrapper->bytes_written - encoder_wrapper->stream_offset;
-                               encoder_wrapper->seek_table.points[i].frame_samples = FLAC__stream_encoder_blocksize(encoder);
+                               encoder_wrapper->seek_table.points[i].frame_samples = FLAC__stream_encoder_get_blocksize(encoder);
                                encoder_wrapper->first_seek_point_to_check++;
                                break;
                        }
@@ -953,8 +980,8 @@ FLAC__StreamDecoderWriteStatus verify_write_callback(const FLAC__StreamDecoder *
 {
        encoder_wrapper_struct *encoder_wrapper = (encoder_wrapper_struct *)client_data;
        unsigned channel, l, r;
-       const unsigned channels = FLAC__stream_decoder_channels(decoder);
-       const unsigned bytes_per_block = sizeof(int32) * FLAC__stream_decoder_blocksize(decoder);
+       const unsigned channels = FLAC__stream_decoder_get_channels(decoder);
+       const unsigned bytes_per_block = sizeof(int32) * FLAC__stream_decoder_get_blocksize(decoder);
 
        for(channel = 0; channel < channels; channel++) {
                if(0 != memcmp(buffer[channel], encoder_wrapper->verify_fifo.original[channel], bytes_per_block)) {
index 2c45c9e..e9b9dd0 100644 (file)
@@ -78,6 +78,7 @@ const char *FLAC__FileDecoderStateString[] = {
        "FLAC__FILE_DECODER_STREAM_ERROR",
        "FLAC__FILE_DECODER_STREAM_DECODER_ERROR",
        "FLAC__FILE_DECODER_ALREADY_INITIALIZED",
+       "FLAC__FILE_DECODER_INVALID_CALLBACK",
        "FLAC__FILE_DECODER_UNINITIALIZED"
 };
 
@@ -111,6 +112,12 @@ FLAC__FileDecoder *FLAC__file_decoder_new()
 
        decoder->protected->state = FLAC__FILE_DECODER_UNINITIALIZED;
 
+       decoder->private->filename = 0;
+       decoder->private->write_callback = 0;
+       decoder->private->metadata_callback = 0;
+       decoder->private->error_callback = 0;
+       decoder->private->client_data = 0;
+
        return decoder;
 }
 
@@ -131,52 +138,32 @@ void FLAC__file_decoder_delete(FLAC__FileDecoder *decoder)
  *
  ***********************************************************************/
 
-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
-)
+FLAC__FileDecoderState FLAC__file_decoder_init(FLAC__FileDecoder *decoder)
 {
        FLAC__ASSERT(decoder != 0);
-       FLAC__ASSERT(write_callback != 0);
-       FLAC__ASSERT(metadata_callback != 0);
-       FLAC__ASSERT(error_callback != 0);
 
        if(decoder->protected->state != FLAC__FILE_DECODER_UNINITIALIZED)
                return decoder->protected->state = FLAC__FILE_DECODER_ALREADY_INITIALIZED;
 
        decoder->protected->state = FLAC__FILE_DECODER_OK;
 
-       decoder->protected->check_md5 = check_md5;
+    if(0 == decoder->private->write_callback || 0 == decoder->private->metadata_callback || 0 == decoder->private->error_callback)
+        return decoder->protected->state = FLAC__FILE_DECODER_INVALID_CALLBACK;
 
-       decoder->private->write_callback = write_callback;
-       decoder->private->metadata_callback = metadata_callback;
-       decoder->private->error_callback = error_callback;
-       decoder->private->client_data = client_data;
        decoder->private->file = 0;
        decoder->private->stream_decoder = 0;
-       decoder->private->filename = 0;
        decoder->private->seek_table = 0;
 
-       if(0 == strcmp(filename, "-")) {
+       if(0 == strcmp(decoder->private->filename, "-"))
                decoder->private->file = stdin;
-       }
-       else {
-               if(0 == (decoder->private->filename = (char*)malloc(strlen(filename)+1)))
-                       return decoder->protected->state = FLAC__FILE_DECODER_MEMORY_ALLOCATION_ERROR;
-               strcpy(decoder->private->filename, filename);
-               decoder->private->file = fopen(filename, "rb");
-       }
+       else
+               decoder->private->file = fopen(decoder->private->filename, "rb");
 
        if(decoder->private->file == 0)
                return decoder->protected->state = FLAC__FILE_DECODER_ERROR_OPENING_FILE;
 
        /* We initialize the MD5Context even though we may never use it.  This is
-        * because check_md5 may be turned on to start and then turned off if a
+        * because md5_checking may be turned on to start and then turned off if a
         * seek occurs.  So we always init the context here and finalize it in
         * FLAC__file_decoder_finish() to make sure things are always cleaned up
         * properly.
@@ -184,7 +171,14 @@ FLAC__FileDecoderState FLAC__file_decoder_init(
        MD5Init(&decoder->private->md5context);
 
        decoder->private->stream_decoder = FLAC__stream_decoder_new();
-       if(FLAC__stream_decoder_init(decoder->private->stream_decoder, read_callback_, write_callback_, metadata_callback_, error_callback_, decoder) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
+
+       FLAC__stream_decoder_set_read_callback(decoder->private->stream_decoder, read_callback_);
+       FLAC__stream_decoder_set_write_callback(decoder->private->stream_decoder, write_callback_);
+       FLAC__stream_decoder_set_metadata_callback(decoder->private->stream_decoder, metadata_callback_);
+       FLAC__stream_decoder_set_error_callback(decoder->private->stream_decoder, error_callback_);
+       FLAC__stream_decoder_set_client_data(decoder->private->stream_decoder, decoder);
+
+       if(FLAC__stream_decoder_init(decoder->private->stream_decoder) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA)
                return decoder->protected->state = FLAC__FILE_DECODER_STREAM_DECODER_ERROR;
 
        return decoder->protected->state;
@@ -209,7 +203,7 @@ bool FLAC__file_decoder_finish(FLAC__FileDecoder *decoder)
                FLAC__stream_decoder_finish(decoder->private->stream_decoder);
                FLAC__stream_decoder_delete(decoder->private->stream_decoder);
        }
-       if(decoder->protected->check_md5) {
+       if(decoder->protected->md5_checking) {
                if(memcmp(decoder->private->stored_md5sum, decoder->private->computed_md5sum, 16))
                        md5_failed = true;
        }
@@ -217,14 +211,66 @@ bool FLAC__file_decoder_finish(FLAC__FileDecoder *decoder)
        return !md5_failed;
 }
 
-FLAC__FileDecoderState FLAC__file_decoder_state(const FLAC__FileDecoder *decoder)
+bool FLAC__file_decoder_set_md5_checking(const FLAC__FileDecoder *decoder, bool value)
+{
+       if(decoder->protected->state != FLAC__FILE_DECODER_UNINITIALIZED)
+               return false;
+       decoder->protected->md5_checking = value;
+       return true;
+}
+
+bool FLAC__file_decoder_set_filename(const FLAC__FileDecoder *decoder, const char *value)
+{
+       if(decoder->protected->state != FLAC__FILE_DECODER_UNINITIALIZED)
+               return false;
+       if(0 == (decoder->private->filename = (char*)malloc(strlen(value)+1))) {
+               decoder->protected->state = FLAC__FILE_DECODER_MEMORY_ALLOCATION_ERROR;
+               return false;
+       }
+       strcpy(decoder->private->filename, value);
+       return true;
+}
+
+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))
+{
+       if(decoder->protected->state != FLAC__FILE_DECODER_UNINITIALIZED)
+               return false;
+       decoder->private->write_callback = value;
+       return true;
+}
+
+bool FLAC__file_decoder_set_metadata_callback(const FLAC__FileDecoder *decoder, void (*value)(const FLAC__FileDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data))
+{
+       if(decoder->protected->state != FLAC__FILE_DECODER_UNINITIALIZED)
+               return false;
+       decoder->private->metadata_callback = value;
+       return true;
+}
+
+bool FLAC__file_decoder_set_error_callback(const FLAC__FileDecoder *decoder, void (*value)(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data))
+{
+       if(decoder->protected->state != FLAC__FILE_DECODER_UNINITIALIZED)
+               return false;
+       decoder->private->error_callback = value;
+       return true;
+}
+
+bool FLAC__file_decoder_set_client_data(const FLAC__FileDecoder *decoder, void *value)
+{
+       if(decoder->protected->state != FLAC__FILE_DECODER_UNINITIALIZED)
+               return false;
+       decoder->private->client_data = value;
+       return true;
+}
+
+FLAC__FileDecoderState FLAC__file_decoder_get_state(const FLAC__FileDecoder *decoder)
 {
        return decoder->protected->state;
 }
 
-bool FLAC__file_decoder_check_md5(const FLAC__FileDecoder *decoder)
+bool FLAC__file_decoder_get_md5_checking(const FLAC__FileDecoder *decoder)
 {
-       return decoder->protected->check_md5;
+       return decoder->protected->md5_checking;
 }
 
 bool FLAC__file_decoder_process_whole_file(FLAC__FileDecoder *decoder)
@@ -329,7 +375,7 @@ bool FLAC__file_decoder_seek_absolute(FLAC__FileDecoder *decoder, uint64 sample)
        decoder->protected->state = FLAC__FILE_DECODER_SEEKING;
 
        /* turn off md5 checking if a seek is attempted */
-       decoder->protected->check_md5 = false;
+       decoder->protected->md5_checking = false;
 
        if(!FLAC__stream_decoder_reset(decoder->private->stream_decoder)) {
                decoder->protected->state = FLAC__FILE_DECODER_STREAM_ERROR;
@@ -421,7 +467,7 @@ FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decode
                }
        }
        else {
-               if(file_decoder->protected->check_md5) {
+               if(file_decoder->protected->md5_checking) {
                        if(!FLAC__MD5Accumulate(&file_decoder->private->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
                                return FLAC__STREAM_DECODER_WRITE_ABORT;
                }
@@ -439,7 +485,7 @@ void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMe
                /* save the MD5 signature for comparison later */
                memcpy(file_decoder->private->stored_md5sum, metadata->data.stream_info.md5sum, 16);
                if(0 == memcmp(file_decoder->private->stored_md5sum, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16))
-                       file_decoder->protected->check_md5 = false;
+                       file_decoder->protected->md5_checking = false;
        }
        else if(metadata->type == FLAC__METADATA_TYPE_SEEKTABLE) {
                file_decoder->private->seek_table = &metadata->data.seek_table;
@@ -488,7 +534,7 @@ bool seek_to_absolute_sample_(FLAC__FileDecoder *decoder, long filesize, uint64
                decoder->protected->state = FLAC__FILE_DECODER_SEEK_ERROR;
                return false;
        }
-       first_frame_offset -= FLAC__stream_decoder_input_bytes_unconsumed(decoder->private->stream_decoder);
+       first_frame_offset -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder->private->stream_decoder);
        FLAC__ASSERT(first_frame_offset >= 0);
 
        /*
@@ -610,7 +656,7 @@ bool seek_to_absolute_sample_(FLAC__FileDecoder *decoder, long filesize, uint64
                                                decoder->protected->state = FLAC__FILE_DECODER_SEEK_ERROR;
                                                return false;
                                        }
-                                       pos -= FLAC__stream_decoder_input_bytes_unconsumed(decoder->private->stream_decoder);
+                                       pos -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder->private->stream_decoder);
                                        needs_seek = false;
                                }
                        }
index 7f34b2c..3d0b6bd 100644 (file)
@@ -23,7 +23,7 @@
 #include "FLAC/file_decoder.h"
 
 typedef struct FLAC__FileDecoderProtected {
-       bool check_md5; /* if true, generate MD5 signature of decoded data and compare against signature in the Encoding metadata block */
+       bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the Encoding metadata block */
        FLAC__FileDecoderState state;
 } FLAC__FileDecoderProtected;
 
index df15db2..1314d3a 100644 (file)
@@ -34,6 +34,6 @@ typedef struct FLAC__StreamDecoderProtected {
 /*
  * return the number of input bytes consumed
  */
-unsigned FLAC__stream_decoder_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
+unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
 
 #endif
index 2951ce3..ea11e17 100644 (file)
@@ -40,6 +40,8 @@ typedef struct FLAC__StreamEncoderProtected {
        unsigned rice_parameter_search_dist;
        uint64   total_samples_estimate;
        const FLAC__StreamMetaData_SeekTable *seek_table;
+       unsigned padding;
+       bool     last_metadata_is_last;
 } FLAC__StreamEncoderProtected;
 
 #endif
index dccd1d8..5933cb5 100644 (file)
@@ -104,6 +104,7 @@ const char *FLAC__StreamDecoderStateString[] = {
        "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"
 };
 
@@ -153,6 +154,12 @@ FLAC__StreamDecoder *FLAC__stream_decoder_new()
 
        decoder->protected->state = FLAC__STREAM_DECODER_UNINITIALIZED;
 
+       decoder->private->read_callback = 0;
+       decoder->private->write_callback = 0;
+       decoder->private->metadata_callback = 0;
+       decoder->private->error_callback = 0;
+       decoder->private->client_data = 0;
+
        return decoder;
 }
 
@@ -173,32 +180,19 @@ void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  *
  ***********************************************************************/
 
-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)
+FLAC__StreamDecoderState FLAC__stream_decoder_init(FLAC__StreamDecoder *decoder)
 {
        unsigned i;
 
        FLAC__ASSERT(decoder != 0);
-       FLAC__ASSERT(read_callback != 0);
-       FLAC__ASSERT(write_callback != 0);
-       FLAC__ASSERT(metadata_callback != 0);
-       FLAC__ASSERT(error_callback != 0);
 
        if(decoder->protected->state != FLAC__STREAM_DECODER_UNINITIALIZED)
                return decoder->protected->state = FLAC__STREAM_DECODER_ALREADY_INITIALIZED;
 
        decoder->protected->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
 
-       decoder->private->read_callback = read_callback;
-       decoder->private->write_callback = write_callback;
-       decoder->private->metadata_callback = metadata_callback;
-       decoder->private->error_callback = error_callback;
-       decoder->private->client_data = client_data;
+       if(0 == decoder->private->read_callback || 0 == decoder->private->write_callback || 0 == decoder->private->metadata_callback || 0 == decoder->private->error_callback)
+               return decoder->protected->state = FLAC__STREAM_DECODER_INVALID_CALLBACK;
 
        FLAC__bitbuffer_init(&decoder->private->input);
 
@@ -267,32 +261,72 @@ void FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
        decoder->protected->state = FLAC__STREAM_DECODER_UNINITIALIZED;
 }
 
-FLAC__StreamDecoderState FLAC__stream_decoder_state(const FLAC__StreamDecoder *decoder)
+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))
+{
+       if(decoder->protected->state != FLAC__STREAM_DECODER_UNINITIALIZED)
+               return false;
+       decoder->private->read_callback = value;
+       return true;
+}
+
+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))
+{
+       if(decoder->protected->state != FLAC__STREAM_DECODER_UNINITIALIZED)
+               return false;
+       decoder->private->write_callback = value;
+       return true;
+}
+
+bool FLAC__stream_decoder_set_metadata_callback(const FLAC__StreamDecoder *decoder, void (*value)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data))
+{
+       if(decoder->protected->state != FLAC__STREAM_DECODER_UNINITIALIZED)
+               return false;
+       decoder->private->metadata_callback = value;
+       return true;
+}
+
+bool FLAC__stream_decoder_set_error_callback(const FLAC__StreamDecoder *decoder, void (*value)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data))
+{
+       if(decoder->protected->state != FLAC__STREAM_DECODER_UNINITIALIZED)
+               return false;
+       decoder->private->error_callback = value;
+       return true;
+}
+
+bool FLAC__stream_decoder_set_client_data(const FLAC__StreamDecoder *decoder, void *value)
+{
+       if(decoder->protected->state != FLAC__STREAM_DECODER_UNINITIALIZED)
+               return false;
+       decoder->private->client_data = value;
+       return true;
+}
+
+FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
 {
        return decoder->protected->state;
 }
 
-unsigned FLAC__stream_decoder_channels(const FLAC__StreamDecoder *decoder)
+unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
 {
        return decoder->protected->channels;
 }
 
-FLAC__ChannelAssignment FLAC__stream_decoder_channel_assignment(const FLAC__StreamDecoder *decoder)
+FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
 {
        return decoder->protected->channel_assignment;
 }
 
-unsigned FLAC__stream_decoder_bits_per_sample(const FLAC__StreamDecoder *decoder)
+unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
 {
        return decoder->protected->bits_per_sample;
 }
 
-unsigned FLAC__stream_decoder_sample_rate(const FLAC__StreamDecoder *decoder)
+unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
 {
        return decoder->protected->sample_rate;
 }
 
-unsigned FLAC__stream_decoder_blocksize(const FLAC__StreamDecoder *decoder)
+unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
 {
        return decoder->protected->blocksize;
 }
@@ -464,7 +498,7 @@ bool FLAC__stream_decoder_process_remaining_frames(FLAC__StreamDecoder *decoder)
  *
  ***********************************************************************/
 
-unsigned FLAC__stream_decoder_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
+unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
 {
        FLAC__ASSERT(decoder != 0);
        return decoder->private->input.bytes - decoder->private->input.consumed_bytes;
index eb18622..ba41d8f 100644 (file)
@@ -130,6 +130,7 @@ typedef struct FLAC__StreamEncoderPrivate {
 
 const char *FLAC__StreamEncoderStateString[] = {
        "FLAC__STREAM_ENCODER_OK",
+       "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",
@@ -182,6 +183,29 @@ FLAC__StreamEncoder *FLAC__stream_encoder_new()
 
        encoder->protected->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
 
+       encoder->protected->streamable_subset = true;
+       encoder->protected->do_mid_side_stereo = false;
+       encoder->protected->loose_mid_side_stereo = false;
+       encoder->protected->channels = 2;
+       encoder->protected->bits_per_sample = 16;
+       encoder->protected->sample_rate = 44100;
+       encoder->protected->blocksize = 1152;
+       encoder->protected->max_lpc_order = 0;
+       encoder->protected->qlp_coeff_precision = 0;
+       encoder->protected->do_qlp_coeff_prec_search = false;
+       encoder->protected->do_exhaustive_model_search = false;
+       encoder->protected->min_residual_partition_order = 0;
+       encoder->protected->max_residual_partition_order = 0;
+       encoder->protected->rice_parameter_search_dist = 0;
+       encoder->protected->total_samples_estimate = 0;
+       encoder->protected->seek_table = 0;
+       encoder->protected->padding = 0;
+       encoder->protected->last_metadata_is_last = true;
+
+       encoder->private->write_callback = 0;
+       encoder->private->metadata_callback = 0;
+       encoder->private->client_data = 0;
+
        return encoder;
 }
 
@@ -202,59 +226,21 @@ void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  *
  ***********************************************************************/
 
-FLAC__StreamEncoderState FLAC__stream_encoder_init(
-       FLAC__StreamEncoder *encoder,
-       bool streamable_subset,
-       bool do_mid_side_stereo,
-       bool loose_mid_side_stereo,
-       unsigned channels,
-       unsigned bits_per_sample,
-       unsigned sample_rate,
-       unsigned blocksize,
-       unsigned max_lpc_order,
-       unsigned qlp_coeff_precision,
-       bool do_qlp_coeff_prec_search,
-       bool do_exhaustive_model_search,
-       unsigned min_residual_partition_order,
-       unsigned max_residual_partition_order,
-       unsigned rice_parameter_search_dist,
-       uint64 total_samples_estimate,
-       const FLAC__StreamMetaData_SeekTable *seek_table,
-       unsigned padding,
-       bool last_metadata_is_last,
-       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)
+FLAC__StreamEncoderState FLAC__stream_encoder_init(FLAC__StreamEncoder *encoder)
 {
        unsigned i;
        FLAC__StreamMetaData padding_block;
        FLAC__StreamMetaData seek_table_block;
 
        FLAC__ASSERT(encoder != 0);
-       FLAC__ASSERT(write_callback != 0);
-       FLAC__ASSERT(metadata_callback != 0);
 
        if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
                return encoder->protected->state = FLAC__STREAM_ENCODER_ALREADY_INITIALIZED;
 
        encoder->protected->state = FLAC__STREAM_ENCODER_OK;
 
-       encoder->protected->streamable_subset = streamable_subset;
-       encoder->protected->do_mid_side_stereo = do_mid_side_stereo;
-       encoder->protected->loose_mid_side_stereo = loose_mid_side_stereo;
-       encoder->protected->channels = channels;
-       encoder->protected->bits_per_sample = bits_per_sample;
-       encoder->protected->sample_rate = sample_rate;
-       encoder->protected->blocksize = blocksize;
-       encoder->protected->max_lpc_order = max_lpc_order;
-       encoder->protected->qlp_coeff_precision = qlp_coeff_precision;
-       encoder->protected->do_qlp_coeff_prec_search = do_qlp_coeff_prec_search;
-       encoder->protected->do_exhaustive_model_search = do_exhaustive_model_search;
-       encoder->protected->min_residual_partition_order = min_residual_partition_order;
-       encoder->protected->max_residual_partition_order = max_residual_partition_order;
-       encoder->protected->rice_parameter_search_dist = rice_parameter_search_dist;
-       encoder->protected->total_samples_estimate = total_samples_estimate;
-       encoder->protected->seek_table = seek_table;
+       if(0 == encoder->private->write_callback || 0 == encoder->private->metadata_callback)
+               return encoder->protected->state = FLAC__STREAM_ENCODER_INVALID_CALLBACK;
 
        if(encoder->protected->channels == 0 || encoder->protected->channels > FLAC__MAX_CHANNELS)
                return encoder->protected->state = FLAC__STREAM_ENCODER_INVALID_NUMBER_OF_CHANNELS;
@@ -411,9 +397,6 @@ FLAC__StreamEncoderState FLAC__stream_encoder_init(
                return encoder->protected->state;
        }
        FLAC__bitbuffer_init(&encoder->private->frame);
-       encoder->private->write_callback = write_callback;
-       encoder->private->metadata_callback = metadata_callback;
-       encoder->private->client_data = client_data;
 
        /*
         * write the stream header
@@ -425,7 +408,7 @@ FLAC__StreamEncoderState FLAC__stream_encoder_init(
                return encoder->protected->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
 
        encoder->private->metadata.type = FLAC__METADATA_TYPE_STREAMINFO;
-       encoder->private->metadata.is_last = (encoder->protected->seek_table == 0 && padding == 0 && last_metadata_is_last);
+       encoder->private->metadata.is_last = (encoder->protected->seek_table == 0 && encoder->protected->padding == 0 && encoder->protected->last_metadata_is_last);
        encoder->private->metadata.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
        encoder->private->metadata.data.stream_info.min_blocksize = encoder->protected->blocksize; /* this encoder uses the same blocksize for the whole stream */
        encoder->private->metadata.data.stream_info.max_blocksize = encoder->protected->blocksize;
@@ -444,7 +427,7 @@ FLAC__StreamEncoderState FLAC__stream_encoder_init(
                if(!FLAC__seek_table_is_valid(encoder->protected->seek_table))
                        return encoder->protected->state = FLAC__STREAM_ENCODER_INVALID_SEEK_TABLE;
                seek_table_block.type = FLAC__METADATA_TYPE_SEEKTABLE;
-               seek_table_block.is_last = (padding == 0 && last_metadata_is_last);
+               seek_table_block.is_last = (encoder->protected->padding == 0 && encoder->protected->last_metadata_is_last);
                seek_table_block.length = encoder->protected->seek_table->num_points * FLAC__STREAM_METADATA_SEEKPOINT_LEN;
                seek_table_block.data.seek_table = *encoder->protected->seek_table;
                if(!FLAC__add_metadata_block(&seek_table_block, &encoder->private->frame))
@@ -452,10 +435,10 @@ FLAC__StreamEncoderState FLAC__stream_encoder_init(
        }
 
        /* add a PADDING block if requested */
-       if(padding > 0) {
+       if(encoder->protected->padding > 0) {
                padding_block.type = FLAC__METADATA_TYPE_PADDING;
-               padding_block.is_last = last_metadata_is_last;
-               padding_block.length = padding;
+               padding_block.is_last = encoder->protected->last_metadata_is_last;
+               padding_block.length = encoder->protected->padding;
                if(!FLAC__add_metadata_block(&padding_block, &encoder->private->frame))
                        return encoder->protected->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
        }
@@ -539,77 +522,245 @@ void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
        encoder->protected->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
 }
 
-FLAC__StreamEncoderState FLAC__stream_encoder_state(const FLAC__StreamEncoder *encoder)
+bool FLAC__stream_encoder_set_streamable_subset(const FLAC__StreamEncoder *encoder, bool value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->streamable_subset = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_do_mid_side_stereo(const FLAC__StreamEncoder *encoder, bool value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->do_mid_side_stereo = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder, bool value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->loose_mid_side_stereo = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_channels(const FLAC__StreamEncoder *encoder, unsigned value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->channels = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_bits_per_sample(const FLAC__StreamEncoder *encoder, unsigned value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->bits_per_sample = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_sample_rate(const FLAC__StreamEncoder *encoder, unsigned value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->sample_rate = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_blocksize(const FLAC__StreamEncoder *encoder, unsigned value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->blocksize = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_max_lpc_order(const FLAC__StreamEncoder *encoder, unsigned value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->max_lpc_order = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_qlp_coeff_precision(const FLAC__StreamEncoder *encoder, unsigned value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->qlp_coeff_precision = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder, bool value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->do_qlp_coeff_prec_search = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder, bool value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->do_exhaustive_model_search = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_min_residual_partition_order(const FLAC__StreamEncoder *encoder, unsigned value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->min_residual_partition_order = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_max_residual_partition_order(const FLAC__StreamEncoder *encoder, unsigned value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->max_residual_partition_order = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder, unsigned value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->rice_parameter_search_dist = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_total_samples_estimate(const FLAC__StreamEncoder *encoder, uint64 value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->total_samples_estimate = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_seek_table(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData_SeekTable *value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->seek_table = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_padding(const FLAC__StreamEncoder *encoder, unsigned value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->padding = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_last_metadata_is_last(const FLAC__StreamEncoder *encoder, bool value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->protected->last_metadata_is_last = value;
+       return true;
+}
+
+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))
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->private->write_callback = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_metadata_callback(const FLAC__StreamEncoder *encoder, void (*value)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetaData *metadata, void *client_data))
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->private->metadata_callback = value;
+       return true;
+}
+
+bool FLAC__stream_encoder_set_client_data(const FLAC__StreamEncoder *encoder, void *value)
+{
+       if(encoder->protected->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
+               return false;
+       encoder->private->client_data = value;
+       return true;
+}
+
+FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->state;
 }
 
-bool FLAC__stream_encoder_streamable_subset(const FLAC__StreamEncoder *encoder)
+bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->streamable_subset;
 }
 
-bool FLAC__stream_encoder_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
+bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->do_mid_side_stereo;
 }
 
-bool FLAC__stream_encoder_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
+bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->loose_mid_side_stereo;
 }
 
-unsigned FLAC__stream_encoder_channels(const FLAC__StreamEncoder *encoder)
+unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->channels;
 }
 
-unsigned FLAC__stream_encoder_bits_per_sample(const FLAC__StreamEncoder *encoder)
+unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->bits_per_sample;
 }
 
-unsigned FLAC__stream_encoder_sample_rate(const FLAC__StreamEncoder *encoder)
+unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->sample_rate;
 }
 
-unsigned FLAC__stream_encoder_blocksize(const FLAC__StreamEncoder *encoder)
+unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->blocksize;
 }
 
-unsigned FLAC__stream_encoder_max_lpc_order(const FLAC__StreamEncoder *encoder)
+unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->max_lpc_order;
 }
 
-unsigned FLAC__stream_encoder_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
+unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->qlp_coeff_precision;
 }
 
-bool FLAC__stream_encoder_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
+bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->do_qlp_coeff_prec_search;
 }
 
-bool FLAC__stream_encoder_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
+bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->do_exhaustive_model_search;
 }
 
-unsigned FLAC__stream_encoder_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
+unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->min_residual_partition_order;
 }
 
-unsigned FLAC__stream_encoder_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
+unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->max_residual_partition_order;
 }
 
-unsigned FLAC__stream_encoder_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
+unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
 {
        return encoder->protected->rice_parameter_search_dist;
 }
@@ -1637,4 +1788,3 @@ unsigned stream_encoder_get_wasted_bits_(int32 signal[], unsigned samples)
 
        return shift;
 }
-
index a8563cf..e4e8d92 100644 (file)
@@ -41,7 +41,7 @@ typedef struct {
        unsigned length_in_ms;
 } stream_info_struct;
 
-static bool stream_init(const char *infile);
+static bool stream_init(const char *infilename);
 static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data);
 static void metadata_callback(const FLAC__FileDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data);
 static void error_callback(const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
@@ -161,7 +161,7 @@ void stop()
                thread_handle = INVALID_HANDLE_VALUE;
        }
        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);
        }
 
@@ -210,14 +210,20 @@ void getfileinfo(char *filename, char *title, int *length_in_ms)
                        FLAC__FileDecoder *tmp_decoder = FLAC__file_decoder_new();
                        stream_info_struct tmp_stream_info;
                        tmp_stream_info.abort_flag = false;
-                       if(FLAC__file_decoder_init(tmp_decoder, false /*md5_check*/, filename, write_callback, metadata_callback, error_callback, &tmp_stream_info) != FLAC__FILE_DECODER_OK)
+                       FLAC__file_decoder_set_md5_checking(tmp_decoder, false);
+                       FLAC__file_decoder_set_filename(tmp_decoder, filename);
+                       FLAC__file_decoder_set_write_callback(tmp_decoder, write_callback);
+                       FLAC__file_decoder_set_metadata_callback(tmp_decoder, metadata_callback);
+                       FLAC__file_decoder_set_error_callback(tmp_decoder, error_callback);
+                       FLAC__file_decoder_set_client_data(tmp_decoder, &tmp_stream_info);
+                       if(FLAC__file_decoder_init(tmp_decoder) != FLAC__FILE_DECODER_OK)
                                return;
                        if(!FLAC__file_decoder_process_metadata(tmp_decoder))
                                return;
 
                        *length_in_ms = (int)tmp_stream_info.length_in_ms;
 
-                       if(FLAC__file_decoder_state(tmp_decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
+                       if(FLAC__file_decoder_get_state(tmp_decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
                                FLAC__file_decoder_finish(tmp_decoder);
                        FLAC__file_decoder_delete(tmp_decoder);
                }
@@ -261,7 +267,7 @@ DWORD WINAPI __stdcall DecodeThread(void *b)
                }
                else if (mod.outMod->CanWrite() >= ((int)(576*channels*bytes_per_sample) << (mod.dsp_isactive()?1:0))) {
                        while(samples_in_reservoir < 576) {
-                               if(FLAC__file_decoder_state(decoder) == FLAC__FILE_DECODER_END_OF_FILE) {
+                               if(FLAC__file_decoder_get_state(decoder) == FLAC__FILE_DECODER_END_OF_FILE) {
                                        done = 1;
                                        break;
                                }
@@ -352,9 +358,15 @@ __declspec( dllexport ) In_Module * winampGetInModule2()
 /***********************************************************************
  * local routines
  **********************************************************************/
-bool stream_init(const char *infile)
+bool stream_init(const char *infilename)
 {
-       if(FLAC__file_decoder_init(decoder, false /*md5_check*/, infile, write_callback, metadata_callback, error_callback, &stream_info) != FLAC__FILE_DECODER_OK) {
+       FLAC__file_decoder_set_md5_checking(decoder, false);
+       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) {
                MessageBox(mod.hMainWindow,"ERROR initializing decoder, state = %d\n","ERROR initializing decoder",0);
                return false;
        }
index 81c839e..80ced21 100644 (file)
@@ -89,7 +89,13 @@ int FLAC_Info::Open(char *url)
                return 1;
        }
        tmp_file_info.abort_flag = false;
-       if(FLAC__file_decoder_init(tmp_decoder, false /*md5_check*/, filename, write_callback_, metadata_callback_, error_callback_, &tmp_file_info) != FLAC__FILE_DECODER_OK) {
+       FLAC__file_decoder_set_md5_checking(tmp_decoder, false);
+       FLAC__file_decoder_set_filename(tmp_decoder, filename);
+       FLAC__file_decoder_set_write_callback(tmp_decoder, write_callback_);
+       FLAC__file_decoder_set_metadata_callback(tmp_decoder, metadata_callback_);
+       FLAC__file_decoder_set_error_callback(tmp_decoder, error_callback_);
+       FLAC__file_decoder_set_client_data(tmp_decoder, &tmp_file_info);
+       if(FLAC__file_decoder_init(tmp_decoder) != FLAC__FILE_DECODER_OK) {
                length_in_msec_ = -1;
                return 1;
        }
@@ -100,7 +106,7 @@ int FLAC_Info::Open(char *url)
 
        length_in_msec_ = (int)tmp_file_info.length_in_msec;
 
-       if(FLAC__file_decoder_state(tmp_decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
+       if(FLAC__file_decoder_get_state(tmp_decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
                FLAC__file_decoder_finish(tmp_decoder);
        FLAC__file_decoder_delete(tmp_decoder);
 
@@ -213,7 +219,7 @@ int FLAC_Source::GetSamples(char *sample_buffer, int bytes, int *bps, int *nch,
                const unsigned wide_samples = bytes / channels / bytes_per_sample;
 if(bytes&0x3)fprintf(stderr,"@@@ Got odd buffer size request\n");
                while(reservoir_samples_ < wide_samples) {
-                       if(FLAC__file_decoder_state(decoder) == FLAC__FILE_DECODER_END_OF_FILE) {
+                       if(FLAC__file_decoder_get_state(decoder) == FLAC__FILE_DECODER_END_OF_FILE) {
                                file_info_.eof = true;
                                break;
                        }
@@ -256,7 +262,7 @@ int FLAC_Source::SetPosition(int position)
 
 void FLAC_Source::cleanup()
 {
-       if(decoder_ && FLAC__file_decoder_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED)
+       if(decoder_ && FLAC__file_decoder_get_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED)
                FLAC__file_decoder_finish(decoder_);
 
        reservoir_samples_ = 0;
@@ -322,7 +328,13 @@ bool decoder_init_(const char *filename)
        if(decoder_ == 0)
                return false;
 
-       if(FLAC__file_decoder_init(decoder_, false /*md5_check*/, filename, write_callback_, metadata_callback_, error_callback_, &file_info_) != FLAC__FILE_DECODER_OK)
+       FLAC__file_decoder_set_md5_checking(decoder, false);
+       FLAC__file_decoder_set_filename(decoder, filename);
+       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, &file_info_);
+       if(FLAC__file_decoder_init(decoder_) != FLAC__FILE_DECODER_OK)
                return false;
 
        file_info_.abort_flag = false;
index b854b05..51e51b8 100644 (file)
@@ -152,7 +152,7 @@ void FLAC_XMMS__play_file(char *filename)
 
        if (flac_ip.output->open_audio(file_info_.sample_format, file_info_.sample_rate, file_info_.channels) == 0) {
                audio_error_ = true;
-               if(decoder_ && FLAC__file_decoder_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED)
+               if(decoder_ && FLAC__file_decoder_get_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED)
                        FLAC__file_decoder_finish(decoder_);
                return;
        }
@@ -170,7 +170,7 @@ void FLAC_XMMS__stop()
                file_info_.is_playing = false;
                pthread_join(decode_thread_, NULL);
                flac_ip.output->close_audio();
-               if(decoder_ && FLAC__file_decoder_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED)
+               if(decoder_ && FLAC__file_decoder_get_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED)
                        FLAC__file_decoder_finish(decoder_);
        }
 }
@@ -222,7 +222,13 @@ void FLAC_XMMS__get_song_info(char *filename, char **title, int *length_in_msec)
                        return;
                }
                tmp_file_info.abort_flag = false;
-               if(FLAC__file_decoder_init(tmp_decoder, false /*md5_check*/, filename, write_callback_, metadata_callback_, error_callback_, &tmp_file_info) != FLAC__FILE_DECODER_OK) {
+               FLAC__file_decoder_set_md5_checking(tmp_decoder, false);
+               FLAC__file_decoder_set_filename(tmp_decoder, filename);
+               FLAC__file_decoder_set_write_callback(tmp_decoder, write_callback_);
+               FLAC__file_decoder_set_metadata_callback(tmp_decoder, metadata_callback_);
+               FLAC__file_decoder_set_error_callback(tmp_decoder, error_callback_);
+               FLAC__file_decoder_set_client_data(tmp_decoder, &tmp_file_info);
+               if(FLAC__file_decoder_init(tmp_decoder) != FLAC__FILE_DECODER_OK) {
                        *length_in_msec = -1;
                        return;
                }
@@ -233,7 +239,7 @@ void FLAC_XMMS__get_song_info(char *filename, char **title, int *length_in_msec)
 
                *length_in_msec = (int)tmp_file_info.length_in_msec;
 
-               if(FLAC__file_decoder_state(tmp_decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
+               if(FLAC__file_decoder_get_state(tmp_decoder) != FLAC__FILE_DECODER_UNINITIALIZED)
                        FLAC__file_decoder_finish(tmp_decoder);
                FLAC__file_decoder_delete(tmp_decoder);
        }
@@ -297,7 +303,7 @@ void *play_loop_(void *arg)
        while(file_info_.is_playing) {
                if(!file_info_.eof) {
                        while(reservoir_samples_ < SAMPLES_PER_WRITE) {
-                               if(FLAC__file_decoder_state(decoder_) == FLAC__FILE_DECODER_END_OF_FILE) {
+                               if(FLAC__file_decoder_get_state(decoder_) == FLAC__FILE_DECODER_END_OF_FILE) {
                                        file_info_.eof = true;
                                        break;
                                }
@@ -342,7 +348,7 @@ void *play_loop_(void *arg)
                }
 
        }
-       if(decoder_ && FLAC__file_decoder_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED)
+       if(decoder_ && FLAC__file_decoder_get_state(decoder_) != FLAC__FILE_DECODER_UNINITIALIZED)
                FLAC__file_decoder_finish(decoder_);
 
        /* are these two calls necessary? */
@@ -358,7 +364,13 @@ bool decoder_init_(const char *filename)
        if(decoder_ == 0)
                return false;
 
-       if(FLAC__file_decoder_init(decoder_, false /*md5_check*/, filename, write_callback_, metadata_callback_, error_callback_, &file_info_) != FLAC__FILE_DECODER_OK)
+       FLAC__file_decoder_set_md5_checking(decoder_, false);
+       FLAC__file_decoder_set_filename(decoder_, filename);
+       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_, &file_info_);
+       if(FLAC__file_decoder_init(decoder_) != FLAC__FILE_DECODER_OK)
                return false;
 
        file_info_.abort_flag = false;