1 /* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
2 * Copyright (C) 2002,2003 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 "OggFLAC++/encoder.h"
21 #include "FLAC/assert.h"
27 encoder_(::OggFLAC__stream_encoder_new())
33 ::OggFLAC__stream_encoder_finish(encoder_);
34 ::OggFLAC__stream_encoder_delete(encoder_);
38 bool Stream::is_valid() const
43 bool Stream::set_serial_number(long value)
45 FLAC__ASSERT(is_valid());
46 return (bool)::OggFLAC__stream_encoder_set_serial_number(encoder_, value);
49 bool Stream::set_verify(bool value)
51 FLAC__ASSERT(is_valid());
52 return (bool)::OggFLAC__stream_encoder_set_verify(encoder_, value);
55 bool Stream::set_streamable_subset(bool value)
57 FLAC__ASSERT(is_valid());
58 return (bool)::OggFLAC__stream_encoder_set_streamable_subset(encoder_, value);
61 bool Stream::set_do_mid_side_stereo(bool value)
63 FLAC__ASSERT(is_valid());
64 return (bool)::OggFLAC__stream_encoder_set_do_mid_side_stereo(encoder_, value);
67 bool Stream::set_loose_mid_side_stereo(bool value)
69 FLAC__ASSERT(is_valid());
70 return (bool)::OggFLAC__stream_encoder_set_loose_mid_side_stereo(encoder_, value);
73 bool Stream::set_channels(unsigned value)
75 FLAC__ASSERT(is_valid());
76 return (bool)::OggFLAC__stream_encoder_set_channels(encoder_, value);
79 bool Stream::set_bits_per_sample(unsigned value)
81 FLAC__ASSERT(is_valid());
82 return (bool)::OggFLAC__stream_encoder_set_bits_per_sample(encoder_, value);
85 bool Stream::set_sample_rate(unsigned value)
87 FLAC__ASSERT(is_valid());
88 return (bool)::OggFLAC__stream_encoder_set_sample_rate(encoder_, value);
91 bool Stream::set_blocksize(unsigned value)
93 FLAC__ASSERT(is_valid());
94 return (bool)::OggFLAC__stream_encoder_set_blocksize(encoder_, value);
97 bool Stream::set_max_lpc_order(unsigned value)
99 FLAC__ASSERT(is_valid());
100 return (bool)::OggFLAC__stream_encoder_set_max_lpc_order(encoder_, value);
103 bool Stream::set_qlp_coeff_precision(unsigned value)
105 FLAC__ASSERT(is_valid());
106 return (bool)::OggFLAC__stream_encoder_set_qlp_coeff_precision(encoder_, value);
109 bool Stream::set_do_qlp_coeff_prec_search(bool value)
111 FLAC__ASSERT(is_valid());
112 return (bool)::OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder_, value);
115 bool Stream::set_do_escape_coding(bool value)
117 FLAC__ASSERT(is_valid());
118 return (bool)::OggFLAC__stream_encoder_set_do_escape_coding(encoder_, value);
121 bool Stream::set_do_exhaustive_model_search(bool value)
123 FLAC__ASSERT(is_valid());
124 return (bool)::OggFLAC__stream_encoder_set_do_exhaustive_model_search(encoder_, value);
127 bool Stream::set_min_residual_partition_order(unsigned value)
129 FLAC__ASSERT(is_valid());
130 return (bool)::OggFLAC__stream_encoder_set_min_residual_partition_order(encoder_, value);
133 bool Stream::set_max_residual_partition_order(unsigned value)
135 FLAC__ASSERT(is_valid());
136 return (bool)::OggFLAC__stream_encoder_set_max_residual_partition_order(encoder_, value);
139 bool Stream::set_rice_parameter_search_dist(unsigned value)
141 FLAC__ASSERT(is_valid());
142 return (bool)::OggFLAC__stream_encoder_set_rice_parameter_search_dist(encoder_, value);
145 bool Stream::set_total_samples_estimate(FLAC__uint64 value)
147 FLAC__ASSERT(is_valid());
148 return (bool)::OggFLAC__stream_encoder_set_total_samples_estimate(encoder_, value);
151 bool Stream::set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks)
153 FLAC__ASSERT(is_valid());
154 return (bool)::OggFLAC__stream_encoder_set_metadata(encoder_, metadata, num_blocks);
157 Stream::State Stream::get_state() const
159 FLAC__ASSERT(is_valid());
160 return State(::OggFLAC__stream_encoder_get_state(encoder_));
163 FLAC::Encoder::Stream::State Stream::get_FLAC_stream_encoder_state() const
165 FLAC__ASSERT(is_valid());
166 return FLAC::Encoder::Stream::State(::OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(encoder_));
169 FLAC::Decoder::Stream::State Stream::get_verify_decoder_state() const
171 FLAC__ASSERT(is_valid());
172 return FLAC::Decoder::Stream::State(::OggFLAC__stream_encoder_get_verify_decoder_state(encoder_));
175 void Stream::get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got)
177 FLAC__ASSERT(is_valid());
178 ::OggFLAC__stream_encoder_get_verify_decoder_error_stats(encoder_, absolute_sample, frame_number, channel, sample, expected, got);
181 bool Stream::get_verify() const
183 FLAC__ASSERT(is_valid());
184 return (bool)::OggFLAC__stream_encoder_get_verify(encoder_);
187 bool Stream::get_streamable_subset() const
189 FLAC__ASSERT(is_valid());
190 return (bool)::OggFLAC__stream_encoder_get_streamable_subset(encoder_);
193 bool Stream::get_do_mid_side_stereo() const
195 FLAC__ASSERT(is_valid());
196 return (bool)::OggFLAC__stream_encoder_get_do_mid_side_stereo(encoder_);
199 bool Stream::get_loose_mid_side_stereo() const
201 FLAC__ASSERT(is_valid());
202 return (bool)::OggFLAC__stream_encoder_get_loose_mid_side_stereo(encoder_);
205 unsigned Stream::get_channels() const
207 FLAC__ASSERT(is_valid());
208 return ::OggFLAC__stream_encoder_get_channels(encoder_);
211 unsigned Stream::get_bits_per_sample() const
213 FLAC__ASSERT(is_valid());
214 return ::OggFLAC__stream_encoder_get_bits_per_sample(encoder_);
217 unsigned Stream::get_sample_rate() const
219 FLAC__ASSERT(is_valid());
220 return ::OggFLAC__stream_encoder_get_sample_rate(encoder_);
223 unsigned Stream::get_blocksize() const
225 FLAC__ASSERT(is_valid());
226 return ::OggFLAC__stream_encoder_get_blocksize(encoder_);
229 unsigned Stream::get_max_lpc_order() const
231 FLAC__ASSERT(is_valid());
232 return ::OggFLAC__stream_encoder_get_max_lpc_order(encoder_);
235 unsigned Stream::get_qlp_coeff_precision() const
237 FLAC__ASSERT(is_valid());
238 return ::OggFLAC__stream_encoder_get_qlp_coeff_precision(encoder_);
241 bool Stream::get_do_qlp_coeff_prec_search() const
243 FLAC__ASSERT(is_valid());
244 return (bool)::OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder_);
247 bool Stream::get_do_escape_coding() const
249 FLAC__ASSERT(is_valid());
250 return (bool)::OggFLAC__stream_encoder_get_do_escape_coding(encoder_);
253 bool Stream::get_do_exhaustive_model_search() const
255 FLAC__ASSERT(is_valid());
256 return (bool)::OggFLAC__stream_encoder_get_do_exhaustive_model_search(encoder_);
259 unsigned Stream::get_min_residual_partition_order() const
261 FLAC__ASSERT(is_valid());
262 return ::OggFLAC__stream_encoder_get_min_residual_partition_order(encoder_);
265 unsigned Stream::get_max_residual_partition_order() const
267 FLAC__ASSERT(is_valid());
268 return ::OggFLAC__stream_encoder_get_max_residual_partition_order(encoder_);
271 unsigned Stream::get_rice_parameter_search_dist() const
273 FLAC__ASSERT(is_valid());
274 return ::OggFLAC__stream_encoder_get_rice_parameter_search_dist(encoder_);
277 FLAC__uint64 Stream::get_total_samples_estimate() const
279 FLAC__ASSERT(is_valid());
280 return ::OggFLAC__stream_encoder_get_total_samples_estimate(encoder_);
283 Stream::State Stream::init()
285 FLAC__ASSERT(is_valid());
286 ::OggFLAC__stream_encoder_set_write_callback(encoder_, write_callback_);
287 ::OggFLAC__stream_encoder_set_client_data(encoder_, (void*)this);
288 return State(::OggFLAC__stream_encoder_init(encoder_));
291 void Stream::finish()
293 FLAC__ASSERT(is_valid());
294 ::OggFLAC__stream_encoder_finish(encoder_);
297 bool Stream::process(const FLAC__int32 * const buffer[], unsigned samples)
299 FLAC__ASSERT(is_valid());
300 return (bool)::OggFLAC__stream_encoder_process(encoder_, buffer, samples);
303 bool Stream::process_interleaved(const FLAC__int32 buffer[], unsigned samples)
305 FLAC__ASSERT(is_valid());
306 return (bool)::OggFLAC__stream_encoder_process_interleaved(encoder_, buffer, samples);
309 ::FLAC__StreamEncoderWriteStatus Stream::write_callback_(const ::OggFLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
312 FLAC__ASSERT(0 != client_data);
313 Stream *instance = reinterpret_cast<Stream *>(client_data);
314 FLAC__ASSERT(0 != instance);
315 return instance->write_callback(buffer, bytes, samples, current_frame);