flac_FLAC_stream_encoder.h 79 KB

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