1 /* libOggFLAC - Free Lossless Audio Codec + Ogg library
2 * Copyright (C) 2002,2003,2004,2005,2006 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 OggFLAC__STREAM_ENCODER_H
33 #define OggFLAC__STREAM_ENCODER_H
37 #include "FLAC/stream_encoder.h"
44 /** \file include/OggFLAC/stream_encoder.h
47 * This module contains the functions which implement the stream
50 * See the detailed documentation in the
51 * \link oggflac_stream_encoder stream encoder \endlink module.
54 /** \defgroup oggflac_encoder OggFLAC/ *_encoder.h: encoder interfaces
58 * This module describes the three encoder layers provided by libOggFLAC.
60 * libOggFLAC currently provides the same three layers of access as libFLAC;
61 * the interfaces are nearly identical, with the addition of a method for
62 * specifying the Ogg serial number. See the \link flac_encoder FLAC
63 * encoder module \endlink for full documentation.
66 /** \defgroup oggflac_stream_encoder OggFLAC/stream_encoder.h: stream encoder interface
67 * \ingroup oggflac_encoder
70 * This module contains the functions which implement the stream
71 * encoder. The Ogg stream encoder is derived
72 * from the FLAC stream encoder.
74 * The interface here is nearly identical to FLAC's stream encoder,
75 * including the callbacks, with the addition of
76 * OggFLAC__stream_encoder_set_serial_number(). See the
77 * \link flac_stream_encoder FLAC stream encoder module \endlink
78 * for full documentation.
84 /** State values for an OggFLAC__StreamEncoder
86 * The encoder's state can be obtained by calling OggFLAC__stream_encoder_get_state().
90 OggFLAC__STREAM_ENCODER_OK = 0,
91 /**< The encoder is in the normal OK state and samples can be processed. */
93 OggFLAC__STREAM_ENCODER_UNINITIALIZED,
94 /**< The encoder is in the uninitialized state; one of the
95 * OggFLAC__stream_encoder_init_*() functions must be called before samples
99 OggFLAC__STREAM_ENCODER_OGG_ERROR,
100 /**< An error occurred in the underlying Ogg layer. */
102 OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR,
103 /**< An error occurred in the underlying FLAC stream encoder;
104 * check OggFLAC__stream_encoder_get_FLAC_stream_encoder_state().
107 OggFLAC__STREAM_ENCODER_CLIENT_ERROR,
108 /**< One of the callbacks returned a fatal error. */
110 OggFLAC__STREAM_ENCODER_IO_ERROR,
111 /**< An I/O error occurred while opening/reading/writing a file.
115 OggFLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
116 /**< Memory allocation failed. */
118 } OggFLAC__StreamEncoderState;
120 /** Maps an OggFLAC__StreamEncoderState to a C string.
122 * Using an OggFLAC__StreamEncoderState as the index to this array
123 * will give the string equivalent. The contents should not be modified.
125 extern OggFLAC_API const char * const OggFLAC__StreamEncoderStateString[];
128 /** Return values for the OggFLAC__StreamEncoder read callback.
132 OggFLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
133 /**< The read was OK and decoding can continue. */
135 OggFLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
136 /**< The read was attempted at the end of the stream. */
138 OggFLAC__STREAM_ENCODER_READ_STATUS_ABORT,
139 /**< An unrecoverable error occurred. */
141 OggFLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
142 /**< Client does not support reading back from the output. */
144 } OggFLAC__StreamEncoderReadStatus;
146 /** Maps a OggFLAC__StreamEncoderReadStatus to a C string.
148 * Using a OggFLAC__StreamEncoderReadStatus as the index to this array
149 * will give the string equivalent. The contents should not be modified.
151 extern OggFLAC_API const char * const OggFLAC__StreamEncoderReadStatusString[];
154 /***********************************************************************
156 * class OggFLAC__StreamEncoder
158 ***********************************************************************/
160 struct OggFLAC__StreamEncoderProtected;
161 struct OggFLAC__StreamEncoderPrivate;
162 /** The opaque structure definition for the stream encoder type.
163 * See the \link oggflac_stream_encoder stream encoder module \endlink
164 * for a detailed description.
167 FLAC__StreamEncoder super_; /* parentclass@@@@@@ */
168 struct OggFLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
169 struct OggFLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
170 } OggFLAC__StreamEncoder;
172 /** Signature for the read callback.
174 * A function pointer matching this signature must be passed to
175 * OggFLAC__stream_encoder_init_stream() if seeking is supported.
176 * The supplied function will be called when the encoder needs to read back
177 * encoded data. This happens during the metadata callback, when the encoder
178 * has to read, modify, and rewrite the metadata (e.g. seekpoints) gathered
179 * while encoding. The address of the buffer to be filled is supplied, along
180 * with the number of bytes the buffer can hold. The callback may choose to
181 * supply less data and modify the byte count but must be careful not to
182 * overflow the buffer. The callback then returns a status code chosen from
183 * OggFLAC__StreamEncoderReadStatus.
185 * \note In general, FLAC__StreamEncoder functions which change the
186 * state should not be called on the \a encoder while in the callback.
188 * \param encoder The encoder instance calling the callback.
189 * \param buffer A pointer to a location for the callee to store
190 * data to be encoded.
191 * \param bytes A pointer to the size of the buffer. On entry
192 * to the callback, it contains the maximum number
193 * of bytes that may be stored in \a buffer. The
194 * callee must set it to the actual number of bytes
195 * stored (0 in case of error or end-of-stream) before
197 * \param client_data The callee's client data set through
198 * OggFLAC__stream_encoder_set_client_data().
199 * \retval OggFLAC__StreamEncoderReadStatus
200 * The callee's return status.
202 typedef OggFLAC__StreamEncoderReadStatus (*OggFLAC__StreamEncoderReadCallback)(const OggFLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
205 /***********************************************************************
207 * Class constructor/destructor
209 ***********************************************************************/
211 /** Create a new stream encoder instance. The instance is created with
212 * default settings; see the individual OggFLAC__stream_encoder_set_*()
213 * functions for each setting's default.
215 * \retval OggFLAC__StreamEncoder*
216 * \c NULL if there was an error allocating memory, else the new instance.
218 OggFLAC_API OggFLAC__StreamEncoder *OggFLAC__stream_encoder_new();
220 /** Free an encoder instance. Deletes the object pointed to by \a encoder.
222 * \param encoder A pointer to an existing encoder.
224 * \code encoder != NULL \endcode
226 OggFLAC_API void OggFLAC__stream_encoder_delete(OggFLAC__StreamEncoder *encoder);
229 /***********************************************************************
231 * Public class method prototypes
233 ***********************************************************************/
235 /** Set the serial number for the FLAC stream.
238 * It is recommended to set a serial number explicitly as the default of '0'
239 * may collide with other streams.
242 * \param encoder An encoder instance to set.
243 * \param serial_number See above.
245 * \code encoder != NULL \endcode
247 * \c false if the encoder is already initialized, else \c true.
249 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_serial_number(OggFLAC__StreamEncoder *encoder, long serial_number);
251 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_verify()
254 * \param encoder An encoder instance to set.
255 * \param value Flag value (see above).
257 * \code encoder != NULL \endcode
259 * \c false if the encoder is already initialized, else \c true.
261 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_verify(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
263 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_streamable_subset()
266 * \param encoder An encoder instance to set.
267 * \param value Flag value (see above).
269 * \code encoder != NULL \endcode
271 * \c false if the encoder is already initialized, else \c true.
273 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_streamable_subset(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
275 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_mid_side_stereo()
278 * \param encoder An encoder instance to set.
279 * \param value Flag value (see above).
281 * \code encoder != NULL \endcode
283 * \c false if the encoder is already initialized, else \c true.
285 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_mid_side_stereo(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
287 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_loose_mid_side_stereo()
290 * \param encoder An encoder instance to set.
291 * \param value Flag value (see above).
293 * \code encoder != NULL \endcode
295 * \c false if the encoder is already initialized, else \c true.
297 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_loose_mid_side_stereo(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
299 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_channels()
302 * \param encoder An encoder instance to set.
303 * \param value See above.
305 * \code encoder != NULL \endcode
307 * \c false if the encoder is already initialized, else \c true.
309 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_channels(OggFLAC__StreamEncoder *encoder, unsigned value);
311 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_bits_per_sample()
314 * \param encoder An encoder instance to set.
315 * \param value See above.
317 * \code encoder != NULL \endcode
319 * \c false if the encoder is already initialized, else \c true.
321 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_bits_per_sample(OggFLAC__StreamEncoder *encoder, unsigned value);
323 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_sample_rate()
326 * \param encoder An encoder instance to set.
327 * \param value See above.
329 * \code encoder != NULL \endcode
331 * \c false if the encoder is already initialized, else \c true.
333 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_sample_rate(OggFLAC__StreamEncoder *encoder, unsigned value);
335 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_blocksize()
338 * \param encoder An encoder instance to set.
339 * \param value See above.
341 * \code encoder != NULL \endcode
343 * \c false if the encoder is already initialized, else \c true.
345 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_blocksize(OggFLAC__StreamEncoder *encoder, unsigned value);
347 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_apodization()
350 * \param encoder An encoder instance to set.
351 * \param specification See above.
353 * \code encoder != NULL \endcode
354 * \code specification != NULL \endcode
356 * \c false if the encoder is already initialized, else \c true.
358 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_apodization(OggFLAC__StreamEncoder *encoder, const char *specification);
360 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_max_lpc_order()
363 * \param encoder An encoder instance to set.
364 * \param value See above.
366 * \code encoder != NULL \endcode
368 * \c false if the encoder is already initialized, else \c true.
370 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_max_lpc_order(OggFLAC__StreamEncoder *encoder, unsigned value);
372 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_qlp_coeff_precision()
375 * \param encoder An encoder instance to set.
376 * \param value See above.
378 * \code encoder != NULL \endcode
380 * \c false if the encoder is already initialized, else \c true.
382 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_qlp_coeff_precision(OggFLAC__StreamEncoder *encoder, unsigned value);
384 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_qlp_coeff_prec_search()
387 * \param encoder An encoder instance to set.
388 * \param value See above.
390 * \code encoder != NULL \endcode
392 * \c false if the encoder is already initialized, else \c true.
394 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
396 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_escape_coding()
399 * \param encoder An encoder instance to set.
400 * \param value See above.
402 * \code encoder != NULL \endcode
404 * \c false if the encoder is already initialized, else \c true.
406 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_escape_coding(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
408 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_exhaustive_model_search()
411 * \param encoder An encoder instance to set.
412 * \param value See above.
414 * \code encoder != NULL \endcode
416 * \c false if the encoder is already initialized, else \c true.
418 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_exhaustive_model_search(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
420 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_min_residual_partition_order()
423 * \param encoder An encoder instance to set.
424 * \param value See above.
426 * \code encoder != NULL \endcode
428 * \c false if the encoder is already initialized, else \c true.
430 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_min_residual_partition_order(OggFLAC__StreamEncoder *encoder, unsigned value);
432 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_max_residual_partition_order()
435 * \param encoder An encoder instance to set.
436 * \param value See above.
438 * \code encoder != NULL \endcode
440 * \c false if the encoder is already initialized, else \c true.
442 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_max_residual_partition_order(OggFLAC__StreamEncoder *encoder, unsigned value);
444 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_rice_parameter_search_dist()
447 * \param encoder An encoder instance to set.
448 * \param value See above.
450 * \code encoder != NULL \endcode
452 * \c false if the encoder is already initialized, else \c true.
454 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_rice_parameter_search_dist(OggFLAC__StreamEncoder *encoder, unsigned value);
456 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_total_samples_estimate()
459 * \param encoder An encoder instance to set.
460 * \param value See above.
462 * \code encoder != NULL \endcode
464 * \c false if the encoder is already initialized, else \c true.
466 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_total_samples_estimate(OggFLAC__StreamEncoder *encoder, FLAC__uint64 value);
468 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_metadata()
470 * \note The Ogg FLAC mapping requires that the VORBIS_COMMENT block be
471 * the second metadata block of the stream. The encoder already supplies
472 * the STREAMINFO block automatically. If \a metadata does not contain a
473 * VORBIS_COMMENT block, the encoder will supply that too. Otherwise, if
474 * \a metadata does contain a VORBIS_COMMENT block and it is not the
475 * first, this function will reorder \a metadata by moving the
476 * VORBIS_COMMENT block to the front; the relative ordering of the other
477 * blocks will remain as they were.
479 * \note The Ogg FLAC mapping limits the number of metadata blocks per
480 * stream to \c 65535. If \a num_blocks exceeds this the function will
483 * \default \c NULL, 0
484 * \param encoder An encoder instance to set.
485 * \param metadata See above.
486 * \param num_blocks See above.
488 * \code encoder != NULL \endcode
490 * \c false if the encoder is already initialized, or if
491 * \a num_blocks > 65535, else \c true.
493 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_metadata(OggFLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
495 /** Get the current encoder state.
497 * \param encoder An encoder instance to query.
499 * \code encoder != NULL \endcode
500 * \retval OggFLAC__StreamEncoderState
501 * The current encoder state.
503 OggFLAC_API OggFLAC__StreamEncoderState OggFLAC__stream_encoder_get_state(const OggFLAC__StreamEncoder *encoder);
505 /** Get the state of the underlying FLAC stream encoder.
506 * Useful when the stream encoder state is
507 * \c OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR.
509 * \param encoder An encoder instance to query.
511 * \code encoder != NULL \endcode
512 * \retval FLAC__StreamEncoderState
513 * The FLAC stream encoder state.
515 OggFLAC_API FLAC__StreamEncoderState OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(const OggFLAC__StreamEncoder *encoder);
517 /** Get the state of the underlying FLAC stream encoder's verify decoder.
518 * Useful when the stream encoder state is
519 * \c OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR and the
520 * FLAC encoder state is \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR.
522 * \param encoder An encoder instance to query.
524 * \code encoder != NULL \endcode
525 * \retval FLAC__StreamDecoderState
526 * The FLAC verify decoder state.
528 OggFLAC_API FLAC__StreamDecoderState OggFLAC__stream_encoder_get_verify_decoder_state(const OggFLAC__StreamEncoder *encoder);
530 /** Get the current encoder state as a C string.
531 * This version automatically resolves
532 * \c OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR by getting the
533 * FLAC stream encoder's state.
535 * \param encoder A encoder instance to query.
537 * \code encoder != NULL \endcode
538 * \retval const char *
539 * The encoder state as a C string. Do not modify the contents.
541 OggFLAC_API const char *OggFLAC__stream_encoder_get_resolved_state_string(const OggFLAC__StreamEncoder *encoder);
543 /** Get relevant values about the nature of a verify decoder error.
544 * Inherited from FLAC__stream_encoder_get_verify_decoder_error_stats().
545 * Useful when the stream encoder state is
546 * \c OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR and the
547 * FLAC stream encoder state is
548 * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR.
550 * \param encoder An encoder instance to query.
551 * \param absolute_sample The absolute sample number of the mismatch.
552 * \param frame_number The number of the frame in which the mismatch occurred.
553 * \param channel The channel in which the mismatch occurred.
554 * \param sample The number of the sample (relative to the frame) in
555 * which the mismatch occurred.
556 * \param expected The expected value for the sample in question.
557 * \param got The actual value returned by the decoder.
559 * \code encoder != NULL \endcode
560 * \code absolute_sample != NULL \endcode
561 * \code frame_number != NULL \endcode
562 * \code channel != NULL \endcode
563 * \code sample != NULL \endcode
564 * \code expected != NULL \endcode
566 OggFLAC_API void OggFLAC__stream_encoder_get_verify_decoder_error_stats(const OggFLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
568 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_verify()
570 * \param encoder An encoder instance to query.
572 * \code encoder != NULL \endcode
574 * See OggFLAC__stream_encoder_set_verify().
576 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_verify(const OggFLAC__StreamEncoder *encoder);
578 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_streamable_subset()
580 * \param encoder An encoder instance to query.
582 * \code encoder != NULL \endcode
584 * See OggFLAC__stream_encoder_set_streamable_subset().
586 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_streamable_subset(const OggFLAC__StreamEncoder *encoder);
588 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_mid_side_stereo()
590 * \param encoder An encoder instance to query.
592 * \code encoder != NULL \endcode
594 * See OggFLAC__stream_encoder_get_do_mid_side_stereo().
596 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_mid_side_stereo(const OggFLAC__StreamEncoder *encoder);
598 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_loose_mid_side_stereo()
600 * \param encoder An encoder instance to query.
602 * \code encoder != NULL \endcode
604 * See OggFLAC__stream_encoder_set_loose_mid_side_stereo().
606 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_loose_mid_side_stereo(const OggFLAC__StreamEncoder *encoder);
608 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_channels()
610 * \param encoder An encoder instance to query.
612 * \code encoder != NULL \endcode
614 * See OggFLAC__stream_encoder_set_channels().
616 OggFLAC_API unsigned OggFLAC__stream_encoder_get_channels(const OggFLAC__StreamEncoder *encoder);
618 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_bits_per_sample()
620 * \param encoder An encoder instance to query.
622 * \code encoder != NULL \endcode
624 * See OggFLAC__stream_encoder_set_bits_per_sample().
626 OggFLAC_API unsigned OggFLAC__stream_encoder_get_bits_per_sample(const OggFLAC__StreamEncoder *encoder);
628 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_sample_rate()
630 * \param encoder An encoder instance to query.
632 * \code encoder != NULL \endcode
634 * See OggFLAC__stream_encoder_set_sample_rate().
636 OggFLAC_API unsigned OggFLAC__stream_encoder_get_sample_rate(const OggFLAC__StreamEncoder *encoder);
638 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_blocksize()
640 * \param encoder An encoder instance to query.
642 * \code encoder != NULL \endcode
644 * See OggFLAC__stream_encoder_set_blocksize().
646 OggFLAC_API unsigned OggFLAC__stream_encoder_get_blocksize(const OggFLAC__StreamEncoder *encoder);
648 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_max_lpc_order()
650 * \param encoder An encoder instance to query.
652 * \code encoder != NULL \endcode
654 * See OggFLAC__stream_encoder_set_max_lpc_order().
656 OggFLAC_API unsigned OggFLAC__stream_encoder_get_max_lpc_order(const OggFLAC__StreamEncoder *encoder);
658 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_qlp_coeff_precision()
660 * \param encoder An encoder instance to query.
662 * \code encoder != NULL \endcode
664 * See OggFLAC__stream_encoder_set_qlp_coeff_precision().
666 OggFLAC_API unsigned OggFLAC__stream_encoder_get_qlp_coeff_precision(const OggFLAC__StreamEncoder *encoder);
668 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_qlp_coeff_prec_search()
670 * \param encoder An encoder instance to query.
672 * \code encoder != NULL \endcode
674 * See OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search().
676 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search(const OggFLAC__StreamEncoder *encoder);
678 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_escape_coding()
680 * \param encoder An encoder instance to query.
682 * \code encoder != NULL \endcode
684 * See OggFLAC__stream_encoder_set_do_escape_coding().
686 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_escape_coding(const OggFLAC__StreamEncoder *encoder);
688 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_exhaustive_model_search()
690 * \param encoder An encoder instance to query.
692 * \code encoder != NULL \endcode
694 * See OggFLAC__stream_encoder_set_do_exhaustive_model_search().
696 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_exhaustive_model_search(const OggFLAC__StreamEncoder *encoder);
698 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_min_residual_partition_order()
700 * \param encoder An encoder instance to query.
702 * \code encoder != NULL \endcode
704 * See OggFLAC__stream_encoder_set_min_residual_partition_order().
706 OggFLAC_API unsigned OggFLAC__stream_encoder_get_min_residual_partition_order(const OggFLAC__StreamEncoder *encoder);
708 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_man_residual_partition_order()
710 * \param encoder An encoder instance to query.
712 * \code encoder != NULL \endcode
714 * See OggFLAC__stream_encoder_set_max_residual_partition_order().
716 OggFLAC_API unsigned OggFLAC__stream_encoder_get_max_residual_partition_order(const OggFLAC__StreamEncoder *encoder);
718 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_rice_parameter_search_dist()
720 * \param encoder An encoder instance to query.
722 * \code encoder != NULL \endcode
724 * See OggFLAC__stream_encoder_set_rice_parameter_search_dist().
726 OggFLAC_API unsigned OggFLAC__stream_encoder_get_rice_parameter_search_dist(const OggFLAC__StreamEncoder *encoder);
728 /** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_total_samples_estimate()
730 * \param encoder An encoder instance to set.
732 * \code encoder != NULL \endcode
733 * \retval FLAC__uint64
734 * See OggFLAC__stream_encoder_get_total_samples_estimate().
736 OggFLAC_API FLAC__uint64 OggFLAC__stream_encoder_get_total_samples_estimate(const OggFLAC__StreamEncoder *encoder);
738 /** Initialize the encoder instance.
739 * Should be called after OggFLAC__stream_encoder_new() and
740 * OggFLAC__stream_encoder_set_*() but before OggFLAC__stream_encoder_process()
741 * or OggFLAC__stream_encoder_process_interleaved(). Will set and return
742 * the encoder state, which will be OggFLAC__STREAM_ENCODER_OK if
743 * initialization succeeded.
745 * The call to OggFLAC__stream_encoder_init() currently will also immediately
746 * call the write callback several times, once with the \c fLaC signature,
747 * and once for each encoded metadata block.
749 * \param encoder An uninitialized encoder instance.
751 * \code encoder != NULL \endcode
752 * \retval OggFLAC__StreamEncoderState
753 * \c OggFLAC__STREAM_ENCODER_OK if initialization was successful; see
754 * OggFLAC__StreamEncoderState for the meanings of other return values.
756 OggFLAC_API OggFLAC__StreamEncoderState OggFLAC__stream_encoder_init(OggFLAC__StreamEncoder *encoder);
758 /** Initialize the encoder instance.
760 * This flavor of initialization sets up the encoder to encode to a stream.
761 * I/O is performed via callbacks to the client. For encoding to a plain file
762 * via filename or open \c FILE*, OggFLAC__stream_encoder_init_file() and
763 * OggFLAC__stream_encoder_init_FILE() provide a simpler interface.
765 * This function should be called after OggFLAC__stream_encoder_new() and
766 * OggFLAC__stream_encoder_set_*() but before OggFLAC__stream_encoder_process()
767 * or OggFLAC__stream_encoder_process_interleaved().
768 * initialization succeeded.
770 * The call to OggFLAC__stream_encoder_init_stream() currently will also immediately
771 * call the write callback several times, once with the \c fLaC signature,
772 * and once for each encoded metadata block.
775 * Unlike the FLAC stream encoder write callback, the Ogg stream
776 * encoder write callback will be called twice when writing each audio
777 * frame; once for the page header, and once for the page body.
778 * When writing the page header, the \a samples argument to the
779 * write callback will be \c 0.
781 * \param encoder An uninitialized encoder instance.
782 * \param read_callback See OggFLAC__StreamEncoderReadCallback. This
783 * pointer must not be \c NULL if \a seek_callback
784 * is non-NULL since they are both needed to be
785 * able to write data back to the Ogg FLAC stream
786 * in the post-encode phase.
787 * \param write_callback See FLAC__StreamEncoderWriteCallback. This
788 * pointer must not be \c NULL.
789 * \param seek_callback See FLAC__StreamEncoderSeekCallback. This
790 * pointer may be \c NULL if seeking is not
791 * supported. The encoder uses seeking to go back
792 * and write some some stream statistics to the
793 * STREAMINFO block; this is recommended but not
794 * necessary to create a valid FLAC stream. If
795 * \a seek_callback is not \c NULL then a
796 * \a tell_callback must also be supplied.
797 * Alternatively, a dummy seek callback that just
798 * returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
799 * may also be supplied, all though this is slightly
800 * less efficient for the decoder.
801 * \param tell_callback See FLAC__StreamEncoderTellCallback. This
802 * pointer may be \c NULL if seeking is not
803 * supported. If \a seek_callback is \c NULL then
804 * this argument will be ignored. If
805 * \a seek_callback is not \c NULL then a
806 * \a tell_callback must also be supplied.
807 * Alternatively, a dummy tell callback that just
808 * returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
809 * may also be supplied, all though this is slightly
810 * less efficient for the decoder.
811 * \param metadata_callback See FLAC__StreamEncoderMetadataCallback. This
812 * pointer may be \c NULL if the callback is not
813 * desired. If the client provides a seek callback,
814 * this function is not necessary as the encoder
815 * will automatically seek back and update the
816 * STREAMINFO block. It may also be \c NULL if the
817 * client does not support seeking, since it will
818 * have no way of going back to update the
819 * STREAMINFO. However the client can still supply
820 * a callback if it would like to know the details
821 * from the STREAMINFO.
822 * \param client_data This value will be supplied to callbacks in their
823 * \a client_data argument.
825 * \code encoder != NULL \endcode
826 * \retval FLAC__StreamEncoderInitStatus
827 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
828 * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
830 OggFLAC_API FLAC__StreamEncoderInitStatus OggFLAC__stream_encoder_init_stream(OggFLAC__StreamEncoder *encoder, OggFLAC__StreamEncoderReadCallback read_callback, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data);
832 /** Initialize the encoder instance.
834 * This flavor of initialization sets up the encoder to encode to a plain
835 * file. For non-stdio streams, you must use
836 * OggFLAC__stream_encoder_init_stream() and provide callbacks for the I/O.
838 * This function should be called after OggFLAC__stream_encoder_new() and
839 * OggFLAC__stream_encoder_set_*() but before OggFLAC__stream_encoder_process()
840 * or OggFLAC__stream_encoder_process_interleaved().
841 * initialization succeeded.
843 * The call to OggFLAC__stream_encoder_init_stream() currently will also immediately
844 * call the write callback several times, once with the \c fLaC signature,
845 * and once for each encoded metadata block.
848 * Unlike the FLAC stream encoder write callback, the Ogg stream
849 * encoder write callback will be called twice when writing each audio
850 * frame; once for the page header, and once for the page body.
851 * When writing the page header, the \a samples argument to the
852 * write callback will be \c 0.
854 * \param encoder An uninitialized encoder instance.
855 * \param file An open file. The file should have been opened
856 * with mode \c "w+b" and rewound. The file
857 * becomes owned by the encoder and should not be
858 * manipulated by the client while encoding.
859 * Unless \a file is \c stdout, it will be closed
860 * when OggFLAC__stream_encoder_finish() is called.
861 * Note however that a proper SEEKTABLE cannot be
862 * created when encoding to \c stdout since it is
864 * \param progress_callback See FLAC__StreamEncoderProgressCallback. This
865 * pointer may be \c NULL if the callback is not
867 * \param client_data This value will be supplied to callbacks in their
868 * \a client_data argument.
870 * \code encoder != NULL \endcode
871 * \code file != NULL \endcode
872 * \retval FLAC__StreamEncoderInitStatus
873 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
874 * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
876 OggFLAC_API FLAC__StreamEncoderInitStatus OggFLAC__stream_encoder_init_FILE(OggFLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
878 /** Initialize the encoder instance.
880 * This flavor of initialization sets up the encoder to encode to a plain
881 * file. If POSIX fopen() semantics are not sufficient (for example,
882 * with Unicode filenames on Windows), you must use
883 * OggFLAC__stream_encodeR_init_FILE(), or OggFLAC__stream_encoder_init_stream()
884 * and provide callbacks for the I/O.
886 * This function should be called after OggFLAC__stream_encoder_new() and
887 * OggFLAC__stream_encoder_set_*() but before OggFLAC__stream_encoder_process()
888 * or OggFLAC__stream_encoder_process_interleaved().
889 * initialization succeeded.
891 * The call to OggFLAC__stream_encoder_init_stream() currently will also immediately
892 * call the write callback several times, once with the \c fLaC signature,
893 * and once for each encoded metadata block.
896 * Unlike the FLAC stream encoder write callback, the Ogg stream
897 * encoder write callback will be called twice when writing each audio
898 * frame; once for the page header, and once for the page body.
899 * When writing the page header, the \a samples argument to the
900 * write callback will be \c 0.
902 * \param encoder An uninitialized encoder instance.
903 * \param filename The name of the file to encode to. The file will
904 * be opened with fopen(). Use \c NULL to encode to
905 * \c stdout. Note however that a proper SEEKTABLE
906 * cannot be created when encoding to \c stdout since
907 * it is not seekable.
908 * \param progress_callback See FLAC__StreamEncoderProgressCallback. This
909 * pointer may be \c NULL if the callback is not
911 * \param client_data This value will be supplied to callbacks in their
912 * \a client_data argument.
914 * \code encoder != NULL \endcode
915 * \retval FLAC__StreamEncoderInitStatus
916 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
917 * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
919 OggFLAC_API FLAC__StreamEncoderInitStatus OggFLAC__stream_encoder_init_file(OggFLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
921 /** Finish the encoding process.
922 * Flushes the encoding buffer, releases resources, resets the encoder
923 * settings to their defaults, and returns the encoder state to
924 * OggFLAC__STREAM_ENCODER_UNINITIALIZED. Note that this can generate
925 * one or more write callbacks before returning.
927 * In the event of a prematurely-terminated encode, it is not strictly
928 * necessary to call this immediately before OggFLAC__stream_encoder_delete()
929 * but it is good practice to match every OggFLAC__stream_encoder_init()
930 * with an OggFLAC__stream_encoder_finish().
932 * \param encoder An uninitialized encoder instance.
934 * \code encoder != NULL \endcode
936 OggFLAC_API void OggFLAC__stream_encoder_finish(OggFLAC__StreamEncoder *encoder);
938 /** Submit data for encoding.
939 * This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_process().
941 * \param encoder An initialized encoder instance in the OK state.
942 * \param buffer An array of pointers to each channel's signal.
943 * \param samples The number of samples in one channel.
945 * \code encoder != NULL \endcode
946 * \code OggFLAC__stream_encoder_get_state(encoder) == OggFLAC__STREAM_ENCODER_OK \endcode
948 * \c true if successful, else \c false; in this case, check the
949 * encoder state with OggFLAC__stream_encoder_get_state() to see what
952 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_process(OggFLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
954 /** Submit data for encoding.
955 * This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_process_interleaved().
957 * \param encoder An initialized encoder instance in the OK state.
958 * \param buffer An array of channel-interleaved data (see above).
959 * \param samples The number of samples in one channel, the same as for
960 * OggFLAC__stream_encoder_process(). For example, if
961 * encoding two channels, \c 1000 \a samples corresponds
962 * to a \a buffer of 2000 values.
964 * \code encoder != NULL \endcode
965 * \code OggFLAC__stream_encoder_get_state(encoder) == OggFLAC__STREAM_ENCODER_OK \endcode
967 * \c true if successful, else \c false; in this case, check the
968 * encoder state with OggFLAC__stream_encoder_get_state() to see what
971 OggFLAC_API FLAC__bool OggFLAC__stream_encoder_process_interleaved(OggFLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);