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 #include "FLAC++/encoder.h"
21 #include "FLAC/assert.h"
26 const char *File::State::resolved_as_cstring(const File &encoder) const
28 if(state_ == ::FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
29 FLAC::Encoder::SeekableStream::State state__ = encoder.get_seekable_stream_encoder_state();
30 if(state__ == ::FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
31 FLAC::Encoder::Stream::State state___ = encoder.get_stream_encoder_state();
32 if(state___ == ::FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
33 return encoder.get_verify_decoder_state().as_cstring();
35 return state___.as_cstring();
38 return state__.as_cstring();
45 encoder_(::FLAC__file_encoder_new())
51 ::FLAC__file_encoder_finish(encoder_);
52 ::FLAC__file_encoder_delete(encoder_);
56 bool File::is_valid() const
61 bool File::set_verify(bool value)
63 FLAC__ASSERT(is_valid());
64 return (bool)::FLAC__file_encoder_set_verify(encoder_, value);
67 bool File::set_streamable_subset(bool value)
69 FLAC__ASSERT(is_valid());
70 return (bool)::FLAC__file_encoder_set_streamable_subset(encoder_, value);
73 bool File::set_do_mid_side_stereo(bool value)
75 FLAC__ASSERT(is_valid());
76 return (bool)::FLAC__file_encoder_set_do_mid_side_stereo(encoder_, value);
79 bool File::set_loose_mid_side_stereo(bool value)
81 FLAC__ASSERT(is_valid());
82 return (bool)::FLAC__file_encoder_set_loose_mid_side_stereo(encoder_, value);
85 bool File::set_channels(unsigned value)
87 FLAC__ASSERT(is_valid());
88 return (bool)::FLAC__file_encoder_set_channels(encoder_, value);
91 bool File::set_bits_per_sample(unsigned value)
93 FLAC__ASSERT(is_valid());
94 return (bool)::FLAC__file_encoder_set_bits_per_sample(encoder_, value);
97 bool File::set_sample_rate(unsigned value)
99 FLAC__ASSERT(is_valid());
100 return (bool)::FLAC__file_encoder_set_sample_rate(encoder_, value);
103 bool File::set_blocksize(unsigned value)
105 FLAC__ASSERT(is_valid());
106 return (bool)::FLAC__file_encoder_set_blocksize(encoder_, value);
109 bool File::set_max_lpc_order(unsigned value)
111 FLAC__ASSERT(is_valid());
112 return (bool)::FLAC__file_encoder_set_max_lpc_order(encoder_, value);
115 bool File::set_qlp_coeff_precision(unsigned value)
117 FLAC__ASSERT(is_valid());
118 return (bool)::FLAC__file_encoder_set_qlp_coeff_precision(encoder_, value);
121 bool File::set_do_qlp_coeff_prec_search(bool value)
123 FLAC__ASSERT(is_valid());
124 return (bool)::FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder_, value);
127 bool File::set_do_escape_coding(bool value)
129 FLAC__ASSERT(is_valid());
130 return (bool)::FLAC__file_encoder_set_do_escape_coding(encoder_, value);
133 bool File::set_do_exhaustive_model_search(bool value)
135 FLAC__ASSERT(is_valid());
136 return (bool)::FLAC__file_encoder_set_do_exhaustive_model_search(encoder_, value);
139 bool File::set_min_residual_partition_order(unsigned value)
141 FLAC__ASSERT(is_valid());
142 return (bool)::FLAC__file_encoder_set_min_residual_partition_order(encoder_, value);
145 bool File::set_max_residual_partition_order(unsigned value)
147 FLAC__ASSERT(is_valid());
148 return (bool)::FLAC__file_encoder_set_max_residual_partition_order(encoder_, value);
151 bool File::set_rice_parameter_search_dist(unsigned value)
153 FLAC__ASSERT(is_valid());
154 return (bool)::FLAC__file_encoder_set_rice_parameter_search_dist(encoder_, value);
157 bool File::set_total_samples_estimate(FLAC__uint64 value)
159 FLAC__ASSERT(is_valid());
160 return (bool)::FLAC__file_encoder_set_total_samples_estimate(encoder_, value);
163 bool File::set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks)
165 FLAC__ASSERT(is_valid());
166 return (bool)::FLAC__file_encoder_set_metadata(encoder_, metadata, num_blocks);
169 bool File::set_filename(const char *value)
171 FLAC__ASSERT(is_valid());
172 return (bool)::FLAC__file_encoder_set_filename(encoder_, value);
175 File::State File::get_state() const
177 FLAC__ASSERT(is_valid());
178 return State(::FLAC__file_encoder_get_state(encoder_));
181 SeekableStream::State File::get_seekable_stream_encoder_state() const
183 FLAC__ASSERT(is_valid());
184 return SeekableStream::State(::FLAC__file_encoder_get_seekable_stream_encoder_state(encoder_));
187 Stream::State File::get_stream_encoder_state() const
189 FLAC__ASSERT(is_valid());
190 return Stream::State(::FLAC__file_encoder_get_stream_encoder_state(encoder_));
193 Decoder::Stream::State File::get_verify_decoder_state() const
195 FLAC__ASSERT(is_valid());
196 return Decoder::Stream::State(::FLAC__file_encoder_get_verify_decoder_state(encoder_));
199 void File::get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got)
201 FLAC__ASSERT(is_valid());
202 ::FLAC__file_encoder_get_verify_decoder_error_stats(encoder_, absolute_sample, frame_number, channel, sample, expected, got);
205 bool File::get_verify() const
207 FLAC__ASSERT(is_valid());
208 return (bool)::FLAC__file_encoder_get_verify(encoder_);
211 bool File::get_streamable_subset() const
213 FLAC__ASSERT(is_valid());
214 return (bool)::FLAC__file_encoder_get_streamable_subset(encoder_);
217 bool File::get_do_mid_side_stereo() const
219 FLAC__ASSERT(is_valid());
220 return (bool)::FLAC__file_encoder_get_do_mid_side_stereo(encoder_);
223 bool File::get_loose_mid_side_stereo() const
225 FLAC__ASSERT(is_valid());
226 return (bool)::FLAC__file_encoder_get_loose_mid_side_stereo(encoder_);
229 unsigned File::get_channels() const
231 FLAC__ASSERT(is_valid());
232 return ::FLAC__file_encoder_get_channels(encoder_);
235 unsigned File::get_bits_per_sample() const
237 FLAC__ASSERT(is_valid());
238 return ::FLAC__file_encoder_get_bits_per_sample(encoder_);
241 unsigned File::get_sample_rate() const
243 FLAC__ASSERT(is_valid());
244 return ::FLAC__file_encoder_get_sample_rate(encoder_);
247 unsigned File::get_blocksize() const
249 FLAC__ASSERT(is_valid());
250 return ::FLAC__file_encoder_get_blocksize(encoder_);
253 unsigned File::get_max_lpc_order() const
255 FLAC__ASSERT(is_valid());
256 return ::FLAC__file_encoder_get_max_lpc_order(encoder_);
259 unsigned File::get_qlp_coeff_precision() const
261 FLAC__ASSERT(is_valid());
262 return ::FLAC__file_encoder_get_qlp_coeff_precision(encoder_);
265 bool File::get_do_qlp_coeff_prec_search() const
267 FLAC__ASSERT(is_valid());
268 return (bool)::FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder_);
271 bool File::get_do_escape_coding() const
273 FLAC__ASSERT(is_valid());
274 return (bool)::FLAC__file_encoder_get_do_escape_coding(encoder_);
277 bool File::get_do_exhaustive_model_search() const
279 FLAC__ASSERT(is_valid());
280 return (bool)::FLAC__file_encoder_get_do_exhaustive_model_search(encoder_);
283 unsigned File::get_min_residual_partition_order() const
285 FLAC__ASSERT(is_valid());
286 return ::FLAC__file_encoder_get_min_residual_partition_order(encoder_);
289 unsigned File::get_max_residual_partition_order() const
291 FLAC__ASSERT(is_valid());
292 return ::FLAC__file_encoder_get_max_residual_partition_order(encoder_);
295 unsigned File::get_rice_parameter_search_dist() const
297 FLAC__ASSERT(is_valid());
298 return ::FLAC__file_encoder_get_rice_parameter_search_dist(encoder_);
301 FLAC__uint64 File::get_total_samples_estimate() const
303 FLAC__ASSERT(is_valid());
304 return ::FLAC__file_encoder_get_total_samples_estimate(encoder_);
307 File::State File::init()
309 FLAC__ASSERT(is_valid());
310 ::FLAC__file_encoder_set_progress_callback(encoder_, progress_callback_);
311 ::FLAC__file_encoder_set_client_data(encoder_, (void*)this);
312 return State(::FLAC__file_encoder_init(encoder_));
317 FLAC__ASSERT(is_valid());
318 ::FLAC__file_encoder_finish(encoder_);
321 bool File::process(const FLAC__int32 * const buffer[], unsigned samples)
323 FLAC__ASSERT(is_valid());
324 return (bool)::FLAC__file_encoder_process(encoder_, buffer, samples);
327 bool File::process_interleaved(const FLAC__int32 buffer[], unsigned samples)
329 FLAC__ASSERT(is_valid());
330 return (bool)::FLAC__file_encoder_process_interleaved(encoder_, buffer, samples);
333 void File::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate)
335 (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate;
338 void File::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 FLAC__ASSERT(0 != client_data);
342 File *instance = reinterpret_cast<File *>(client_data);
343 FLAC__ASSERT(0 != instance);
344 instance->progress_callback(bytes_written, samples_written, frames_written, total_frames_estimate);