stream_encoder.h 80 KB

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