1 /* libFLAC++ - Free Lossless Audio Codec library
2 * Copyright (C) 2002 Josh Coalson
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #ifndef FLACPP__ENCODER_H
21 #define FLACPP__ENCODER_H
25 #include "FLAC/file_encoder.h"
26 #include "FLAC/seekable_stream_encoder.h"
27 #include "FLAC/stream_encoder.h"
31 /** \file include/FLAC++/encoder.h
34 * This module contains the classes which implement the various
37 * See the detailed documentation in the
38 * \link flacpp_encoder encoder \endlink module.
41 /** \defgroup flacpp_encoder FLAC++/encoder.h: encoder classes
45 * This module describes the three encoder layers provided by libFLAC++.
47 * The libFLAC++ encoder classes are object wrappers around their
48 * counterparts in libFLAC. All three encoding layers available in
49 * libFLAC are also provided here. The interface is very similar;
50 * make sure to read the \link flac_encoder libFLAC encoder module \endlink.
52 * The only real difference here is that instead of passing in C function
53 * pointers for callbacks, you inherit from the encoder class and provide
54 * implementations for the callbacks in the derived class; because of this
55 * there is no need for a 'client_data' property.
61 // ============================================================
63 // Equivalent: FLAC__StreamEncoder
65 // ============================================================
67 /** \defgroup flacpp_stream_encoder FLAC++/encoder.h: stream encoder class
68 * \ingroup flacpp_encoder
71 * This class wraps the ::FLAC__StreamEncoder.
73 * See the \link flac_stream_encoder libFLAC stream encoder module \endlink.
78 /** This class wraps the ::FLAC__StreamEncoder.
80 class FLACPP_API Stream {
82 class FLACPP_API State {
84 inline State(::FLAC__StreamEncoderState state): state_(state) { }
85 inline operator ::FLAC__StreamEncoderState() const { return state_; }
86 inline const char *as_cstring() const { return ::FLAC__StreamEncoderStateString[state_]; }
87 const char *resolved_as_cstring(const Stream &) const;
89 ::FLAC__StreamEncoderState state_;
95 bool is_valid() const;
96 inline operator bool() const { return is_valid(); }
98 bool set_verify(bool value);
99 bool set_streamable_subset(bool value);
100 bool set_do_mid_side_stereo(bool value);
101 bool set_loose_mid_side_stereo(bool value);
102 bool set_channels(unsigned value);
103 bool set_bits_per_sample(unsigned value);
104 bool set_sample_rate(unsigned value);
105 bool set_blocksize(unsigned value);
106 bool set_max_lpc_order(unsigned value);
107 bool set_qlp_coeff_precision(unsigned value);
108 bool set_do_qlp_coeff_prec_search(bool value);
109 bool set_do_escape_coding(bool value);
110 bool set_do_exhaustive_model_search(bool value);
111 bool set_min_residual_partition_order(unsigned value);
112 bool set_max_residual_partition_order(unsigned value);
113 bool set_rice_parameter_search_dist(unsigned value);
114 bool set_total_samples_estimate(FLAC__uint64 value);
115 bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
117 State get_state() const;
118 Decoder::Stream::State get_verify_decoder_state() const;
119 void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
120 bool get_verify() const;
121 bool get_streamable_subset() const;
122 bool get_do_mid_side_stereo() const;
123 bool get_loose_mid_side_stereo() const;
124 unsigned get_channels() const;
125 unsigned get_bits_per_sample() const;
126 unsigned get_sample_rate() const;
127 unsigned get_blocksize() const;
128 unsigned get_max_lpc_order() const;
129 unsigned get_qlp_coeff_precision() const;
130 bool get_do_qlp_coeff_prec_search() const;
131 bool get_do_escape_coding() const;
132 bool get_do_exhaustive_model_search() const;
133 unsigned get_min_residual_partition_order() const;
134 unsigned get_max_residual_partition_order() const;
135 unsigned get_rice_parameter_search_dist() const;
136 FLAC__uint64 get_total_samples_estimate() const;
142 bool process(const FLAC__int32 * const buffer[], unsigned samples);
143 bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
145 virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
146 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
148 ::FLAC__StreamEncoder *encoder_;
150 static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
151 static void metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
153 // Private and undefined so you can't use them:
154 Stream(const Stream &);
155 void operator=(const Stream &);
160 /** \defgroup flacpp_seekable_stream_encoder FLAC++/encoder.h: seekable stream encoder class
161 * \ingroup flacpp_encoder
164 * This class wraps the ::FLAC__SeekableStreamEncoder.
166 * See the \link flac_seekable_stream_encoder libFLAC seekable stream encoder module \endlink.
171 /** This class wraps the ::FLAC__SeekableStreamEncoder.
173 class FLACPP_API SeekableStream {
175 class FLACPP_API State {
177 inline State(::FLAC__SeekableStreamEncoderState state): state_(state) { }
178 inline operator ::FLAC__SeekableStreamEncoderState() const { return state_; }
179 inline const char *as_cstring() const { return ::FLAC__SeekableStreamEncoderStateString[state_]; }
180 const char *resolved_as_cstring(const SeekableStream &) const;
182 ::FLAC__SeekableStreamEncoderState state_;
186 virtual ~SeekableStream();
188 bool is_valid() const;
189 inline operator bool() const { return is_valid(); }
191 bool set_verify(bool value);
192 bool set_streamable_subset(bool value);
193 bool set_do_mid_side_stereo(bool value);
194 bool set_loose_mid_side_stereo(bool value);
195 bool set_channels(unsigned value);
196 bool set_bits_per_sample(unsigned value);
197 bool set_sample_rate(unsigned value);
198 bool set_blocksize(unsigned value);
199 bool set_max_lpc_order(unsigned value);
200 bool set_qlp_coeff_precision(unsigned value);
201 bool set_do_qlp_coeff_prec_search(bool value);
202 bool set_do_escape_coding(bool value);
203 bool set_do_exhaustive_model_search(bool value);
204 bool set_min_residual_partition_order(unsigned value);
205 bool set_max_residual_partition_order(unsigned value);
206 bool set_rice_parameter_search_dist(unsigned value);
207 bool set_total_samples_estimate(FLAC__uint64 value);
208 bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
210 State get_state() const;
211 Stream::State get_stream_encoder_state() const;
212 Decoder::Stream::State get_verify_decoder_state() const;
213 void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
214 bool get_verify() const;
215 bool get_streamable_subset() const;
216 bool get_do_mid_side_stereo() const;
217 bool get_loose_mid_side_stereo() const;
218 unsigned get_channels() const;
219 unsigned get_bits_per_sample() const;
220 unsigned get_sample_rate() const;
221 unsigned get_blocksize() const;
222 unsigned get_max_lpc_order() const;
223 unsigned get_qlp_coeff_precision() const;
224 bool get_do_qlp_coeff_prec_search() const;
225 bool get_do_escape_coding() const;
226 bool get_do_exhaustive_model_search() const;
227 unsigned get_min_residual_partition_order() const;
228 unsigned get_max_residual_partition_order() const;
229 unsigned get_rice_parameter_search_dist() const;
230 FLAC__uint64 get_total_samples_estimate() const;
236 bool process(const FLAC__int32 * const buffer[], unsigned samples);
237 bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
239 virtual ::FLAC__SeekableStreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
240 virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
242 ::FLAC__SeekableStreamEncoder *encoder_;
244 static ::FLAC__SeekableStreamEncoderSeekStatus seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
245 static ::FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
247 // Private and undefined so you can't use them:
248 SeekableStream(const SeekableStream &);
249 void operator=(const SeekableStream &);
254 /** \defgroup flacpp_file_encoder FLAC++/encoder.h: file encoder class
255 * \ingroup flacpp_encoder
258 * This class wraps the ::FLAC__FileEncoder.
260 * See the \link flac_file_encoder libFLAC file encoder module \endlink.
265 /** This class wraps the ::FLAC__FileEncoder.
267 class FLACPP_API File {
269 class FLACPP_API State {
271 inline State(::FLAC__FileEncoderState state): state_(state) { }
272 inline operator ::FLAC__FileEncoderState() const { return state_; }
273 inline const char *as_cstring() const { return ::FLAC__FileEncoderStateString[state_]; }
274 const char *resolved_as_cstring(const File &) const;
276 ::FLAC__FileEncoderState state_;
282 bool is_valid() const;
283 inline operator bool() const { return is_valid(); }
285 bool set_verify(bool value);
286 bool set_streamable_subset(bool value);
287 bool set_do_mid_side_stereo(bool value);
288 bool set_loose_mid_side_stereo(bool value);
289 bool set_channels(unsigned value);
290 bool set_bits_per_sample(unsigned value);
291 bool set_sample_rate(unsigned value);
292 bool set_blocksize(unsigned value);
293 bool set_max_lpc_order(unsigned value);
294 bool set_qlp_coeff_precision(unsigned value);
295 bool set_do_qlp_coeff_prec_search(bool value);
296 bool set_do_escape_coding(bool value);
297 bool set_do_exhaustive_model_search(bool value);
298 bool set_min_residual_partition_order(unsigned value);
299 bool set_max_residual_partition_order(unsigned value);
300 bool set_rice_parameter_search_dist(unsigned value);
301 bool set_total_samples_estimate(FLAC__uint64 value);
302 bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
303 bool set_filename(const char *value);
305 State get_state() const;
306 SeekableStream::State get_seekable_stream_encoder_state() const;
307 Stream::State get_stream_encoder_state() const;
308 Decoder::Stream::State get_verify_decoder_state() const;
309 void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
310 bool get_verify() const;
311 bool get_streamable_subset() const;
312 bool get_do_mid_side_stereo() const;
313 bool get_loose_mid_side_stereo() const;
314 unsigned get_channels() const;
315 unsigned get_bits_per_sample() const;
316 unsigned get_sample_rate() const;
317 unsigned get_blocksize() const;
318 unsigned get_max_lpc_order() const;
319 unsigned get_qlp_coeff_precision() const;
320 bool get_do_qlp_coeff_prec_search() const;
321 bool get_do_escape_coding() const;
322 bool get_do_exhaustive_model_search() const;
323 unsigned get_min_residual_partition_order() const;
324 unsigned get_max_residual_partition_order() const;
325 unsigned get_rice_parameter_search_dist() const;
326 FLAC__uint64 get_total_samples_estimate() const;
332 bool process(const FLAC__int32 * const buffer[], unsigned samples);
333 bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
335 virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
337 ::FLAC__FileEncoder *encoder_;
339 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);
341 // Private and undefined so you can't use them:
342 File(const Stream &);
343 void operator=(const Stream &);