1 /* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
2 * Copyright (C) 2002,2003,2004 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 #include "OggFLAC++/encoder.h"
33 #include "FLAC/assert.h"
36 // warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
37 #pragma warning ( disable : 4800 )
44 encoder_(::OggFLAC__file_encoder_new())
50 ::OggFLAC__file_encoder_finish(encoder_);
51 ::OggFLAC__file_encoder_delete(encoder_);
55 bool File::set_serial_number(long value)
57 FLAC__ASSERT(is_valid());
58 return (bool)::OggFLAC__file_encoder_set_serial_number(encoder_, value);
61 bool File::is_valid() const
66 bool File::set_verify(bool value)
68 FLAC__ASSERT(is_valid());
69 return (bool)::OggFLAC__file_encoder_set_verify(encoder_, value);
72 bool File::set_streamable_subset(bool value)
74 FLAC__ASSERT(is_valid());
75 return (bool)::OggFLAC__file_encoder_set_streamable_subset(encoder_, value);
78 bool File::set_do_mid_side_stereo(bool value)
80 FLAC__ASSERT(is_valid());
81 return (bool)::OggFLAC__file_encoder_set_do_mid_side_stereo(encoder_, value);
84 bool File::set_loose_mid_side_stereo(bool value)
86 FLAC__ASSERT(is_valid());
87 return (bool)::OggFLAC__file_encoder_set_loose_mid_side_stereo(encoder_, value);
90 bool File::set_channels(unsigned value)
92 FLAC__ASSERT(is_valid());
93 return (bool)::OggFLAC__file_encoder_set_channels(encoder_, value);
96 bool File::set_bits_per_sample(unsigned value)
98 FLAC__ASSERT(is_valid());
99 return (bool)::OggFLAC__file_encoder_set_bits_per_sample(encoder_, value);
102 bool File::set_sample_rate(unsigned value)
104 FLAC__ASSERT(is_valid());
105 return (bool)::OggFLAC__file_encoder_set_sample_rate(encoder_, value);
108 bool File::set_blocksize(unsigned value)
110 FLAC__ASSERT(is_valid());
111 return (bool)::OggFLAC__file_encoder_set_blocksize(encoder_, value);
114 bool File::set_max_lpc_order(unsigned value)
116 FLAC__ASSERT(is_valid());
117 return (bool)::OggFLAC__file_encoder_set_max_lpc_order(encoder_, value);
120 bool File::set_qlp_coeff_precision(unsigned value)
122 FLAC__ASSERT(is_valid());
123 return (bool)::OggFLAC__file_encoder_set_qlp_coeff_precision(encoder_, value);
126 bool File::set_do_qlp_coeff_prec_search(bool value)
128 FLAC__ASSERT(is_valid());
129 return (bool)::OggFLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder_, value);
132 bool File::set_do_escape_coding(bool value)
134 FLAC__ASSERT(is_valid());
135 return (bool)::OggFLAC__file_encoder_set_do_escape_coding(encoder_, value);
138 bool File::set_do_exhaustive_model_search(bool value)
140 FLAC__ASSERT(is_valid());
141 return (bool)::OggFLAC__file_encoder_set_do_exhaustive_model_search(encoder_, value);
144 bool File::set_min_residual_partition_order(unsigned value)
146 FLAC__ASSERT(is_valid());
147 return (bool)::OggFLAC__file_encoder_set_min_residual_partition_order(encoder_, value);
150 bool File::set_max_residual_partition_order(unsigned value)
152 FLAC__ASSERT(is_valid());
153 return (bool)::OggFLAC__file_encoder_set_max_residual_partition_order(encoder_, value);
156 bool File::set_rice_parameter_search_dist(unsigned value)
158 FLAC__ASSERT(is_valid());
159 return (bool)::OggFLAC__file_encoder_set_rice_parameter_search_dist(encoder_, value);
162 bool File::set_total_samples_estimate(FLAC__uint64 value)
164 FLAC__ASSERT(is_valid());
165 return (bool)::OggFLAC__file_encoder_set_total_samples_estimate(encoder_, value);
168 bool File::set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks)
170 FLAC__ASSERT(is_valid());
171 return (bool)::OggFLAC__file_encoder_set_metadata(encoder_, metadata, num_blocks);
174 bool File::set_filename(const char *value)
176 FLAC__ASSERT(is_valid());
177 return (bool)::OggFLAC__file_encoder_set_filename(encoder_, value);
180 File::State File::get_state() const
182 FLAC__ASSERT(is_valid());
183 return State(::OggFLAC__file_encoder_get_state(encoder_));
186 SeekableStream::State File::get_seekable_stream_encoder_state() const
188 FLAC__ASSERT(is_valid());
189 return SeekableStream::State(::OggFLAC__file_encoder_get_seekable_stream_encoder_state(encoder_));
192 FLAC::Encoder::Stream::State File::get_FLAC_stream_encoder_state() const
194 FLAC__ASSERT(is_valid());
195 return FLAC::Encoder::Stream::State(::OggFLAC__file_encoder_get_FLAC_stream_encoder_state(encoder_));
198 FLAC::Decoder::Stream::State File::get_verify_decoder_state() const
200 FLAC__ASSERT(is_valid());
201 return FLAC::Decoder::Stream::State(::OggFLAC__file_encoder_get_verify_decoder_state(encoder_));
204 void File::get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got)
206 FLAC__ASSERT(is_valid());
207 ::OggFLAC__file_encoder_get_verify_decoder_error_stats(encoder_, absolute_sample, frame_number, channel, sample, expected, got);
210 bool File::get_verify() const
212 FLAC__ASSERT(is_valid());
213 return (bool)::OggFLAC__file_encoder_get_verify(encoder_);
216 bool File::get_streamable_subset() const
218 FLAC__ASSERT(is_valid());
219 return (bool)::OggFLAC__file_encoder_get_streamable_subset(encoder_);
222 bool File::get_do_mid_side_stereo() const
224 FLAC__ASSERT(is_valid());
225 return (bool)::OggFLAC__file_encoder_get_do_mid_side_stereo(encoder_);
228 bool File::get_loose_mid_side_stereo() const
230 FLAC__ASSERT(is_valid());
231 return (bool)::OggFLAC__file_encoder_get_loose_mid_side_stereo(encoder_);
234 unsigned File::get_channels() const
236 FLAC__ASSERT(is_valid());
237 return ::OggFLAC__file_encoder_get_channels(encoder_);
240 unsigned File::get_bits_per_sample() const
242 FLAC__ASSERT(is_valid());
243 return ::OggFLAC__file_encoder_get_bits_per_sample(encoder_);
246 unsigned File::get_sample_rate() const
248 FLAC__ASSERT(is_valid());
249 return ::OggFLAC__file_encoder_get_sample_rate(encoder_);
252 unsigned File::get_blocksize() const
254 FLAC__ASSERT(is_valid());
255 return ::OggFLAC__file_encoder_get_blocksize(encoder_);
258 unsigned File::get_max_lpc_order() const
260 FLAC__ASSERT(is_valid());
261 return ::OggFLAC__file_encoder_get_max_lpc_order(encoder_);
264 unsigned File::get_qlp_coeff_precision() const
266 FLAC__ASSERT(is_valid());
267 return ::OggFLAC__file_encoder_get_qlp_coeff_precision(encoder_);
270 bool File::get_do_qlp_coeff_prec_search() const
272 FLAC__ASSERT(is_valid());
273 return (bool)::OggFLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder_);
276 bool File::get_do_escape_coding() const
278 FLAC__ASSERT(is_valid());
279 return (bool)::OggFLAC__file_encoder_get_do_escape_coding(encoder_);
282 bool File::get_do_exhaustive_model_search() const
284 FLAC__ASSERT(is_valid());
285 return (bool)::OggFLAC__file_encoder_get_do_exhaustive_model_search(encoder_);
288 unsigned File::get_min_residual_partition_order() const
290 FLAC__ASSERT(is_valid());
291 return ::OggFLAC__file_encoder_get_min_residual_partition_order(encoder_);
294 unsigned File::get_max_residual_partition_order() const
296 FLAC__ASSERT(is_valid());
297 return ::OggFLAC__file_encoder_get_max_residual_partition_order(encoder_);
300 unsigned File::get_rice_parameter_search_dist() const
302 FLAC__ASSERT(is_valid());
303 return ::OggFLAC__file_encoder_get_rice_parameter_search_dist(encoder_);
306 FLAC__uint64 File::get_total_samples_estimate() const
308 FLAC__ASSERT(is_valid());
309 return ::OggFLAC__file_encoder_get_total_samples_estimate(encoder_);
312 File::State File::init()
314 FLAC__ASSERT(is_valid());
315 ::OggFLAC__file_encoder_set_progress_callback(encoder_, progress_callback_);
316 ::OggFLAC__file_encoder_set_client_data(encoder_, (void*)this);
317 return State(::OggFLAC__file_encoder_init(encoder_));
322 FLAC__ASSERT(is_valid());
323 ::OggFLAC__file_encoder_finish(encoder_);
326 bool File::process(const FLAC__int32 * const buffer[], unsigned samples)
328 FLAC__ASSERT(is_valid());
329 return (bool)::OggFLAC__file_encoder_process(encoder_, buffer, samples);
332 bool File::process_interleaved(const FLAC__int32 buffer[], unsigned samples)
334 FLAC__ASSERT(is_valid());
335 return (bool)::OggFLAC__file_encoder_process_interleaved(encoder_, buffer, samples);
338 void File::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate)
340 (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate;
343 void File::progress_callback_(const ::OggFLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data)
346 FLAC__ASSERT(0 != client_data);
347 File *instance = reinterpret_cast<File *>(client_data);
348 FLAC__ASSERT(0 != instance);
349 instance->progress_callback(bytes_written, samples_written, frames_written, total_frames_estimate);