1 /* libFLAC - Free Lossless Audio Codec library 2 * Copyright (C) 2000-2009 Josh Coalson 3 * Copyright (C) 2011-2013 Xiph.Org Foundation 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * - Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * - Neither the name of the Xiph.org Foundation nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 module deimos.flac.stream_encoder; 34 35 import deimos.flac.export_; 36 import deimos.flac.format; 37 import deimos.flac.ordinals; 38 import deimos.flac.stream_decoder; 39 40 import core.stdc.stdio; 41 42 version(Posix) {} 43 else version(Windows) {} 44 else static assert(0, "Unsupported OS."); 45 46 extern(C): 47 nothrow: 48 49 50 /** \file include/FLAC/stream_encoder.h 51 * 52 * \brief 53 * This module contains the functions which implement the stream 54 * encoder. 55 * 56 * See the detailed documentation in the 57 * \link flac_stream_encoder stream encoder \endlink module. 58 */ 59 60 /** \defgroup flac_encoder FLAC/ \*_encoder.h: encoder interfaces 61 * \ingroup flac 62 * 63 * \brief 64 * This module describes the encoder layers provided by libFLAC. 65 * 66 * The stream encoder can be used to encode complete streams either to the 67 * client via callbacks, or directly to a file, depending on how it is 68 * initialized. When encoding via callbacks, the client provides a write 69 * callback which will be called whenever FLAC data is ready to be written. 70 * If the client also supplies a seek callback, the encoder will also 71 * automatically handle the writing back of metadata discovered while 72 * encoding, like stream info, seek points offsets, etc. When encoding to 73 * a file, the client needs only supply a filename or open \c FILE* and an 74 * optional progress callback for periodic notification of progress; the 75 * write and seek callbacks are supplied internally. For more info see the 76 * \link flac_stream_encoder stream encoder \endlink module. 77 */ 78 79 /** \defgroup flac_stream_encoder FLAC/stream_encoder.h: stream encoder interface 80 * \ingroup flac_encoder 81 * 82 * \brief 83 * This module contains the functions which implement the stream 84 * encoder. 85 * 86 * The stream encoder can encode to native FLAC, and optionally Ogg FLAC 87 * (check FLAC_API_SUPPORTS_OGG_FLAC) streams and files. 88 * 89 * The basic usage of this encoder is as follows: 90 * - The program creates an instance of an encoder using 91 * FLAC__stream_encoder_new(). 92 * - The program overrides the default settings using 93 * FLAC__stream_encoder_set_*() functions. At a minimum, the following 94 * functions should be called: 95 * - FLAC__stream_encoder_set_channels() 96 * - FLAC__stream_encoder_set_bits_per_sample() 97 * - FLAC__stream_encoder_set_sample_rate() 98 * - FLAC__stream_encoder_set_ogg_serial_number() (if encoding to Ogg FLAC) 99 * - FLAC__stream_encoder_set_total_samples_estimate() (if known) 100 * - If the application wants to control the compression level or set its own 101 * metadata, then the following should also be called: 102 * - FLAC__stream_encoder_set_compression_level() 103 * - FLAC__stream_encoder_set_verify() 104 * - FLAC__stream_encoder_set_metadata() 105 * - The rest of the set functions should only be called if the client needs 106 * exact control over how the audio is compressed; thorough understanding 107 * of the FLAC format is necessary to achieve good results. 108 * - The program initializes the instance to validate the settings and 109 * prepare for encoding using 110 * - FLAC__stream_encoder_init_stream() or FLAC__stream_encoder_init_FILE() 111 * or FLAC__stream_encoder_init_file() for native FLAC 112 * - FLAC__stream_encoder_init_ogg_stream() or FLAC__stream_encoder_init_ogg_FILE() 113 * or FLAC__stream_encoder_init_ogg_file() for Ogg FLAC 114 * - The program calls FLAC__stream_encoder_process() or 115 * FLAC__stream_encoder_process_interleaved() to encode data, which 116 * subsequently calls the callbacks when there is encoder data ready 117 * to be written. 118 * - The program finishes the encoding with FLAC__stream_encoder_finish(), 119 * which causes the encoder to encode any data still in its input pipe, 120 * update the metadata with the final encoding statistics if output 121 * seeking is possible, and finally reset the encoder to the 122 * uninitialized state. 123 * - The instance may be used again or deleted with 124 * FLAC__stream_encoder_delete(). 125 * 126 * In more detail, the stream encoder functions similarly to the 127 * \link flac_stream_decoder stream decoder \endlink, but has fewer 128 * callbacks and more options. Typically the client will create a new 129 * instance by calling FLAC__stream_encoder_new(), then set the necessary 130 * parameters with FLAC__stream_encoder_set_*(), and initialize it by 131 * calling one of the FLAC__stream_encoder_init_*() functions. 132 * 133 * Unlike the decoders, the stream encoder has many options that can 134 * affect the speed and compression ratio. When setting these parameters 135 * you should have some basic knowledge of the format (see the 136 * <A HREF="../documentation_format_overview.html">user-level documentation</A> 137 * or the <A HREF="../format.html">formal description</A>). The 138 * FLAC__stream_encoder_set_*() functions themselves do not validate the 139 * values as many are interdependent. The FLAC__stream_encoder_init_*() 140 * functions will do this, so make sure to pay attention to the state 141 * returned by FLAC__stream_encoder_init_*() to make sure that it is 142 * FLAC__STREAM_ENCODER_INIT_STATUS_OK. Any parameters that are not set 143 * before FLAC__stream_encoder_init_*() will take on the defaults from 144 * the constructor. 145 * 146 * There are three initialization functions for native FLAC, one for 147 * setting up the encoder to encode FLAC data to the client via 148 * callbacks, and two for encoding directly to a file. 149 * 150 * For encoding via callbacks, use FLAC__stream_encoder_init_stream(). 151 * You must also supply a write callback which will be called anytime 152 * there is raw encoded data to write. If the client can seek the output 153 * it is best to also supply seek and tell callbacks, as this allows the 154 * encoder to go back after encoding is finished to write back 155 * information that was collected while encoding, like seek point offsets, 156 * frame sizes, etc. 157 * 158 * For encoding directly to a file, use FLAC__stream_encoder_init_FILE() 159 * or FLAC__stream_encoder_init_file(). Then you must only supply a 160 * filename or open \c FILE*; the encoder will handle all the callbacks 161 * internally. You may also supply a progress callback for periodic 162 * notification of the encoding progress. 163 * 164 * There are three similarly-named init functions for encoding to Ogg 165 * FLAC streams. Check \c FLAC_API_SUPPORTS_OGG_FLAC to find out if the 166 * library has been built with Ogg support. 167 * 168 * The call to FLAC__stream_encoder_init_*() currently will also immediately 169 * call the write callback several times, once with the \c fLaC signature, 170 * and once for each encoded metadata block. Note that for Ogg FLAC 171 * encoding you will usually get at least twice the number of callbacks than 172 * with native FLAC, one for the Ogg page header and one for the page body. 173 * 174 * After initializing the instance, the client may feed audio data to the 175 * encoder in one of two ways: 176 * 177 * - Channel separate, through FLAC__stream_encoder_process() - The client 178 * will pass an array of pointers to buffers, one for each channel, to 179 * the encoder, each of the same length. The samples need not be 180 * block-aligned, but each channel should have the same number of samples. 181 * - Channel interleaved, through 182 * FLAC__stream_encoder_process_interleaved() - The client will pass a single 183 * pointer to data that is channel-interleaved (i.e. channel0_sample0, 184 * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...). 185 * Again, the samples need not be block-aligned but they must be 186 * sample-aligned, i.e. the first value should be channel0_sample0 and 187 * the last value channelN_sampleM. 188 * 189 * Note that for either process call, each sample in the buffers should be a 190 * signed integer, right-justified to the resolution set by 191 * FLAC__stream_encoder_set_bits_per_sample(). For example, if the resolution 192 * is 16 bits per sample, the samples should all be in the range [-32768,32767]. 193 * 194 * When the client is finished encoding data, it calls 195 * FLAC__stream_encoder_finish(), which causes the encoder to encode any 196 * data still in its input pipe, and call the metadata callback with the 197 * final encoding statistics. Then the instance may be deleted with 198 * FLAC__stream_encoder_delete() or initialized again to encode another 199 * stream. 200 * 201 * For programs that write their own metadata, but that do not know the 202 * actual metadata until after encoding, it is advantageous to instruct 203 * the encoder to write a PADDING block of the correct size, so that 204 * instead of rewriting the whole stream after encoding, the program can 205 * just overwrite the PADDING block. If only the maximum size of the 206 * metadata is known, the program can write a slightly larger padding 207 * block, then split it after encoding. 208 * 209 * Make sure you understand how lengths are calculated. All FLAC metadata 210 * blocks have a 4 byte header which contains the type and length. This 211 * length does not include the 4 bytes of the header. See the format page 212 * for the specification of metadata blocks and their lengths. 213 * 214 * \note 215 * If you are writing the FLAC data to a file via callbacks, make sure it 216 * is open for update (e.g. mode "w+" for stdio streams). This is because 217 * after the first encoding pass, the encoder will try to seek back to the 218 * beginning of the stream, to the STREAMINFO block, to write some data 219 * there. (If using FLAC__stream_encoder_init*_file() or 220 * FLAC__stream_encoder_init*_FILE(), the file is managed internally.) 221 * 222 * \note 223 * The "set" functions may only be called when the encoder is in the 224 * state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after 225 * FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but 226 * before FLAC__stream_encoder_init_*(). If this is the case they will 227 * return \c true, otherwise \c false. 228 * 229 * \note 230 * FLAC__stream_encoder_finish() resets all settings to the constructor 231 * defaults. 232 * 233 * \{ 234 */ 235 236 237 /** State values for a FLAC__StreamEncoder. 238 * 239 * The encoder's state can be obtained by calling FLAC__stream_encoder_get_state(). 240 * 241 * If the encoder gets into any other state besides \c FLAC__STREAM_ENCODER_OK 242 * or \c FLAC__STREAM_ENCODER_UNINITIALIZED, it becomes invalid for encoding and 243 * must be deleted with FLAC__stream_encoder_delete(). 244 */ 245 enum FLAC__StreamEncoderState 246 { 247 FLAC__STREAM_ENCODER_OK = 0, 248 /**< The encoder is in the normal OK state and samples can be processed. */ 249 250 FLAC__STREAM_ENCODER_UNINITIALIZED, 251 /**< The encoder is in the uninitialized state; one of the 252 * FLAC__stream_encoder_init_*() functions must be called before samples 253 * can be processed. 254 */ 255 256 FLAC__STREAM_ENCODER_OGG_ERROR, 257 /**< An error occurred in the underlying Ogg layer. */ 258 259 FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR, 260 /**< An error occurred in the underlying verify stream decoder; 261 * check FLAC__stream_encoder_get_verify_decoder_state(). 262 */ 263 264 FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA, 265 /**< The verify decoder detected a mismatch between the original 266 * audio signal and the decoded audio signal. 267 */ 268 269 FLAC__STREAM_ENCODER_CLIENT_ERROR, 270 /**< One of the callbacks returned a fatal error. */ 271 272 FLAC__STREAM_ENCODER_IO_ERROR, 273 /**< An I/O error occurred while opening/reading/writing a file. 274 * Check \c errno. 275 */ 276 277 FLAC__STREAM_ENCODER_FRAMING_ERROR, 278 /**< An error occurred while writing the stream; usually, the 279 * write_callback returned an error. 280 */ 281 282 FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR 283 /**< Memory allocation failed. */ 284 } 285 286 /** Maps a FLAC__StreamEncoderState to a C string. 287 * 288 * Using a FLAC__StreamEncoderState as the index to this array 289 * will give the string equivalent. The contents should not be modified. 290 */ 291 extern __gshared const char** FLAC__StreamEncoderStateString; 292 293 294 /** Possible return values for the FLAC__stream_encoder_init_*() functions. 295 */ 296 enum FLAC__StreamEncoderInitStatus 297 { 298 FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0, 299 /**< Initialization was successful. */ 300 301 FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR, 302 /**< General failure to set up encoder; call FLAC__stream_encoder_get_state() for cause. */ 303 304 FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER, 305 /**< The library was not compiled with support for the given container 306 * format. 307 */ 308 309 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS, 310 /**< A required callback was not supplied. */ 311 312 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS, 313 /**< The encoder has an invalid setting for number of channels. */ 314 315 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE, 316 /**< The encoder has an invalid setting for bits-per-sample. 317 * FLAC supports 4-32 bps but the reference encoder currently supports 318 * only up to 24 bps. 319 */ 320 321 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE, 322 /**< The encoder has an invalid setting for the input sample rate. */ 323 324 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE, 325 /**< The encoder has an invalid setting for the block size. */ 326 327 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER, 328 /**< The encoder has an invalid setting for the maximum LPC order. */ 329 330 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION, 331 /**< The encoder has an invalid setting for the precision of the quantized linear predictor coefficients. */ 332 333 FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER, 334 /**< The specified block size is less than the maximum LPC order. */ 335 336 FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE, 337 /**< The encoder is bound to the <A HREF="../format.html#subset">Subset</A> but other settings violate it. */ 338 339 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA, 340 /**< The metadata input to the encoder is invalid, in one of the following ways: 341 * - FLAC__stream_encoder_set_metadata() was called with a null pointer but a block count > 0 342 * - One of the metadata blocks contains an undefined type 343 * - It contains an illegal CUESHEET as checked by FLAC__format_cuesheet_is_legal() 344 * - It contains an illegal SEEKTABLE as checked by FLAC__format_seektable_is_legal() 345 * - It contains more than one SEEKTABLE block or more than one VORBIS_COMMENT block 346 */ 347 348 FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED 349 /**< FLAC__stream_encoder_init_*() was called when the encoder was 350 * already initialized, usually because 351 * FLAC__stream_encoder_finish() was not called. 352 */ 353 } 354 355 /** Maps a FLAC__StreamEncoderInitStatus to a C string. 356 * 357 * Using a FLAC__StreamEncoderInitStatus as the index to this array 358 * will give the string equivalent. The contents should not be modified. 359 */ 360 extern __gshared const char** FLAC__StreamEncoderInitStatusString; 361 362 363 /** Return values for the FLAC__StreamEncoder read callback. 364 */ 365 enum FLAC__StreamEncoderReadStatus 366 { 367 FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE, 368 /**< The read was OK and decoding can continue. */ 369 370 FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM, 371 /**< The read was attempted at the end of the stream. */ 372 373 FLAC__STREAM_ENCODER_READ_STATUS_ABORT, 374 /**< An unrecoverable error occurred. */ 375 376 FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED 377 /**< Client does not support reading back from the output. */ 378 } 379 380 /** Maps a FLAC__StreamEncoderReadStatus to a C string. 381 * 382 * Using a FLAC__StreamEncoderReadStatus as the index to this array 383 * will give the string equivalent. The contents should not be modified. 384 */ 385 extern __gshared const char** FLAC__StreamEncoderReadStatusString; 386 387 388 /** Return values for the FLAC__StreamEncoder write callback. 389 */ 390 enum FLAC__StreamEncoderWriteStatus 391 { 392 FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0, 393 /**< The write was OK and encoding can continue. */ 394 395 FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR 396 /**< An unrecoverable error occurred. The encoder will return from the process call. */ 397 } 398 399 /** Maps a FLAC__StreamEncoderWriteStatus to a C string. 400 * 401 * Using a FLAC__StreamEncoderWriteStatus as the index to this array 402 * will give the string equivalent. The contents should not be modified. 403 */ 404 extern __gshared const char** FLAC__StreamEncoderWriteStatusString; 405 406 407 /** Return values for the FLAC__StreamEncoder seek callback. 408 */ 409 enum FLAC__StreamEncoderSeekStatus 410 { 411 FLAC__STREAM_ENCODER_SEEK_STATUS_OK, 412 /**< The seek was OK and encoding can continue. */ 413 414 FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR, 415 /**< An unrecoverable error occurred. */ 416 417 FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED 418 /**< Client does not support seeking. */ 419 } 420 421 /** Maps a FLAC__StreamEncoderSeekStatus to a C string. 422 * 423 * Using a FLAC__StreamEncoderSeekStatus as the index to this array 424 * will give the string equivalent. The contents should not be modified. 425 */ 426 extern __gshared const char** FLAC__StreamEncoderSeekStatusString; 427 428 429 /** Return values for the FLAC__StreamEncoder tell callback. 430 */ 431 enum FLAC__StreamEncoderTellStatus 432 { 433 FLAC__STREAM_ENCODER_TELL_STATUS_OK, 434 /**< The tell was OK and encoding can continue. */ 435 436 FLAC__STREAM_ENCODER_TELL_STATUS_ERROR, 437 /**< An unrecoverable error occurred. */ 438 439 FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED 440 /**< Client does not support seeking. */ 441 } 442 443 /** Maps a FLAC__StreamEncoderTellStatus to a C string. 444 * 445 * Using a FLAC__StreamEncoderTellStatus as the index to this array 446 * will give the string equivalent. The contents should not be modified. 447 */ 448 extern __gshared char** FLAC__StreamEncoderTellStatusString; 449 450 451 /*********************************************************************** 452 * 453 * class FLAC__StreamEncoder 454 * 455 ***********************************************************************/ 456 457 extern struct FLAC__StreamEncoderProtected; 458 extern struct FLAC__StreamEncoderPrivate; 459 /** The opaque structure definition for the stream encoder type. 460 * See the \link flac_stream_encoder stream encoder module \endlink 461 * for a detailed description. 462 */ 463 struct FLAC__StreamEncoder 464 { 465 FLAC__StreamEncoderProtected* protected_; /* avoid the C++ keyword 'protected' */ 466 FLAC__StreamEncoderPrivate* private_; /* avoid the C++ keyword 'private' */ 467 } 468 469 /** Signature for the read callback. 470 * 471 * A function pointer matching this signature must be passed to 472 * FLAC__stream_encoder_init_ogg_stream() if seeking is supported. 473 * The supplied function will be called when the encoder needs to read back 474 * encoded data. This happens during the metadata callback, when the encoder 475 * has to read, modify, and rewrite the metadata (e.g. seekpoints) gathered 476 * while encoding. The address of the buffer to be filled is supplied, along 477 * with the number of bytes the buffer can hold. The callback may choose to 478 * supply less data and modify the byte count but must be careful not to 479 * overflow the buffer. The callback then returns a status code chosen from 480 * FLAC__StreamEncoderReadStatus. 481 * 482 * Here is an example of a read callback for stdio streams: 483 * \code 484 * FLAC__StreamEncoderReadStatus read_cb(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data) 485 * { 486 * FILE *file = ((MyClientData*)client_data)->file; 487 * if(*bytes > 0) { 488 * *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, file); 489 * if(ferror(file)) 490 * return FLAC__STREAM_ENCODER_READ_STATUS_ABORT; 491 * else if(*bytes == 0) 492 * return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM; 493 * else 494 * return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE; 495 * } 496 * else 497 * return FLAC__STREAM_ENCODER_READ_STATUS_ABORT; 498 * } 499 * \endcode 500 * 501 * \note In general, FLAC__StreamEncoder functions which change the 502 * state should not be called on the \a encoder while in the callback. 503 * 504 * \param encoder The encoder instance calling the callback. 505 * \param buffer A pointer to a location for the callee to store 506 * data to be encoded. 507 * \param bytes A pointer to the size of the buffer. On entry 508 * to the callback, it contains the maximum number 509 * of bytes that may be stored in \a buffer. The 510 * callee must set it to the actual number of bytes 511 * stored (0 in case of error or end-of-stream) before 512 * returning. 513 * \param client_data The callee's client data set through 514 * FLAC__stream_encoder_set_client_data(). 515 * \retval FLAC__StreamEncoderReadStatus 516 * The callee's return status. 517 */ 518 alias FLAC__StreamEncoderReadStatus function(const FLAC__StreamEncoder* encoder, FLAC__byte* buffer, size_t* bytes, void* client_data) FLAC__StreamEncoderReadCallback; 519 520 /** Signature for the write callback. 521 * 522 * A function pointer matching this signature must be passed to 523 * FLAC__stream_encoder_init*_stream(). The supplied function will be called 524 * by the encoder anytime there is raw encoded data ready to write. It may 525 * include metadata mixed with encoded audio frames and the data is not 526 * guaranteed to be aligned on frame or metadata block boundaries. 527 * 528 * The only duty of the callback is to write out the \a bytes worth of data 529 * in \a buffer to the current position in the output stream. The arguments 530 * \a samples and \a current_frame are purely informational. If \a samples 531 * is greater than \c 0, then \a current_frame will hold the current frame 532 * number that is being written; otherwise it indicates that the write 533 * callback is being called to write metadata. 534 * 535 * \note 536 * Unlike when writing to native FLAC, when writing to Ogg FLAC the 537 * write callback will be called twice when writing each audio 538 * frame; once for the page header, and once for the page body. 539 * When writing the page header, the \a samples argument to the 540 * write callback will be \c 0. 541 * 542 * \note In general, FLAC__StreamEncoder functions which change the 543 * state should not be called on the \a encoder while in the callback. 544 * 545 * \param encoder The encoder instance calling the callback. 546 * \param buffer An array of encoded data of length \a bytes. 547 * \param bytes The byte length of \a buffer. 548 * \param samples The number of samples encoded by \a buffer. 549 * \c 0 has a special meaning; see above. 550 * \param current_frame The number of the current frame being encoded. 551 * \param client_data The callee's client data set through 552 * FLAC__stream_encoder_init_*(). 553 * \retval FLAC__StreamEncoderWriteStatus 554 * The callee's return status. 555 */ 556 alias FLAC__StreamEncoderWriteStatus function(const FLAC__StreamEncoder* encoder, const FLAC__byte* buffer, size_t bytes, uint samples, uint current_frame, void* client_data) FLAC__StreamEncoderWriteCallback; 557 558 /** Signature for the seek callback. 559 * 560 * A function pointer matching this signature may be passed to 561 * FLAC__stream_encoder_init*_stream(). The supplied function will be called 562 * when the encoder needs to seek the output stream. The encoder will pass 563 * the absolute byte offset to seek to, 0 meaning the beginning of the stream. 564 * 565 * Here is an example of a seek callback for stdio streams: 566 * \code 567 * FLAC__StreamEncoderSeekStatus seek_cb(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) 568 * { 569 * FILE *file = ((MyClientData*)client_data)->file; 570 * if(file == stdin) 571 * return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED; 572 * else if(fseeko(file, (off_t)absolute_byte_offset, SEEK_SET) < 0) 573 * return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR; 574 * else 575 * return FLAC__STREAM_ENCODER_SEEK_STATUS_OK; 576 * } 577 * \endcode 578 * 579 * \note In general, FLAC__StreamEncoder functions which change the 580 * state should not be called on the \a encoder while in the callback. 581 * 582 * \param encoder The encoder instance calling the callback. 583 * \param absolute_byte_offset The offset from the beginning of the stream 584 * to seek to. 585 * \param client_data The callee's client data set through 586 * FLAC__stream_encoder_init_*(). 587 * \retval FLAC__StreamEncoderSeekStatus 588 * The callee's return status. 589 */ 590 alias FLAC__StreamEncoderSeekStatus function(const FLAC__StreamEncoder* encoder, FLAC__uint64 absolute_byte_offset, void* client_data) FLAC__StreamEncoderSeekCallback; 591 592 /** Signature for the tell callback. 593 * 594 * A function pointer matching this signature may be passed to 595 * FLAC__stream_encoder_init*_stream(). The supplied function will be called 596 * when the encoder needs to know the current position of the output stream. 597 * 598 * \warning 599 * The callback must return the true current byte offset of the output to 600 * which the encoder is writing. If you are buffering the output, make 601 * sure and take this into account. If you are writing directly to a 602 * FILE* from your write callback, ftell() is sufficient. If you are 603 * writing directly to a file descriptor from your write callback, you 604 * can use lseek(fd, SEEK_CUR, 0). The encoder may later seek back to 605 * these points to rewrite metadata after encoding. 606 * 607 * Here is an example of a tell callback for stdio streams: 608 * \code 609 * FLAC__StreamEncoderTellStatus tell_cb(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data) 610 * { 611 * FILE *file = ((MyClientData*)client_data)->file; 612 * off_t pos; 613 * if(file == stdin) 614 * return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED; 615 * else if((pos = ftello(file)) < 0) 616 * return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR; 617 * else { 618 * *absolute_byte_offset = (FLAC__uint64)pos; 619 * return FLAC__STREAM_ENCODER_TELL_STATUS_OK; 620 * } 621 * } 622 * \endcode 623 * 624 * \note In general, FLAC__StreamEncoder functions which change the 625 * state should not be called on the \a encoder while in the callback. 626 * 627 * \param encoder The encoder instance calling the callback. 628 * \param absolute_byte_offset The address at which to store the current 629 * position of the output. 630 * \param client_data The callee's client data set through 631 * FLAC__stream_encoder_init_*(). 632 * \retval FLAC__StreamEncoderTellStatus 633 * The callee's return status. 634 */ 635 alias FLAC__StreamEncoderTellStatus function(const FLAC__StreamEncoder* encoder, FLAC__uint64* absolute_byte_offset, void* client_data) FLAC__StreamEncoderTellCallback; 636 637 /** Signature for the metadata callback. 638 * 639 * A function pointer matching this signature may be passed to 640 * FLAC__stream_encoder_init*_stream(). The supplied function will be called 641 * once at the end of encoding with the populated STREAMINFO structure. This 642 * is so the client can seek back to the beginning of the file and write the 643 * STREAMINFO block with the correct statistics after encoding (like 644 * minimum/maximum frame size and total samples). 645 * 646 * \note In general, FLAC__StreamEncoder functions which change the 647 * state should not be called on the \a encoder while in the callback. 648 * 649 * \param encoder The encoder instance calling the callback. 650 * \param metadata The final populated STREAMINFO block. 651 * \param client_data The callee's client data set through 652 * FLAC__stream_encoder_init_*(). 653 */ 654 alias void function(const FLAC__StreamEncoder* encoder, const FLAC__StreamMetadata* metadata, void* client_data) FLAC__StreamEncoderMetadataCallback; 655 656 /** Signature for the progress callback. 657 * 658 * A function pointer matching this signature may be passed to 659 * FLAC__stream_encoder_init*_file() or FLAC__stream_encoder_init*_FILE(). 660 * The supplied function will be called when the encoder has finished 661 * writing a frame. The \c total_frames_estimate argument to the 662 * callback will be based on the value from 663 * FLAC__stream_encoder_set_total_samples_estimate(). 664 * 665 * \note In general, FLAC__StreamEncoder functions which change the 666 * state should not be called on the \a encoder while in the callback. 667 * 668 * \param encoder The encoder instance calling the callback. 669 * \param bytes_written Bytes written so far. 670 * \param samples_written Samples written so far. 671 * \param frames_written Frames written so far. 672 * \param total_frames_estimate The estimate of the total number of 673 * frames to be written. 674 * \param client_data The callee's client data set through 675 * FLAC__stream_encoder_init_*(). 676 */ 677 alias void function(const FLAC__StreamEncoder* encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint frames_written, uint total_frames_estimate, void* client_data) FLAC__StreamEncoderProgressCallback; 678 679 680 /*********************************************************************** 681 * 682 * Class constructor/destructor 683 * 684 ***********************************************************************/ 685 686 /** Create a new stream encoder instance. The instance is created with 687 * default settings; see the individual FLAC__stream_encoder_set_*() 688 * functions for each setting's default. 689 * 690 * \retval FLAC__StreamEncoder* 691 * \c NULL if there was an error allocating memory, else the new instance. 692 */ 693 FLAC__StreamEncoder* FLAC__stream_encoder_new(); 694 695 /** Free an encoder instance. Deletes the object pointed to by \a encoder. 696 * 697 * \param encoder A pointer to an existing encoder. 698 * \assert 699 * \code encoder != NULL \endcode 700 */ 701 void FLAC__stream_encoder_delete(FLAC__StreamEncoder* encoder); 702 703 704 /*********************************************************************** 705 * 706 * Public class method prototypes 707 * 708 ***********************************************************************/ 709 710 /** Set the serial number for the FLAC stream to use in the Ogg container. 711 * 712 * \note 713 * This does not need to be set for native FLAC encoding. 714 * 715 * \note 716 * It is recommended to set a serial number explicitly as the default of '0' 717 * may collide with other streams. 718 * 719 * \default \c 0 720 * \param encoder An encoder instance to set. 721 * \param serial_number See above. 722 * \assert 723 * \code encoder != NULL \endcode 724 * \retval FLAC__bool 725 * \c false if the encoder is already initialized, else \c true. 726 */ 727 FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder* encoder, long serial_number); 728 729 /** Set the "verify" flag. If \c true, the encoder will verify it's own 730 * encoded output by feeding it through an internal decoder and comparing 731 * the original signal against the decoded signal. If a mismatch occurs, 732 * the process call will return \c false. Note that this will slow the 733 * encoding process by the extra time required for decoding and comparison. 734 * 735 * \default \c false 736 * \param encoder An encoder instance to set. 737 * \param value Flag value (see above). 738 * \assert 739 * \code encoder != NULL \endcode 740 * \retval FLAC__bool 741 * \c false if the encoder is already initialized, else \c true. 742 */ 743 FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder* encoder, FLAC__bool value); 744 745 /** Set the <A HREF="../format.html#subset">Subset</A> flag. If \c true, 746 * the encoder will comply with the Subset and will check the 747 * settings during FLAC__stream_encoder_init_*() to see if all settings 748 * comply. If \c false, the settings may take advantage of the full 749 * range that the format allows. 750 * 751 * Make sure you know what it entails before setting this to \c false. 752 * 753 * \default \c true 754 * \param encoder An encoder instance to set. 755 * \param value Flag value (see above). 756 * \assert 757 * \code encoder != NULL \endcode 758 * \retval FLAC__bool 759 * \c false if the encoder is already initialized, else \c true. 760 */ 761 FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder* encoder, FLAC__bool value); 762 763 /** Set the number of channels to be encoded. 764 * 765 * \default \c 2 766 * \param encoder An encoder instance to set. 767 * \param value See above. 768 * \assert 769 * \code encoder != NULL \endcode 770 * \retval FLAC__bool 771 * \c false if the encoder is already initialized, else \c true. 772 */ 773 FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder* encoder, uint value); 774 775 /** Set the sample resolution of the input to be encoded. 776 * 777 * \warning 778 * Do not feed the encoder data that is wider than the value you 779 * set here or you will generate an invalid stream. 780 * 781 * \default \c 16 782 * \param encoder An encoder instance to set. 783 * \param value See above. 784 * \assert 785 * \code encoder != NULL \endcode 786 * \retval FLAC__bool 787 * \c false if the encoder is already initialized, else \c true. 788 */ 789 FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder* encoder, uint value); 790 791 /** Set the sample rate (in Hz) of the input to be encoded. 792 * 793 * \default \c 44100 794 * \param encoder An encoder instance to set. 795 * \param value See above. 796 * \assert 797 * \code encoder != NULL \endcode 798 * \retval FLAC__bool 799 * \c false if the encoder is already initialized, else \c true. 800 */ 801 FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder* encoder, uint value); 802 803 /** Set the compression level 804 * 805 * The compression level is roughly proportional to the amount of effort 806 * the encoder expends to compress the file. A higher level usually 807 * means more computation but higher compression. The default level is 808 * suitable for most applications. 809 * 810 * Currently the levels range from \c 0 (fastest, least compression) to 811 * \c 8 (slowest, most compression). A value larger than \c 8 will be 812 * treated as \c 8. 813 * 814 * This function automatically calls the following other \c _set_ 815 * functions with appropriate values, so the client does not need to 816 * unless it specifically wants to override them: 817 * - FLAC__stream_encoder_set_do_mid_side_stereo() 818 * - FLAC__stream_encoder_set_loose_mid_side_stereo() 819 * - FLAC__stream_encoder_set_apodization() 820 * - FLAC__stream_encoder_set_max_lpc_order() 821 * - FLAC__stream_encoder_set_qlp_coeff_precision() 822 * - FLAC__stream_encoder_set_do_qlp_coeff_prec_search() 823 * - FLAC__stream_encoder_set_do_escape_coding() 824 * - FLAC__stream_encoder_set_do_exhaustive_model_search() 825 * - FLAC__stream_encoder_set_min_residual_partition_order() 826 * - FLAC__stream_encoder_set_max_residual_partition_order() 827 * - FLAC__stream_encoder_set_rice_parameter_search_dist() 828 * 829 * The actual values set for each level are: 830 * <table> 831 * <tr> 832 * <td><b>level</b><td> 833 * <td>do mid-side stereo<td> 834 * <td>loose mid-side stereo<td> 835 * <td>apodization<td> 836 * <td>max lpc order<td> 837 * <td>qlp coeff precision<td> 838 * <td>qlp coeff prec search<td> 839 * <td>escape coding<td> 840 * <td>exhaustive model search<td> 841 * <td>min residual partition order<td> 842 * <td>max residual partition order<td> 843 * <td>rice parameter search dist<td> 844 * </tr> 845 * <tr> <td><b>0</b><td> <td>false<td> <td>false<td> <td>tukey(0.5)<td> <td>0<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>0<td> <td>3<td> <td>0<td> </tr> 846 * <tr> <td><b>1</b><td> <td>true<td> <td>true<td> <td>tukey(0.5)<td> <td>0<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>0<td> <td>3<td> <td>0<td> </tr> 847 * <tr> <td><b>2</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>0<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>0<td> <td>3<td> <td>0<td> </tr> 848 * <tr> <td><b>3</b><td> <td>false<td> <td>false<td> <td>tukey(0.5)<td> <td>6<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>0<td> <td>4<td> <td>0<td> </tr> 849 * <tr> <td><b>4</b><td> <td>true<td> <td>true<td> <td>tukey(0.5)<td> <td>8<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>0<td> <td>4<td> <td>0<td> </tr> 850 * <tr> <td><b>5</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>8<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>0<td> <td>5<td> <td>0<td> </tr> 851 * <tr> <td><b>6</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>8<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>0<td> <td>6<td> <td>0<td> </tr> 852 * <tr> <td><b>7</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>8<td> <td>0<td> <td>false<td> <td>false<td> <td>true<td> <td>0<td> <td>6<td> <td>0<td> </tr> 853 * <tr> <td><b>8</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>12<td> <td>0<td> <td>false<td> <td>false<td> <td>true<td> <td>0<td> <td>6<td> <td>0<td> </tr> 854 * </table> 855 * 856 * \default \c 5 857 * \param encoder An encoder instance to set. 858 * \param value See above. 859 * \assert 860 * \code encoder != NULL \endcode 861 * \retval FLAC__bool 862 * \c false if the encoder is already initialized, else \c true. 863 */ 864 FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder* encoder, uint value); 865 866 /** Set the blocksize to use while encoding. 867 * 868 * The number of samples to use per frame. Use \c 0 to let the encoder 869 * estimate a blocksize; this is usually best. 870 * 871 * \default \c 0 872 * \param encoder An encoder instance to set. 873 * \param value See above. 874 * \assert 875 * \code encoder != NULL \endcode 876 * \retval FLAC__bool 877 * \c false if the encoder is already initialized, else \c true. 878 */ 879 FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder* encoder, uint value); 880 881 /** Set to \c true to enable mid-side encoding on stereo input. The 882 * number of channels must be 2 for this to have any effect. Set to 883 * \c false to use only independent channel coding. 884 * 885 * \default \c false 886 * \param encoder An encoder instance to set. 887 * \param value Flag value (see above). 888 * \assert 889 * \code encoder != NULL \endcode 890 * \retval FLAC__bool 891 * \c false if the encoder is already initialized, else \c true. 892 */ 893 FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder* encoder, FLAC__bool value); 894 895 /** Set to \c true to enable adaptive switching between mid-side and 896 * left-right encoding on stereo input. Set to \c false to use 897 * exhaustive searching. Setting this to \c true requires 898 * FLAC__stream_encoder_set_do_mid_side_stereo() to also be set to 899 * \c true in order to have any effect. 900 * 901 * \default \c false 902 * \param encoder An encoder instance to set. 903 * \param value Flag value (see above). 904 * \assert 905 * \code encoder != NULL \endcode 906 * \retval FLAC__bool 907 * \c false if the encoder is already initialized, else \c true. 908 */ 909 FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder* encoder, FLAC__bool value); 910 911 /** Sets the apodization function(s) the encoder will use when windowing 912 * audio data for LPC analysis. 913 * 914 * The \a specification is a plain ASCII string which specifies exactly 915 * which functions to use. There may be more than one (up to 32), 916 * separated by \c ';' characters. Some functions take one or more 917 * comma-separated arguments in parentheses. 918 * 919 * The available functions are \c bartlett, \c bartlett_hann, 920 * \c blackman, \c blackman_harris_4term_92db, \c connes, \c flattop, 921 * \c gauss(STDDEV), \c hamming, \c hann, \c kaiser_bessel, \c nuttall, 922 * \c rectangle, \c triangle, \c tukey(P), \c welch. 923 * 924 * For \c gauss(STDDEV), STDDEV specifies the standard deviation 925 * (0<STDDEV<=0.5). 926 * 927 * For \c tukey(P), P specifies the fraction of the window that is 928 * tapered (0<=P<=1). P=0 corresponds to \c rectangle and P=1 929 * corresponds to \c hann. 930 * 931 * Example specifications are \c "blackman" or 932 * \c "hann;triangle;tukey(0.5);tukey(0.25);tukey(0.125)" 933 * 934 * Any function that is specified erroneously is silently dropped. Up 935 * to 32 functions are kept, the rest are dropped. If the specification 936 * is empty the encoder defaults to \c "tukey(0.5)". 937 * 938 * When more than one function is specified, then for every subframe the 939 * encoder will try each of them separately and choose the window that 940 * results in the smallest compressed subframe. 941 * 942 * Note that each function specified causes the encoder to occupy a 943 * floating point array in which to store the window. 944 * 945 * \default \c "tukey(0.5)" 946 * \param encoder An encoder instance to set. 947 * \param specification See above. 948 * \assert 949 * \code encoder != NULL \endcode 950 * \code specification != NULL \endcode 951 * \retval FLAC__bool 952 * \c false if the encoder is already initialized, else \c true. 953 */ 954 FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder* encoder, const char* specification); 955 956 /** Set the maximum LPC order, or \c 0 to use only the fixed predictors. 957 * 958 * \default \c 0 959 * \param encoder An encoder instance to set. 960 * \param value See above. 961 * \assert 962 * \code encoder != NULL \endcode 963 * \retval FLAC__bool 964 * \c false if the encoder is already initialized, else \c true. 965 */ 966 FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder* encoder, uint value); 967 968 /** Set the precision, in bits, of the quantized linear predictor 969 * coefficients, or \c 0 to let the encoder select it based on the 970 * blocksize. 971 * 972 * \note 973 * In the current implementation, qlp_coeff_precision + bits_per_sample must 974 * be less than 32. 975 * 976 * \default \c 0 977 * \param encoder An encoder instance to set. 978 * \param value See above. 979 * \assert 980 * \code encoder != NULL \endcode 981 * \retval FLAC__bool 982 * \c false if the encoder is already initialized, else \c true. 983 */ 984 FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder* encoder, uint value); 985 986 /** Set to \c false to use only the specified quantized linear predictor 987 * coefficient precision, or \c true to search neighboring precision 988 * values and use the best one. 989 * 990 * \default \c false 991 * \param encoder An encoder instance to set. 992 * \param value See above. 993 * \assert 994 * \code encoder != NULL \endcode 995 * \retval FLAC__bool 996 * \c false if the encoder is already initialized, else \c true. 997 */ 998 FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder* encoder, FLAC__bool value); 999 1000 /** Deprecated. Setting this value has no effect. 1001 * 1002 * \default \c false 1003 * \param encoder An encoder instance to set. 1004 * \param value See above. 1005 * \assert 1006 * \code encoder != NULL \endcode 1007 * \retval FLAC__bool 1008 * \c false if the encoder is already initialized, else \c true. 1009 */ 1010 FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder* encoder, FLAC__bool value); 1011 1012 /** Set to \c false to let the encoder estimate the best model order 1013 * based on the residual signal energy, or \c true to force the 1014 * encoder to evaluate all order models and select the best. 1015 * 1016 * \default \c false 1017 * \param encoder An encoder instance to set. 1018 * \param value See above. 1019 * \assert 1020 * \code encoder != NULL \endcode 1021 * \retval FLAC__bool 1022 * \c false if the encoder is already initialized, else \c true. 1023 */ 1024 FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder* encoder, FLAC__bool value); 1025 1026 /** Set the minimum partition order to search when coding the residual. 1027 * This is used in tandem with 1028 * FLAC__stream_encoder_set_max_residual_partition_order(). 1029 * 1030 * The partition order determines the context size in the residual. 1031 * The context size will be approximately <tt>blocksize / (2 ^ order)</tt>. 1032 * 1033 * Set both min and max values to \c 0 to force a single context, 1034 * whose Rice parameter is based on the residual signal variance. 1035 * Otherwise, set a min and max order, and the encoder will search 1036 * all orders, using the mean of each context for its Rice parameter, 1037 * and use the best. 1038 * 1039 * \default \c 0 1040 * \param encoder An encoder instance to set. 1041 * \param value See above. 1042 * \assert 1043 * \code encoder != NULL \endcode 1044 * \retval FLAC__bool 1045 * \c false if the encoder is already initialized, else \c true. 1046 */ 1047 FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder* encoder, uint value); 1048 1049 /** Set the maximum partition order to search when coding the residual. 1050 * This is used in tandem with 1051 * FLAC__stream_encoder_set_min_residual_partition_order(). 1052 * 1053 * The partition order determines the context size in the residual. 1054 * The context size will be approximately <tt>blocksize / (2 ^ order)</tt>. 1055 * 1056 * Set both min and max values to \c 0 to force a single context, 1057 * whose Rice parameter is based on the residual signal variance. 1058 * Otherwise, set a min and max order, and the encoder will search 1059 * all orders, using the mean of each context for its Rice parameter, 1060 * and use the best. 1061 * 1062 * \default \c 0 1063 * \param encoder An encoder instance to set. 1064 * \param value See above. 1065 * \assert 1066 * \code encoder != NULL \endcode 1067 * \retval FLAC__bool 1068 * \c false if the encoder is already initialized, else \c true. 1069 */ 1070 FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder* encoder, uint value); 1071 1072 /** Deprecated. Setting this value has no effect. 1073 * 1074 * \default \c 0 1075 * \param encoder An encoder instance to set. 1076 * \param value See above. 1077 * \assert 1078 * \code encoder != NULL \endcode 1079 * \retval FLAC__bool 1080 * \c false if the encoder is already initialized, else \c true. 1081 */ 1082 FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder* encoder, uint value); 1083 1084 /** Set an estimate of the total samples that will be encoded. 1085 * This is merely an estimate and may be set to \c 0 if unknown. 1086 * This value will be written to the STREAMINFO block before encoding, 1087 * and can remove the need for the caller to rewrite the value later 1088 * if the value is known before encoding. 1089 * 1090 * \default \c 0 1091 * \param encoder An encoder instance to set. 1092 * \param value See above. 1093 * \assert 1094 * \code encoder != NULL \endcode 1095 * \retval FLAC__bool 1096 * \c false if the encoder is already initialized, else \c true. 1097 */ 1098 FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder* encoder, FLAC__uint64 value); 1099 1100 /** Set the metadata blocks to be emitted to the stream before encoding. 1101 * A value of \c NULL, \c 0 implies no metadata; otherwise, supply an 1102 * array of pointers to metadata blocks. The array is non-const since 1103 * the encoder may need to change the \a is_last flag inside them, and 1104 * in some cases update seek point offsets. Otherwise, the encoder will 1105 * not modify or free the blocks. It is up to the caller to free the 1106 * metadata blocks after encoding finishes. 1107 * 1108 * \note 1109 * The encoder stores only copies of the pointers in the \a metadata array; 1110 * the metadata blocks themselves must survive at least until after 1111 * FLAC__stream_encoder_finish() returns. Do not free the blocks until then. 1112 * 1113 * \note 1114 * The STREAMINFO block is always written and no STREAMINFO block may 1115 * occur in the supplied array. 1116 * 1117 * \note 1118 * By default the encoder does not create a SEEKTABLE. If one is supplied 1119 * in the \a metadata array, but the client has specified that it does not 1120 * support seeking, then the SEEKTABLE will be written verbatim. However 1121 * by itself this is not very useful as the client will not know the stream 1122 * offsets for the seekpoints ahead of time. In order to get a proper 1123 * seektable the client must support seeking. See next note. 1124 * 1125 * \note 1126 * SEEKTABLE blocks are handled specially. Since you will not know 1127 * the values for the seek point stream offsets, you should pass in 1128 * a SEEKTABLE 'template', that is, a SEEKTABLE object with the 1129 * required sample numbers (or placeholder points), with \c 0 for the 1130 * \a frame_samples and \a stream_offset fields for each point. If the 1131 * client has specified that it supports seeking by providing a seek 1132 * callback to FLAC__stream_encoder_init_stream() or both seek AND read 1133 * callback to FLAC__stream_encoder_init_ogg_stream() (or by using 1134 * FLAC__stream_encoder_init*_file() or FLAC__stream_encoder_init*_FILE()), 1135 * then while it is encoding the encoder will fill the stream offsets in 1136 * for you and when encoding is finished, it will seek back and write the 1137 * real values into the SEEKTABLE block in the stream. There are helper 1138 * routines for manipulating seektable template blocks; see metadata.h: 1139 * FLAC__metadata_object_seektable_template_*(). If the client does 1140 * not support seeking, the SEEKTABLE will have inaccurate offsets which 1141 * will slow down or remove the ability to seek in the FLAC stream. 1142 * 1143 * \note 1144 * The encoder instance \b will modify the first \c SEEKTABLE block 1145 * as it transforms the template to a valid seektable while encoding, 1146 * but it is still up to the caller to free all metadata blocks after 1147 * encoding. 1148 * 1149 * \note 1150 * A VORBIS_COMMENT block may be supplied. The vendor string in it 1151 * will be ignored. libFLAC will use it's own vendor string. libFLAC 1152 * will not modify the passed-in VORBIS_COMMENT's vendor string, it 1153 * will simply write it's own into the stream. If no VORBIS_COMMENT 1154 * block is present in the \a metadata array, libFLAC will write an 1155 * empty one, containing only the vendor string. 1156 * 1157 * \note The Ogg FLAC mapping requires that the VORBIS_COMMENT block be 1158 * the second metadata block of the stream. The encoder already supplies 1159 * the STREAMINFO block automatically. If \a metadata does not contain a 1160 * VORBIS_COMMENT block, the encoder will supply that too. Otherwise, if 1161 * \a metadata does contain a VORBIS_COMMENT block and it is not the 1162 * first, the init function will reorder \a metadata by moving the 1163 * VORBIS_COMMENT block to the front; the relative ordering of the other 1164 * blocks will remain as they were. 1165 * 1166 * \note The Ogg FLAC mapping limits the number of metadata blocks per 1167 * stream to \c 65535. If \a num_blocks exceeds this the function will 1168 * return \c false. 1169 * 1170 * \default \c NULL, 0 1171 * \param encoder An encoder instance to set. 1172 * \param metadata See above. 1173 * \param num_blocks See above. 1174 * \assert 1175 * \code encoder != NULL \endcode 1176 * \retval FLAC__bool 1177 * \c false if the encoder is already initialized, else \c true. 1178 * \c false if the encoder is already initialized, or if 1179 * \a num_blocks > 65535 if encoding to Ogg FLAC, else \c true. 1180 */ 1181 FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder* encoder, FLAC__StreamMetadata** metadata, uint num_blocks); 1182 1183 /** Get the current encoder state. 1184 * 1185 * \param encoder An encoder instance to query. 1186 * \assert 1187 * \code encoder != NULL \endcode 1188 * \retval FLAC__StreamEncoderState 1189 * The current encoder state. 1190 */ 1191 FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder* encoder); 1192 1193 /** Get the state of the verify stream decoder. 1194 * Useful when the stream encoder state is 1195 * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. 1196 * 1197 * \param encoder An encoder instance to query. 1198 * \assert 1199 * \code encoder != NULL \endcode 1200 * \retval FLAC__StreamDecoderState 1201 * The verify stream decoder state. 1202 */ 1203 FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder* encoder); 1204 1205 /** Get the current encoder state as a C string. 1206 * This version automatically resolves 1207 * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR by getting the 1208 * verify decoder's state. 1209 * 1210 * \param encoder A encoder instance to query. 1211 * \assert 1212 * \code encoder != NULL \endcode 1213 * \retval const char * 1214 * The encoder state as a C string. Do not modify the contents. 1215 */ 1216 const(char)* FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder* encoder); 1217 1218 /** Get relevant values about the nature of a verify decoder error. 1219 * Useful when the stream encoder state is 1220 * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. The arguments should 1221 * be addresses in which the stats will be returned, or NULL if value 1222 * is not desired. 1223 * 1224 * \param encoder An encoder instance to query. 1225 * \param absolute_sample The absolute sample number of the mismatch. 1226 * \param frame_number The number of the frame in which the mismatch occurred. 1227 * \param channel The channel in which the mismatch occurred. 1228 * \param sample The number of the sample (relative to the frame) in 1229 * which the mismatch occurred. 1230 * \param expected The expected value for the sample in question. 1231 * \param got The actual value returned by the decoder. 1232 * \assert 1233 * \code encoder != NULL \endcode 1234 */ 1235 void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder* encoder, FLAC__uint64* absolute_sample, uint* frame_number, uint* channel, uint* sample, FLAC__int32* expected, FLAC__int32* got); 1236 1237 /** Get the "verify" flag. 1238 * 1239 * \param encoder An encoder instance to query. 1240 * \assert 1241 * \code encoder != NULL \endcode 1242 * \retval FLAC__bool 1243 * See FLAC__stream_encoder_set_verify(). 1244 */ 1245 FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder* encoder); 1246 1247 /** Get the <A HREF="../format.html#subset>Subset</A> flag. 1248 * 1249 * \param encoder An encoder instance to query. 1250 * \assert 1251 * \code encoder != NULL \endcode 1252 * \retval FLAC__bool 1253 * See FLAC__stream_encoder_set_streamable_subset(). 1254 */ 1255 FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder* encoder); 1256 1257 /** Get the number of input channels being processed. 1258 * 1259 * \param encoder An encoder instance to query. 1260 * \assert 1261 * \code encoder != NULL \endcode 1262 * \retval uint 1263 * See FLAC__stream_encoder_set_channels(). 1264 */ 1265 uint FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder* encoder); 1266 1267 /** Get the input sample resolution setting. 1268 * 1269 * \param encoder An encoder instance to query. 1270 * \assert 1271 * \code encoder != NULL \endcode 1272 * \retval uint 1273 * See FLAC__stream_encoder_set_bits_per_sample(). 1274 */ 1275 uint FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder* encoder); 1276 1277 /** Get the input sample rate setting. 1278 * 1279 * \param encoder An encoder instance to query. 1280 * \assert 1281 * \code encoder != NULL \endcode 1282 * \retval uint 1283 * See FLAC__stream_encoder_set_sample_rate(). 1284 */ 1285 uint FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder* encoder); 1286 1287 /** Get the blocksize setting. 1288 * 1289 * \param encoder An encoder instance to query. 1290 * \assert 1291 * \code encoder != NULL \endcode 1292 * \retval uint 1293 * See FLAC__stream_encoder_set_blocksize(). 1294 */ 1295 uint FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder* encoder); 1296 1297 /** Get the "mid/side stereo coding" flag. 1298 * 1299 * \param encoder An encoder instance to query. 1300 * \assert 1301 * \code encoder != NULL \endcode 1302 * \retval FLAC__bool 1303 * See FLAC__stream_encoder_get_do_mid_side_stereo(). 1304 */ 1305 FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder* encoder); 1306 1307 /** Get the "adaptive mid/side switching" flag. 1308 * 1309 * \param encoder An encoder instance to query. 1310 * \assert 1311 * \code encoder != NULL \endcode 1312 * \retval FLAC__bool 1313 * See FLAC__stream_encoder_set_loose_mid_side_stereo(). 1314 */ 1315 FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder* encoder); 1316 1317 /** Get the maximum LPC order setting. 1318 * 1319 * \param encoder An encoder instance to query. 1320 * \assert 1321 * \code encoder != NULL \endcode 1322 * \retval uint 1323 * See FLAC__stream_encoder_set_max_lpc_order(). 1324 */ 1325 uint FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder* encoder); 1326 1327 /** Get the quantized linear predictor coefficient precision setting. 1328 * 1329 * \param encoder An encoder instance to query. 1330 * \assert 1331 * \code encoder != NULL \endcode 1332 * \retval uint 1333 * See FLAC__stream_encoder_set_qlp_coeff_precision(). 1334 */ 1335 uint FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder* encoder); 1336 1337 /** Get the qlp coefficient precision search flag. 1338 * 1339 * \param encoder An encoder instance to query. 1340 * \assert 1341 * \code encoder != NULL \endcode 1342 * \retval FLAC__bool 1343 * See FLAC__stream_encoder_set_do_qlp_coeff_prec_search(). 1344 */ 1345 FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder* encoder); 1346 1347 /** Get the "escape coding" flag. 1348 * 1349 * \param encoder An encoder instance to query. 1350 * \assert 1351 * \code encoder != NULL \endcode 1352 * \retval FLAC__bool 1353 * See FLAC__stream_encoder_set_do_escape_coding(). 1354 */ 1355 FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder* encoder); 1356 1357 /** Get the exhaustive model search flag. 1358 * 1359 * \param encoder An encoder instance to query. 1360 * \assert 1361 * \code encoder != NULL \endcode 1362 * \retval FLAC__bool 1363 * See FLAC__stream_encoder_set_do_exhaustive_model_search(). 1364 */ 1365 FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder* encoder); 1366 1367 /** Get the minimum residual partition order setting. 1368 * 1369 * \param encoder An encoder instance to query. 1370 * \assert 1371 * \code encoder != NULL \endcode 1372 * \retval uint 1373 * See FLAC__stream_encoder_set_min_residual_partition_order(). 1374 */ 1375 uint FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder* encoder); 1376 1377 /** Get maximum residual partition order setting. 1378 * 1379 * \param encoder An encoder instance to query. 1380 * \assert 1381 * \code encoder != NULL \endcode 1382 * \retval uint 1383 * See FLAC__stream_encoder_set_max_residual_partition_order(). 1384 */ 1385 uint FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder* encoder); 1386 1387 /** Get the Rice parameter search distance setting. 1388 * 1389 * \param encoder An encoder instance to query. 1390 * \assert 1391 * \code encoder != NULL \endcode 1392 * \retval uint 1393 * See FLAC__stream_encoder_set_rice_parameter_search_dist(). 1394 */ 1395 uint FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder* encoder); 1396 1397 /** Get the previously set estimate of the total samples to be encoded. 1398 * The encoder merely mimics back the value given to 1399 * FLAC__stream_encoder_set_total_samples_estimate() since it has no 1400 * other way of knowing how many samples the client will encode. 1401 * 1402 * \param encoder An encoder instance to set. 1403 * \assert 1404 * \code encoder != NULL \endcode 1405 * \retval FLAC__uint64 1406 * See FLAC__stream_encoder_get_total_samples_estimate(). 1407 */ 1408 FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder* encoder); 1409 1410 /** Initialize the encoder instance to encode native FLAC streams. 1411 * 1412 * This flavor of initialization sets up the encoder to encode to a 1413 * native FLAC stream. I/O is performed via callbacks to the client. 1414 * For encoding to a plain file via filename or open \c FILE*, 1415 * FLAC__stream_encoder_init_file() and FLAC__stream_encoder_init_FILE() 1416 * provide a simpler interface. 1417 * 1418 * This function should be called after FLAC__stream_encoder_new() and 1419 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() 1420 * or FLAC__stream_encoder_process_interleaved(). 1421 * initialization succeeded. 1422 * 1423 * The call to FLAC__stream_encoder_init_stream() currently will also 1424 * immediately call the write callback several times, once with the \c fLaC 1425 * signature, and once for each encoded metadata block. 1426 * 1427 * \param encoder An uninitialized encoder instance. 1428 * \param write_callback See FLAC__StreamEncoderWriteCallback. This 1429 * pointer must not be \c NULL. 1430 * \param seek_callback See FLAC__StreamEncoderSeekCallback. This 1431 * pointer may be \c NULL if seeking is not 1432 * supported. The encoder uses seeking to go back 1433 * and write some some stream statistics to the 1434 * STREAMINFO block; this is recommended but not 1435 * necessary to create a valid FLAC stream. If 1436 * \a seek_callback is not \c NULL then a 1437 * \a tell_callback must also be supplied. 1438 * Alternatively, a dummy seek callback that just 1439 * returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED 1440 * may also be supplied, all though this is slightly 1441 * less efficient for the encoder. 1442 * \param tell_callback See FLAC__StreamEncoderTellCallback. This 1443 * pointer may be \c NULL if seeking is not 1444 * supported. If \a seek_callback is \c NULL then 1445 * this argument will be ignored. If 1446 * \a seek_callback is not \c NULL then a 1447 * \a tell_callback must also be supplied. 1448 * Alternatively, a dummy tell callback that just 1449 * returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED 1450 * may also be supplied, all though this is slightly 1451 * less efficient for the encoder. 1452 * \param metadata_callback See FLAC__StreamEncoderMetadataCallback. This 1453 * pointer may be \c NULL if the callback is not 1454 * desired. If the client provides a seek callback, 1455 * this function is not necessary as the encoder 1456 * will automatically seek back and update the 1457 * STREAMINFO block. It may also be \c NULL if the 1458 * client does not support seeking, since it will 1459 * have no way of going back to update the 1460 * STREAMINFO. However the client can still supply 1461 * a callback if it would like to know the details 1462 * from the STREAMINFO. 1463 * \param client_data This value will be supplied to callbacks in their 1464 * \a client_data argument. 1465 * \assert 1466 * \code encoder != NULL \endcode 1467 * \retval FLAC__StreamEncoderInitStatus 1468 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; 1469 * see FLAC__StreamEncoderInitStatus for the meanings of other return values. 1470 */ 1471 FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__StreamEncoder* encoder, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void* client_data); 1472 1473 /** Initialize the encoder instance to encode Ogg FLAC streams. 1474 * 1475 * This flavor of initialization sets up the encoder to encode to a FLAC 1476 * stream in an Ogg container. I/O is performed via callbacks to the 1477 * client. For encoding to a plain file via filename or open \c FILE*, 1478 * FLAC__stream_encoder_init_ogg_file() and FLAC__stream_encoder_init_ogg_FILE() 1479 * provide a simpler interface. 1480 * 1481 * This function should be called after FLAC__stream_encoder_new() and 1482 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() 1483 * or FLAC__stream_encoder_process_interleaved(). 1484 * initialization succeeded. 1485 * 1486 * The call to FLAC__stream_encoder_init_ogg_stream() currently will also 1487 * immediately call the write callback several times to write the metadata 1488 * packets. 1489 * 1490 * \param encoder An uninitialized encoder instance. 1491 * \param read_callback See FLAC__StreamEncoderReadCallback. This 1492 * pointer must not be \c NULL if \a seek_callback 1493 * is non-NULL since they are both needed to be 1494 * able to write data back to the Ogg FLAC stream 1495 * in the post-encode phase. 1496 * \param write_callback See FLAC__StreamEncoderWriteCallback. This 1497 * pointer must not be \c NULL. 1498 * \param seek_callback See FLAC__StreamEncoderSeekCallback. This 1499 * pointer may be \c NULL if seeking is not 1500 * supported. The encoder uses seeking to go back 1501 * and write some some stream statistics to the 1502 * STREAMINFO block; this is recommended but not 1503 * necessary to create a valid FLAC stream. If 1504 * \a seek_callback is not \c NULL then a 1505 * \a tell_callback must also be supplied. 1506 * Alternatively, a dummy seek callback that just 1507 * returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED 1508 * may also be supplied, all though this is slightly 1509 * less efficient for the encoder. 1510 * \param tell_callback See FLAC__StreamEncoderTellCallback. This 1511 * pointer may be \c NULL if seeking is not 1512 * supported. If \a seek_callback is \c NULL then 1513 * this argument will be ignored. If 1514 * \a seek_callback is not \c NULL then a 1515 * \a tell_callback must also be supplied. 1516 * Alternatively, a dummy tell callback that just 1517 * returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED 1518 * may also be supplied, all though this is slightly 1519 * less efficient for the encoder. 1520 * \param metadata_callback See FLAC__StreamEncoderMetadataCallback. This 1521 * pointer may be \c NULL if the callback is not 1522 * desired. If the client provides a seek callback, 1523 * this function is not necessary as the encoder 1524 * will automatically seek back and update the 1525 * STREAMINFO block. It may also be \c NULL if the 1526 * client does not support seeking, since it will 1527 * have no way of going back to update the 1528 * STREAMINFO. However the client can still supply 1529 * a callback if it would like to know the details 1530 * from the STREAMINFO. 1531 * \param client_data This value will be supplied to callbacks in their 1532 * \a client_data argument. 1533 * \assert 1534 * \code encoder != NULL \endcode 1535 * \retval FLAC__StreamEncoderInitStatus 1536 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; 1537 * see FLAC__StreamEncoderInitStatus for the meanings of other return values. 1538 */ 1539 FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(FLAC__StreamEncoder* encoder, FLAC__StreamEncoderReadCallback read_callback, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void* client_data); 1540 1541 /** Initialize the encoder instance to encode native FLAC files. 1542 * 1543 * This flavor of initialization sets up the encoder to encode to a 1544 * plain native FLAC file. For non-stdio streams, you must use 1545 * FLAC__stream_encoder_init_stream() and provide callbacks for the I/O. 1546 * 1547 * This function should be called after FLAC__stream_encoder_new() and 1548 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() 1549 * or FLAC__stream_encoder_process_interleaved(). 1550 * initialization succeeded. 1551 * 1552 * \param encoder An uninitialized encoder instance. 1553 * \param file An open file. The file should have been opened 1554 * with mode \c "w+b" and rewound. The file 1555 * becomes owned by the encoder and should not be 1556 * manipulated by the client while encoding. 1557 * Unless \a file is \c stdout, it will be closed 1558 * when FLAC__stream_encoder_finish() is called. 1559 * Note however that a proper SEEKTABLE cannot be 1560 * created when encoding to \c stdout since it is 1561 * not seekable. 1562 * \param progress_callback See FLAC__StreamEncoderProgressCallback. This 1563 * pointer may be \c NULL if the callback is not 1564 * desired. 1565 * \param client_data This value will be supplied to callbacks in their 1566 * \a client_data argument. 1567 * \assert 1568 * \code encoder != NULL \endcode 1569 * \code file != NULL \endcode 1570 * \retval FLAC__StreamEncoderInitStatus 1571 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; 1572 * see FLAC__StreamEncoderInitStatus for the meanings of other return values. 1573 */ 1574 FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder* encoder, FILE* file, FLAC__StreamEncoderProgressCallback progress_callback, void* client_data); 1575 1576 /** Initialize the encoder instance to encode Ogg FLAC files. 1577 * 1578 * This flavor of initialization sets up the encoder to encode to a 1579 * plain Ogg FLAC file. For non-stdio streams, you must use 1580 * FLAC__stream_encoder_init_ogg_stream() and provide callbacks for the I/O. 1581 * 1582 * This function should be called after FLAC__stream_encoder_new() and 1583 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() 1584 * or FLAC__stream_encoder_process_interleaved(). 1585 * initialization succeeded. 1586 * 1587 * \param encoder An uninitialized encoder instance. 1588 * \param file An open file. The file should have been opened 1589 * with mode \c "w+b" and rewound. The file 1590 * becomes owned by the encoder and should not be 1591 * manipulated by the client while encoding. 1592 * Unless \a file is \c stdout, it will be closed 1593 * when FLAC__stream_encoder_finish() is called. 1594 * Note however that a proper SEEKTABLE cannot be 1595 * created when encoding to \c stdout since it is 1596 * not seekable. 1597 * \param progress_callback See FLAC__StreamEncoderProgressCallback. This 1598 * pointer may be \c NULL if the callback is not 1599 * desired. 1600 * \param client_data This value will be supplied to callbacks in their 1601 * \a client_data argument. 1602 * \assert 1603 * \code encoder != NULL \endcode 1604 * \code file != NULL \endcode 1605 * \retval FLAC__StreamEncoderInitStatus 1606 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; 1607 * see FLAC__StreamEncoderInitStatus for the meanings of other return values. 1608 */ 1609 FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder* encoder, FILE* file, FLAC__StreamEncoderProgressCallback progress_callback, void* client_data); 1610 1611 /** Initialize the encoder instance to encode native FLAC files. 1612 * 1613 * This flavor of initialization sets up the encoder to encode to a plain 1614 * FLAC file. If POSIX fopen() semantics are not sufficient (for example, 1615 * with Unicode filenames on Windows), you must use 1616 * FLAC__stream_encoder_init_FILE(), or FLAC__stream_encoder_init_stream() 1617 * and provide callbacks for the I/O. 1618 * 1619 * This function should be called after FLAC__stream_encoder_new() and 1620 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() 1621 * or FLAC__stream_encoder_process_interleaved(). 1622 * initialization succeeded. 1623 * 1624 * \param encoder An uninitialized encoder instance. 1625 * \param filename The name of the file to encode to. The file will 1626 * be opened with fopen(). Use \c NULL to encode to 1627 * \c stdout. Note however that a proper SEEKTABLE 1628 * cannot be created when encoding to \c stdout since 1629 * it is not seekable. 1630 * \param progress_callback See FLAC__StreamEncoderProgressCallback. This 1631 * pointer may be \c NULL if the callback is not 1632 * desired. 1633 * \param client_data This value will be supplied to callbacks in their 1634 * \a client_data argument. 1635 * \assert 1636 * \code encoder != NULL \endcode 1637 * \retval FLAC__StreamEncoderInitStatus 1638 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; 1639 * see FLAC__StreamEncoderInitStatus for the meanings of other return values. 1640 */ 1641 FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder* encoder, const char* filename, FLAC__StreamEncoderProgressCallback progress_callback, void* client_data); 1642 1643 /** Initialize the encoder instance to encode Ogg FLAC files. 1644 * 1645 * This flavor of initialization sets up the encoder to encode to a plain 1646 * Ogg FLAC file. If POSIX fopen() semantics are not sufficient (for example, 1647 * with Unicode filenames on Windows), you must use 1648 * FLAC__stream_encoder_init_ogg_FILE(), or FLAC__stream_encoder_init_ogg_stream() 1649 * and provide callbacks for the I/O. 1650 * 1651 * This function should be called after FLAC__stream_encoder_new() and 1652 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() 1653 * or FLAC__stream_encoder_process_interleaved(). 1654 * initialization succeeded. 1655 * 1656 * \param encoder An uninitialized encoder instance. 1657 * \param filename The name of the file to encode to. The file will 1658 * be opened with fopen(). Use \c NULL to encode to 1659 * \c stdout. Note however that a proper SEEKTABLE 1660 * cannot be created when encoding to \c stdout since 1661 * it is not seekable. 1662 * \param progress_callback See FLAC__StreamEncoderProgressCallback. This 1663 * pointer may be \c NULL if the callback is not 1664 * desired. 1665 * \param client_data This value will be supplied to callbacks in their 1666 * \a client_data argument. 1667 * \assert 1668 * \code encoder != NULL \endcode 1669 * \retval FLAC__StreamEncoderInitStatus 1670 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; 1671 * see FLAC__StreamEncoderInitStatus for the meanings of other return values. 1672 */ 1673 FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder* encoder, const char* filename, FLAC__StreamEncoderProgressCallback progress_callback, void* client_data); 1674 1675 /** Finish the encoding process. 1676 * Flushes the encoding buffer, releases resources, resets the encoder 1677 * settings to their defaults, and returns the encoder state to 1678 * FLAC__STREAM_ENCODER_UNINITIALIZED. Note that this can generate 1679 * one or more write callbacks before returning, and will generate 1680 * a metadata callback. 1681 * 1682 * Note that in the course of processing the last frame, errors can 1683 * occur, so the caller should be sure to check the return value to 1684 * ensure the file was encoded properly. 1685 * 1686 * In the event of a prematurely-terminated encode, it is not strictly 1687 * necessary to call this immediately before FLAC__stream_encoder_delete() 1688 * but it is good practice to match every FLAC__stream_encoder_init_*() 1689 * with a FLAC__stream_encoder_finish(). 1690 * 1691 * \param encoder An uninitialized encoder instance. 1692 * \assert 1693 * \code encoder != NULL \endcode 1694 * \retval FLAC__bool 1695 * \c false if an error occurred processing the last frame; or if verify 1696 * mode is set (see FLAC__stream_encoder_set_verify()), there was a 1697 * verify mismatch; else \c true. If \c false, caller should check the 1698 * state with FLAC__stream_encoder_get_state() for more information 1699 * about the error. 1700 */ 1701 FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder* encoder); 1702 1703 /** Submit data for encoding. 1704 * This version allows you to supply the input data via an array of 1705 * pointers, each pointer pointing to an array of \a samples samples 1706 * representing one channel. The samples need not be block-aligned, 1707 * but each channel should have the same number of samples. Each sample 1708 * should be a signed integer, right-justified to the resolution set by 1709 * FLAC__stream_encoder_set_bits_per_sample(). For example, if the 1710 * resolution is 16 bits per sample, the samples should all be in the 1711 * range [-32768,32767]. 1712 * 1713 * For applications where channel order is important, channels must 1714 * follow the order as described in the 1715 * <A HREF="../format.html#frame_header">frame header</A>. 1716 * 1717 * \param encoder An initialized encoder instance in the OK state. 1718 * \param buffer An array of pointers to each channel's signal. 1719 * \param samples The number of samples in one channel. 1720 * \assert 1721 * \code encoder != NULL \endcode 1722 * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode 1723 * \retval FLAC__bool 1724 * \c true if successful, else \c false; in this case, check the 1725 * encoder state with FLAC__stream_encoder_get_state() to see what 1726 * went wrong. 1727 */ 1728 FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder* encoder, const FLAC__int32** buffer, uint samples); 1729 1730 /** Submit data for encoding. 1731 * This version allows you to supply the input data where the channels 1732 * are interleaved into a single array (i.e. channel0_sample0, 1733 * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...). 1734 * The samples need not be block-aligned but they must be 1735 * sample-aligned, i.e. the first value should be channel0_sample0 1736 * and the last value channelN_sampleM. Each sample should be a signed 1737 * integer, right-justified to the resolution set by 1738 * FLAC__stream_encoder_set_bits_per_sample(). For example, if the 1739 * resolution is 16 bits per sample, the samples should all be in the 1740 * range [-32768,32767]. 1741 * 1742 * For applications where channel order is important, channels must 1743 * follow the order as described in the 1744 * <A HREF="../format.html#frame_header">frame header</A>. 1745 * 1746 * \param encoder An initialized encoder instance in the OK state. 1747 * \param buffer An array of channel-interleaved data (see above). 1748 * \param samples The number of samples in one channel, the same as for 1749 * FLAC__stream_encoder_process(). For example, if 1750 * encoding two channels, \c 1000 \a samples corresponds 1751 * to a \a buffer of 2000 values. 1752 * \assert 1753 * \code encoder != NULL \endcode 1754 * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode 1755 * \retval FLAC__bool 1756 * \c true if successful, else \c false; in this case, check the 1757 * encoder state with FLAC__stream_encoder_get_state() to see what 1758 * went wrong. 1759 */ 1760 FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder* encoder, const FLAC__int32* buffer, uint samples);