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