1 /* libFLAC++ - Free Lossless Audio Codec library
2 * Copyright (C) 2002,2003,2004,2005 Josh Coalson
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * - Neither the name of the Xiph.org Foundation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef FLACPP__ENCODER_H
33 #define FLACPP__ENCODER_H
37 #include "FLAC/file_encoder.h"
38 #include "FLAC/seekable_stream_encoder.h"
39 #include "FLAC/stream_encoder.h"
44 /** \file include/FLAC++/encoder.h
47 * This module contains the classes which implement the various
50 * See the detailed documentation in the
51 * \link flacpp_encoder encoder \endlink module.
54 /** \defgroup flacpp_encoder FLAC++/encoder.h: encoder classes
58 * This module describes the three encoder layers provided by libFLAC++.
60 * The libFLAC++ encoder classes are object wrappers around their
61 * counterparts in libFLAC. All three encoding layers available in
62 * libFLAC are also provided here. The interface is very similar;
63 * make sure to read the \link flac_encoder libFLAC encoder module \endlink.
65 * The only real difference here is that instead of passing in C function
66 * pointers for callbacks, you inherit from the encoder class and provide
67 * implementations for the callbacks in the derived class; because of this
68 * there is no need for a 'client_data' property.
74 // ============================================================
76 // Equivalent: FLAC__StreamEncoder
78 // ============================================================
80 /** \defgroup flacpp_stream_encoder FLAC++/encoder.h: stream encoder class
81 * \ingroup flacpp_encoder
84 * This class wraps the ::FLAC__StreamEncoder.
86 * See the \link flac_stream_encoder libFLAC stream encoder module \endlink.
91 /** This class wraps the ::FLAC__StreamEncoder.
93 class FLACPP_API Stream {
95 class FLACPP_API State {
97 inline State(::FLAC__StreamEncoderState state): state_(state) { }
98 inline operator ::FLAC__StreamEncoderState() const { return state_; }
99 inline const char *as_cstring() const { return ::FLAC__StreamEncoderStateString[state_]; }
100 inline const char *resolved_as_cstring(const Stream &encoder) const { return ::FLAC__stream_encoder_get_resolved_state_string(encoder.encoder_); }
102 ::FLAC__StreamEncoderState state_;
108 bool is_valid() const;
109 inline operator bool() const { return is_valid(); }
111 bool set_verify(bool value);
112 bool set_streamable_subset(bool value);
113 bool set_do_mid_side_stereo(bool value);
114 bool set_loose_mid_side_stereo(bool value);
115 bool set_channels(unsigned value);
116 bool set_bits_per_sample(unsigned value);
117 bool set_sample_rate(unsigned value);
118 bool set_blocksize(unsigned value);
119 bool set_max_lpc_order(unsigned value);
120 bool set_qlp_coeff_precision(unsigned value);
121 bool set_do_qlp_coeff_prec_search(bool value);
122 bool set_do_escape_coding(bool value);
123 bool set_do_exhaustive_model_search(bool value);
124 bool set_min_residual_partition_order(unsigned value);
125 bool set_max_residual_partition_order(unsigned value);
126 bool set_rice_parameter_search_dist(unsigned value);
127 bool set_total_samples_estimate(FLAC__uint64 value);
128 bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
129 bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks);
131 State get_state() const;
132 Decoder::Stream::State get_verify_decoder_state() const;
133 void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
134 bool get_verify() const;
135 bool get_streamable_subset() const;
136 bool get_do_mid_side_stereo() const;
137 bool get_loose_mid_side_stereo() const;
138 unsigned get_channels() const;
139 unsigned get_bits_per_sample() const;
140 unsigned get_sample_rate() const;
141 unsigned get_blocksize() const;
142 unsigned get_max_lpc_order() const;
143 unsigned get_qlp_coeff_precision() const;
144 bool get_do_qlp_coeff_prec_search() const;
145 bool get_do_escape_coding() const;
146 bool get_do_exhaustive_model_search() const;
147 unsigned get_min_residual_partition_order() const;
148 unsigned get_max_residual_partition_order() const;
149 unsigned get_rice_parameter_search_dist() const;
150 FLAC__uint64 get_total_samples_estimate() const;
156 bool process(const FLAC__int32 * const buffer[], unsigned samples);
157 bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
159 virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
160 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
162 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96)))
163 // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
166 ::FLAC__StreamEncoder *encoder_;
168 static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
169 static void metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
171 // Private and undefined so you can't use them:
172 Stream(const Stream &);
173 void operator=(const Stream &);
178 /** \defgroup flacpp_seekable_stream_encoder FLAC++/encoder.h: seekable stream encoder class
179 * \ingroup flacpp_encoder
182 * This class wraps the ::FLAC__SeekableStreamEncoder.
184 * See the \link flac_seekable_stream_encoder libFLAC seekable stream encoder module \endlink.
189 /** This class wraps the ::FLAC__SeekableStreamEncoder.
191 class FLACPP_API SeekableStream {
193 class FLACPP_API State {
195 inline State(::FLAC__SeekableStreamEncoderState state): state_(state) { }
196 inline operator ::FLAC__SeekableStreamEncoderState() const { return state_; }
197 inline const char *as_cstring() const { return ::FLAC__SeekableStreamEncoderStateString[state_]; }
198 inline const char *resolved_as_cstring(const SeekableStream &encoder) const { return ::FLAC__seekable_stream_encoder_get_resolved_state_string(encoder.encoder_); }
200 ::FLAC__SeekableStreamEncoderState state_;
204 virtual ~SeekableStream();
206 bool is_valid() const;
207 inline operator bool() const { return is_valid(); }
209 bool set_verify(bool value);
210 bool set_streamable_subset(bool value);
211 bool set_do_mid_side_stereo(bool value);
212 bool set_loose_mid_side_stereo(bool value);
213 bool set_channels(unsigned value);
214 bool set_bits_per_sample(unsigned value);
215 bool set_sample_rate(unsigned value);
216 bool set_blocksize(unsigned value);
217 bool set_max_lpc_order(unsigned value);
218 bool set_qlp_coeff_precision(unsigned value);
219 bool set_do_qlp_coeff_prec_search(bool value);
220 bool set_do_escape_coding(bool value);
221 bool set_do_exhaustive_model_search(bool value);
222 bool set_min_residual_partition_order(unsigned value);
223 bool set_max_residual_partition_order(unsigned value);
224 bool set_rice_parameter_search_dist(unsigned value);
225 bool set_total_samples_estimate(FLAC__uint64 value);
226 bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
227 bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks);
229 State get_state() const;
230 Stream::State get_stream_encoder_state() const;
231 Decoder::Stream::State get_verify_decoder_state() const;
232 void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
233 bool get_verify() const;
234 bool get_streamable_subset() const;
235 bool get_do_mid_side_stereo() const;
236 bool get_loose_mid_side_stereo() const;
237 unsigned get_channels() const;
238 unsigned get_bits_per_sample() const;
239 unsigned get_sample_rate() const;
240 unsigned get_blocksize() const;
241 unsigned get_max_lpc_order() const;
242 unsigned get_qlp_coeff_precision() const;
243 bool get_do_qlp_coeff_prec_search() const;
244 bool get_do_escape_coding() const;
245 bool get_do_exhaustive_model_search() const;
246 unsigned get_min_residual_partition_order() const;
247 unsigned get_max_residual_partition_order() const;
248 unsigned get_rice_parameter_search_dist() const;
249 FLAC__uint64 get_total_samples_estimate() const;
255 bool process(const FLAC__int32 * const buffer[], unsigned samples);
256 bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
258 virtual ::FLAC__SeekableStreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
259 virtual ::FLAC__SeekableStreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
260 virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
262 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96)))
263 // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
266 ::FLAC__SeekableStreamEncoder *encoder_;
268 static ::FLAC__SeekableStreamEncoderSeekStatus seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
269 static ::FLAC__SeekableStreamEncoderTellStatus tell_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
270 static ::FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
272 // Private and undefined so you can't use them:
273 SeekableStream(const SeekableStream &);
274 void operator=(const SeekableStream &);
279 /** \defgroup flacpp_file_encoder FLAC++/encoder.h: file encoder class
280 * \ingroup flacpp_encoder
283 * This class wraps the ::FLAC__FileEncoder.
285 * See the \link flac_file_encoder libFLAC file encoder module \endlink.
290 /** This class wraps the ::FLAC__FileEncoder.
292 class FLACPP_API File {
294 class FLACPP_API State {
296 inline State(::FLAC__FileEncoderState state): state_(state) { }
297 inline operator ::FLAC__FileEncoderState() const { return state_; }
298 inline const char *as_cstring() const { return ::FLAC__FileEncoderStateString[state_]; }
299 inline const char *resolved_as_cstring(const File &encoder) const { return ::FLAC__file_encoder_get_resolved_state_string(encoder.encoder_); }
301 ::FLAC__FileEncoderState state_;
307 bool is_valid() const;
308 inline operator bool() const { return is_valid(); }
310 bool set_verify(bool value);
311 bool set_streamable_subset(bool value);
312 bool set_do_mid_side_stereo(bool value);
313 bool set_loose_mid_side_stereo(bool value);
314 bool set_channels(unsigned value);
315 bool set_bits_per_sample(unsigned value);
316 bool set_sample_rate(unsigned value);
317 bool set_blocksize(unsigned value);
318 bool set_max_lpc_order(unsigned value);
319 bool set_qlp_coeff_precision(unsigned value);
320 bool set_do_qlp_coeff_prec_search(bool value);
321 bool set_do_escape_coding(bool value);
322 bool set_do_exhaustive_model_search(bool value);
323 bool set_min_residual_partition_order(unsigned value);
324 bool set_max_residual_partition_order(unsigned value);
325 bool set_rice_parameter_search_dist(unsigned value);
326 bool set_total_samples_estimate(FLAC__uint64 value);
327 bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);
328 bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks);
329 bool set_filename(const char *value);
331 State get_state() const;
332 SeekableStream::State get_seekable_stream_encoder_state() const;
333 Stream::State get_stream_encoder_state() const;
334 Decoder::Stream::State get_verify_decoder_state() const;
335 void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
336 bool get_verify() const;
337 bool get_streamable_subset() const;
338 bool get_do_mid_side_stereo() const;
339 bool get_loose_mid_side_stereo() const;
340 unsigned get_channels() const;
341 unsigned get_bits_per_sample() const;
342 unsigned get_sample_rate() const;
343 unsigned get_blocksize() const;
344 unsigned get_max_lpc_order() const;
345 unsigned get_qlp_coeff_precision() const;
346 bool get_do_qlp_coeff_prec_search() const;
347 bool get_do_escape_coding() const;
348 bool get_do_exhaustive_model_search() const;
349 unsigned get_min_residual_partition_order() const;
350 unsigned get_max_residual_partition_order() const;
351 unsigned get_rice_parameter_search_dist() const;
352 FLAC__uint64 get_total_samples_estimate() const;
358 bool process(const FLAC__int32 * const buffer[], unsigned samples);
359 bool process_interleaved(const FLAC__int32 buffer[], unsigned samples);
361 virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
363 #if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96)))
364 // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
367 ::FLAC__FileEncoder *encoder_;
369 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);
371 // Private and undefined so you can't use them:
372 File(const Stream &);
373 void operator=(const Stream &);