00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 #ifndef FLACPP__ENCODER_H
00033 #define FLACPP__ENCODER_H
00034 
00035 #include "export.h"
00036 
00037 #include "FLAC/file_encoder.h"
00038 #include "FLAC/seekable_stream_encoder.h"
00039 #include "FLAC/stream_encoder.h"
00040 #include "decoder.h"
00041 #include "metadata.h"
00042 
00043 
00071 namespace FLAC {
00072     namespace Encoder {
00073 
00074         
00075         
00076         
00077         
00078         
00079 
00093         class FLACPP_API Stream {
00094         public:
00095             class FLACPP_API State {
00096             public:
00097                 inline State(::FLAC__StreamEncoderState state): state_(state) { }
00098                 inline operator ::FLAC__StreamEncoderState() const { return state_; }
00099                 inline const char *as_cstring() const { return ::FLAC__StreamEncoderStateString[state_]; }
00100                 inline const char *resolved_as_cstring(const Stream &encoder) const { return ::FLAC__stream_encoder_get_resolved_state_string(encoder.encoder_); }
00101             protected:
00102                 ::FLAC__StreamEncoderState state_;
00103             };
00104 
00105             Stream();
00106             virtual ~Stream();
00107 
00108             bool is_valid() const;
00109             inline operator bool() const { return is_valid(); }
00110 
00111             bool set_verify(bool value);
00112             bool set_streamable_subset(bool value);
00113             bool set_do_mid_side_stereo(bool value);
00114             bool set_loose_mid_side_stereo(bool value);
00115             bool set_channels(unsigned value);
00116             bool set_bits_per_sample(unsigned value);
00117             bool set_sample_rate(unsigned value);
00118             bool set_blocksize(unsigned value);
00119             bool set_max_lpc_order(unsigned value);
00120             bool set_qlp_coeff_precision(unsigned value);
00121             bool set_do_qlp_coeff_prec_search(bool value);
00122             bool set_do_escape_coding(bool value);
00123             bool set_do_exhaustive_model_search(bool value);
00124             bool set_min_residual_partition_order(unsigned value);
00125             bool set_max_residual_partition_order(unsigned value);
00126             bool set_rice_parameter_search_dist(unsigned value);
00127             bool set_total_samples_estimate(FLAC__uint64 value);
00128             bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
00129             bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks);
00130 
00131             State    get_state() const;
00132             Decoder::Stream::State get_verify_decoder_state() const;
00133             void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
00134             bool     get_verify() const;
00135             bool     get_streamable_subset() const;
00136             bool     get_do_mid_side_stereo() const;
00137             bool     get_loose_mid_side_stereo() const;
00138             unsigned get_channels() const;
00139             unsigned get_bits_per_sample() const;
00140             unsigned get_sample_rate() const;
00141             unsigned get_blocksize() const;
00142             unsigned get_max_lpc_order() const;
00143             unsigned get_qlp_coeff_precision() const;
00144             bool     get_do_qlp_coeff_prec_search() const;
00145             bool     get_do_escape_coding() const;
00146             bool     get_do_exhaustive_model_search() const;
00147             unsigned get_min_residual_partition_order() const;
00148             unsigned get_max_residual_partition_order() const;
00149             unsigned get_rice_parameter_search_dist() const;
00150             FLAC__uint64 get_total_samples_estimate() const;
00151 
00152             State init();
00153 
00154             void finish();
00155 
00156             bool process(const FLAC__int32 * const buffer[], unsigned samples);
00157             bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
00158         protected:
00159             virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
00160             virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
00161 
00162 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96)))
00163             
00164             friend State;
00165 #endif
00166             ::FLAC__StreamEncoder *encoder_;
00167         private:
00168             static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
00169             static void metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
00170 
00171             
00172             Stream(const Stream &);
00173             void operator=(const Stream &);
00174         };
00175 
00176         
00177 
00191         class FLACPP_API SeekableStream {
00192         public:
00193             class FLACPP_API State {
00194             public:
00195                 inline State(::FLAC__SeekableStreamEncoderState state): state_(state) { }
00196                 inline operator ::FLAC__SeekableStreamEncoderState() const { return state_; }
00197                 inline const char *as_cstring() const { return ::FLAC__SeekableStreamEncoderStateString[state_]; }
00198                 inline const char *resolved_as_cstring(const SeekableStream &encoder) const { return ::FLAC__seekable_stream_encoder_get_resolved_state_string(encoder.encoder_); }
00199             protected:
00200                 ::FLAC__SeekableStreamEncoderState state_;
00201             };
00202 
00203             SeekableStream();
00204             virtual ~SeekableStream();
00205 
00206             bool is_valid() const;
00207             inline operator bool() const { return is_valid(); }
00208 
00209             bool set_verify(bool value);
00210             bool set_streamable_subset(bool value);
00211             bool set_do_mid_side_stereo(bool value);
00212             bool set_loose_mid_side_stereo(bool value);
00213             bool set_channels(unsigned value);
00214             bool set_bits_per_sample(unsigned value);
00215             bool set_sample_rate(unsigned value);
00216             bool set_blocksize(unsigned value);
00217             bool set_max_lpc_order(unsigned value);
00218             bool set_qlp_coeff_precision(unsigned value);
00219             bool set_do_qlp_coeff_prec_search(bool value);
00220             bool set_do_escape_coding(bool value);
00221             bool set_do_exhaustive_model_search(bool value);
00222             bool set_min_residual_partition_order(unsigned value);
00223             bool set_max_residual_partition_order(unsigned value);
00224             bool set_rice_parameter_search_dist(unsigned value);
00225             bool set_total_samples_estimate(FLAC__uint64 value);
00226             bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
00227             bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks);
00228 
00229             State    get_state() const;
00230             Stream::State get_stream_encoder_state() const;
00231             Decoder::Stream::State get_verify_decoder_state() const;
00232             void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
00233             bool     get_verify() const;
00234             bool     get_streamable_subset() const;
00235             bool     get_do_mid_side_stereo() const;
00236             bool     get_loose_mid_side_stereo() const;
00237             unsigned get_channels() const;
00238             unsigned get_bits_per_sample() const;
00239             unsigned get_sample_rate() const;
00240             unsigned get_blocksize() const;
00241             unsigned get_max_lpc_order() const;
00242             unsigned get_qlp_coeff_precision() const;
00243             bool     get_do_qlp_coeff_prec_search() const;
00244             bool     get_do_escape_coding() const;
00245             bool     get_do_exhaustive_model_search() const;
00246             unsigned get_min_residual_partition_order() const;
00247             unsigned get_max_residual_partition_order() const;
00248             unsigned get_rice_parameter_search_dist() const;
00249             FLAC__uint64 get_total_samples_estimate() const;
00250 
00251             State init();
00252 
00253             void finish();
00254 
00255             bool process(const FLAC__int32 * const buffer[], unsigned samples);
00256             bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
00257         protected:
00258             virtual ::FLAC__SeekableStreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
00259             virtual ::FLAC__SeekableStreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
00260             virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
00261 
00262 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96)))
00263             
00264             friend State;
00265 #endif
00266             ::FLAC__SeekableStreamEncoder *encoder_;
00267         private:
00268             static ::FLAC__SeekableStreamEncoderSeekStatus seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
00269             static ::FLAC__SeekableStreamEncoderTellStatus tell_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
00270             static ::FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
00271 
00272             
00273             SeekableStream(const SeekableStream &);
00274             void operator=(const SeekableStream &);
00275         };
00276 
00277         
00278 
00292         class FLACPP_API File {
00293         public:
00294             class FLACPP_API State {
00295             public:
00296                 inline State(::FLAC__FileEncoderState state): state_(state) { }
00297                 inline operator ::FLAC__FileEncoderState() const { return state_; }
00298                 inline const char *as_cstring() const { return ::FLAC__FileEncoderStateString[state_]; }
00299                 inline const char *resolved_as_cstring(const File &encoder) const { return ::FLAC__file_encoder_get_resolved_state_string(encoder.encoder_); }
00300             protected:
00301                 ::FLAC__FileEncoderState state_;
00302             };
00303 
00304             File();
00305             virtual ~File();
00306 
00307             bool is_valid() const;
00308             inline operator bool() const { return is_valid(); }
00309 
00310             bool set_verify(bool value);
00311             bool set_streamable_subset(bool value);
00312             bool set_do_mid_side_stereo(bool value);
00313             bool set_loose_mid_side_stereo(bool value);
00314             bool set_channels(unsigned value);
00315             bool set_bits_per_sample(unsigned value);
00316             bool set_sample_rate(unsigned value);
00317             bool set_blocksize(unsigned value);
00318             bool set_max_lpc_order(unsigned value);
00319             bool set_qlp_coeff_precision(unsigned value);
00320             bool set_do_qlp_coeff_prec_search(bool value);
00321             bool set_do_escape_coding(bool value);
00322             bool set_do_exhaustive_model_search(bool value);
00323             bool set_min_residual_partition_order(unsigned value);
00324             bool set_max_residual_partition_order(unsigned value);
00325             bool set_rice_parameter_search_dist(unsigned value);
00326             bool set_total_samples_estimate(FLAC__uint64 value);
00327             bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
00328             bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks);
00329             bool set_filename(const char *value);
00330 
00331             State    get_state() const;
00332             SeekableStream::State get_seekable_stream_encoder_state() const;
00333             Stream::State get_stream_encoder_state() const;
00334             Decoder::Stream::State get_verify_decoder_state() const;
00335             void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
00336             bool     get_verify() const;
00337             bool     get_streamable_subset() const;
00338             bool     get_do_mid_side_stereo() const;
00339             bool     get_loose_mid_side_stereo() const;
00340             unsigned get_channels() const;
00341             unsigned get_bits_per_sample() const;
00342             unsigned get_sample_rate() const;
00343             unsigned get_blocksize() const;
00344             unsigned get_max_lpc_order() const;
00345             unsigned get_qlp_coeff_precision() const;
00346             bool     get_do_qlp_coeff_prec_search() const;
00347             bool     get_do_escape_coding() const;
00348             bool     get_do_exhaustive_model_search() const;
00349             unsigned get_min_residual_partition_order() const;
00350             unsigned get_max_residual_partition_order() const;
00351             unsigned get_rice_parameter_search_dist() const;
00352             FLAC__uint64 get_total_samples_estimate() const;
00353 
00354             State init();
00355 
00356             void finish();
00357 
00358             bool process(const FLAC__int32 * const buffer[], unsigned samples);
00359             bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
00360         protected:
00361             virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
00362 
00363 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96)))
00364             
00365             friend State;
00366 #endif
00367             ::FLAC__FileEncoder *encoder_;
00368         private:
00369             static void progress_callback_(const ::FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data);
00370 
00371             
00372             File(const Stream &);
00373             void operator=(const Stream &);
00374         };
00375 
00376         
00377 
00378     };
00379 };
00380 
00381 #endif