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