vorbisenc.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  5. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
  9. * by the Xiph.Org Foundation http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function: vorbis encode-engine setup
  13. ********************************************************************/
  14. /** \file
  15. * Libvorbisenc is a convenient API for setting up an encoding
  16. * environment using libvorbis. Libvorbisenc encapsulates the
  17. * actions needed to set up the encoder properly.
  18. */
  19. #ifndef _OV_ENC_H_
  20. #define _OV_ENC_H_
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif /* __cplusplus */
  25. #include "codec.h"
  26. /**
  27. * This is the primary function within libvorbisenc for setting up managed
  28. * bitrate modes.
  29. *
  30. * Before this function is called, the \ref vorbis_info
  31. * struct should be initialized by using vorbis_info_init() from the libvorbis
  32. * API. After encoding, vorbis_info_clear() should be called.
  33. *
  34. * The max_bitrate, nominal_bitrate, and min_bitrate settings are used to set
  35. * constraints for the encoded file. This function uses these settings to
  36. * select the appropriate encoding mode and set it up.
  37. *
  38. * \param vi Pointer to an initialized \ref vorbis_info struct.
  39. * \param channels The number of channels to be encoded.
  40. * \param rate The sampling rate of the source audio.
  41. * \param max_bitrate Desired maximum bitrate (limit). -1 indicates unset.
  42. * \param nominal_bitrate Desired average, or central, bitrate. -1 indicates unset.
  43. * \param min_bitrate Desired minimum bitrate. -1 indicates unset.
  44. *
  45. * \return Zero for success, and negative values for failure.
  46. *
  47. * \retval 0 Success.
  48. * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
  49. * \retval OV_EINVAL Invalid setup request, eg, out of range argument.
  50. * \retval OV_EIMPL Unimplemented mode; unable to comply with bitrate request.
  51. */
  52. extern int vorbis_encode_init(vorbis_info *vi,
  53. long channels,
  54. long rate,
  55. long max_bitrate,
  56. long nominal_bitrate,
  57. long min_bitrate);
  58. /**
  59. * This function performs step-one of a three-step bitrate-managed encode
  60. * setup. It functions similarly to the one-step setup performed by \ref
  61. * vorbis_encode_init but allows an application to make further encode setup
  62. * tweaks using \ref vorbis_encode_ctl before finally calling \ref
  63. * vorbis_encode_setup_init to complete the setup process.
  64. *
  65. * Before this function is called, the \ref vorbis_info struct should be
  66. * initialized by using vorbis_info_init() from the libvorbis API. After
  67. * encoding, vorbis_info_clear() should be called.
  68. *
  69. * The max_bitrate, nominal_bitrate, and min_bitrate settings are used to set
  70. * constraints for the encoded file. This function uses these settings to
  71. * select the appropriate encoding mode and set it up.
  72. *
  73. * \param vi Pointer to an initialized vorbis_info struct.
  74. * \param channels The number of channels to be encoded.
  75. * \param rate The sampling rate of the source audio.
  76. * \param max_bitrate Desired maximum bitrate (limit). -1 indicates unset.
  77. * \param nominal_bitrate Desired average, or central, bitrate. -1 indicates unset.
  78. * \param min_bitrate Desired minimum bitrate. -1 indicates unset.
  79. *
  80. * \return Zero for success, and negative for failure.
  81. *
  82. * \retval 0 Success
  83. * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
  84. * \retval OV_EINVAL Invalid setup request, eg, out of range argument.
  85. * \retval OV_EIMPL Unimplemented mode; unable to comply with bitrate request.
  86. */
  87. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  88. long channels,
  89. long rate,
  90. long max_bitrate,
  91. long nominal_bitrate,
  92. long min_bitrate);
  93. /**
  94. * This function performs step-one of a three-step variable bitrate
  95. * (quality-based) encode setup. It functions similarly to the one-step setup
  96. * performed by \ref vorbis_encode_init_vbr() but allows an application to
  97. * make further encode setup tweaks using \ref vorbis_encode_ctl() before
  98. * finally calling \ref vorbis_encode_setup_init to complete the setup
  99. * process.
  100. *
  101. * Before this function is called, the \ref vorbis_info struct should be
  102. * initialized by using \ref vorbis_info_init() from the libvorbis API. After
  103. * encoding, vorbis_info_clear() should be called.
  104. *
  105. * \param vi Pointer to an initialized vorbis_info struct.
  106. * \param channels The number of channels to be encoded.
  107. * \param rate The sampling rate of the source audio.
  108. * \param quality Desired quality level, currently from -0.1 to 1.0 (lo to hi).
  109. *
  110. * \return Zero for success, and negative values for failure.
  111. *
  112. * \retval 0 Success
  113. * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
  114. * \retval OV_EINVAL Invalid setup request, eg, out of range argument.
  115. * \retval OV_EIMPL Unimplemented mode; unable to comply with quality level request.
  116. */
  117. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  118. long channels,
  119. long rate,
  120. float quality
  121. );
  122. /**
  123. * This is the primary function within libvorbisenc for setting up variable
  124. * bitrate ("quality" based) modes.
  125. *
  126. *
  127. * Before this function is called, the vorbis_info struct should be
  128. * initialized by using vorbis_info_init() from the libvorbis API. After
  129. * encoding, vorbis_info_clear() should be called.
  130. *
  131. * \param vi Pointer to an initialized vorbis_info struct.
  132. * \param channels The number of channels to be encoded.
  133. * \param rate The sampling rate of the source audio.
  134. * \param base_quality Desired quality level, currently from -0.1 to 1.0 (lo to hi).
  135. *
  136. *
  137. * \return Zero for success, or a negative number for failure.
  138. *
  139. * \retval 0 Success
  140. * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
  141. * \retval OV_EINVAL Invalid setup request, eg, out of range argument.
  142. * \retval OV_EIMPL Unimplemented mode; unable to comply with quality level request.
  143. */
  144. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  145. long channels,
  146. long rate,
  147. float base_quality
  148. );
  149. /**
  150. * This function performs the last stage of three-step encoding setup, as
  151. * described in the API overview under managed bitrate modes.
  152. *
  153. * Before this function is called, the \ref vorbis_info struct should be
  154. * initialized by using vorbis_info_init() from the libvorbis API, one of
  155. * \ref vorbis_encode_setup_managed() or \ref vorbis_encode_setup_vbr() called to
  156. * initialize the high-level encoding setup, and \ref vorbis_encode_ctl()
  157. * called if necessary to make encoding setup changes.
  158. * vorbis_encode_setup_init() finalizes the highlevel encoding structure into
  159. * a complete encoding setup after which the application may make no further
  160. * setup changes.
  161. *
  162. * After encoding, vorbis_info_clear() should be called.
  163. *
  164. * \param vi Pointer to an initialized \ref vorbis_info struct.
  165. *
  166. * \return Zero for success, and negative values for failure.
  167. *
  168. * \retval 0 Success.
  169. * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
  170. *
  171. * \retval OV_EINVAL Attempt to use vorbis_encode_setup_init() without first
  172. * calling one of vorbis_encode_setup_managed() or vorbis_encode_setup_vbr() to
  173. * initialize the high-level encoding setup
  174. *
  175. */
  176. extern int vorbis_encode_setup_init(vorbis_info *vi);
  177. /**
  178. * This function implements a generic interface to miscellaneous encoder
  179. * settings similar to the classic UNIX 'ioctl()' system call. Applications
  180. * may use vorbis_encode_ctl() to query or set bitrate management or quality
  181. * mode details by using one of several \e request arguments detailed below.
  182. * vorbis_encode_ctl() must be called after one of
  183. * vorbis_encode_setup_managed() or vorbis_encode_setup_vbr(). When used
  184. * to modify settings, \ref vorbis_encode_ctl() must be called before \ref
  185. * vorbis_encode_setup_init().
  186. *
  187. * \param vi Pointer to an initialized vorbis_info struct.
  188. *
  189. * \param number Specifies the desired action; See \ref encctlcodes "the list
  190. * of available requests".
  191. *
  192. * \param arg void * pointing to a data structure matching the request
  193. * argument.
  194. *
  195. * \retval 0 Success. Any further return information (such as the result of a
  196. * query) is placed into the storage pointed to by *arg.
  197. *
  198. * \retval OV_EINVAL Invalid argument, or an attempt to modify a setting after
  199. * calling vorbis_encode_setup_init().
  200. *
  201. * \retval OV_EIMPL Unimplemented or unknown request
  202. */
  203. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  204. /**
  205. * \deprecated This is a deprecated interface. Please use vorbis_encode_ctl()
  206. * with the \ref ovectl_ratemanage2_arg struct and \ref
  207. * OV_ECTL_RATEMANAGE2_GET and \ref OV_ECTL_RATEMANAGE2_SET calls in new code.
  208. *
  209. * The \ref ovectl_ratemanage_arg structure is used with vorbis_encode_ctl()
  210. * and the \ref OV_ECTL_RATEMANAGE_GET, \ref OV_ECTL_RATEMANAGE_SET, \ref
  211. * OV_ECTL_RATEMANAGE_AVG, \ref OV_ECTL_RATEMANAGE_HARD calls in order to
  212. * query and modify specifics of the encoder's bitrate management
  213. * configuration.
  214. */
  215. struct ovectl_ratemanage_arg {
  216. int management_active; /**< nonzero if bitrate management is active*/
  217. /** hard lower limit (in kilobits per second) below which the stream bitrate
  218. will never be allowed for any given bitrate_hard_window seconds of time.*/
  219. long bitrate_hard_min;
  220. /** hard upper limit (in kilobits per second) above which the stream bitrate
  221. will never be allowed for any given bitrate_hard_window seconds of time.*/
  222. long bitrate_hard_max;
  223. /** the window period (in seconds) used to regulate the hard bitrate minimum
  224. and maximum*/
  225. double bitrate_hard_window;
  226. /** soft lower limit (in kilobits per second) below which the average bitrate
  227. tracker will start nudging the bitrate higher.*/
  228. long bitrate_av_lo;
  229. /** soft upper limit (in kilobits per second) above which the average bitrate
  230. tracker will start nudging the bitrate lower.*/
  231. long bitrate_av_hi;
  232. /** the window period (in seconds) used to regulate the average bitrate
  233. minimum and maximum.*/
  234. double bitrate_av_window;
  235. /** Regulates the relative centering of the average and hard windows; in
  236. libvorbis 1.0 and 1.0.1, the hard window regulation overlapped but
  237. followed the average window regulation. In libvorbis 1.1 a bit-reservoir
  238. interface replaces the old windowing interface; the older windowing
  239. interface is simulated and this field has no effect.*/
  240. double bitrate_av_window_center;
  241. };
  242. /**
  243. * \name struct ovectl_ratemanage2_arg
  244. *
  245. * The ovectl_ratemanage2_arg structure is used with vorbis_encode_ctl() and
  246. * the OV_ECTL_RATEMANAGE2_GET and OV_ECTL_RATEMANAGE2_SET calls in order to
  247. * query and modify specifics of the encoder's bitrate management
  248. * configuration.
  249. *
  250. */
  251. struct ovectl_ratemanage2_arg {
  252. int management_active; /**< nonzero if bitrate management is active */
  253. /** Lower allowed bitrate limit in kilobits per second */
  254. long bitrate_limit_min_kbps;
  255. /** Upper allowed bitrate limit in kilobits per second */
  256. long bitrate_limit_max_kbps;
  257. long bitrate_limit_reservoir_bits; /**<Size of the bitrate reservoir in bits */
  258. /** Regulates the bitrate reservoir's preferred fill level in a range from 0.0
  259. * to 1.0; 0.0 tries to bank bits to buffer against future bitrate spikes, 1.0
  260. * buffers against future sudden drops in instantaneous bitrate. Default is
  261. * 0.1
  262. */
  263. double bitrate_limit_reservoir_bias;
  264. /** Average bitrate setting in kilobits per second */
  265. long bitrate_average_kbps;
  266. /** Slew rate limit setting for average bitrate adjustment; sets the minimum
  267. * time in seconds the bitrate tracker may swing from one extreme to the
  268. * other when boosting or damping average bitrate.
  269. */
  270. double bitrate_average_damping;
  271. };
  272. /**
  273. * \name vorbis_encode_ctl() codes
  274. *
  275. * \anchor encctlcodes
  276. *
  277. * These values are passed as the \c number parameter of vorbis_encode_ctl().
  278. * The type of the referent of that function's \c arg pointer depends on these
  279. * codes.
  280. */
  281. /*@{*/
  282. /**
  283. * Query the current encoder bitrate management setting.
  284. *
  285. *Argument: <tt>struct ovectl_ratemanage2_arg *</tt>
  286. *
  287. * Used to query the current encoder bitrate management setting. Also used to
  288. * initialize fields of an ovectl_ratemanage2_arg structure for use with
  289. * \ref OV_ECTL_RATEMANAGE2_SET.
  290. */
  291. #define OV_ECTL_RATEMANAGE2_GET 0x14
  292. /**
  293. * Set the current encoder bitrate management settings.
  294. *
  295. * Argument: <tt>struct ovectl_ratemanage2_arg *</tt>
  296. *
  297. * Used to set the current encoder bitrate management settings to the values
  298. * listed in the ovectl_ratemanage2_arg. Passing a NULL pointer will disable
  299. * bitrate management.
  300. */
  301. #define OV_ECTL_RATEMANAGE2_SET 0x15
  302. /**
  303. * Returns the current encoder hard-lowpass setting (kHz) in the double
  304. * pointed to by arg.
  305. *
  306. * Argument: <tt>double *</tt>
  307. */
  308. #define OV_ECTL_LOWPASS_GET 0x20
  309. /**
  310. * Sets the encoder hard-lowpass to the value (kHz) pointed to by arg. Valid
  311. * lowpass settings range from 2 to 99.
  312. *
  313. * Argument: <tt>double *</tt>
  314. */
  315. #define OV_ECTL_LOWPASS_SET 0x21
  316. /**
  317. * Returns the current encoder impulse block setting in the double pointed
  318. * to by arg.
  319. *
  320. * Argument: <tt>double *</tt>
  321. */
  322. #define OV_ECTL_IBLOCK_GET 0x30
  323. /**
  324. * Sets the impulse block bias to the the value pointed to by arg.
  325. *
  326. * Argument: <tt>double *</tt>
  327. *
  328. * Valid range is -15.0 to 0.0 [default]. A negative impulse block bias will
  329. * direct to encoder to use more bits when incoding short blocks that contain
  330. * strong impulses, thus improving the accuracy of impulse encoding.
  331. */
  332. #define OV_ECTL_IBLOCK_SET 0x31
  333. /**
  334. * Returns the current encoder coupling setting in the int pointed
  335. * to by arg.
  336. *
  337. * Argument: <tt>int *</tt>
  338. */
  339. #define OV_ECTL_COUPLING_GET 0x40
  340. /**
  341. * Enables/disables channel coupling in multichannel encoding according to arg.
  342. *
  343. * Argument: <tt>int *</tt>
  344. *
  345. * Zero disables channel coupling for multichannel inputs, nonzer enables
  346. * channel coupling. Setting has no effect on monophonic encoding or
  347. * multichannel counts that do not offer coupling. At present, coupling is
  348. * available for stereo and 5.1 encoding.
  349. */
  350. #define OV_ECTL_COUPLING_SET 0x41
  351. /* deprecated rate management supported only for compatibility */
  352. /**
  353. * Old interface to querying bitrate management settings.
  354. *
  355. * Deprecated after move to bit-reservoir style management in 1.1 rendered
  356. * this interface partially obsolete.
  357. * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_GET instead.
  358. *
  359. * Argument: <tt>struct ovectl_ratemanage_arg *</tt>
  360. */
  361. #define OV_ECTL_RATEMANAGE_GET 0x10
  362. /**
  363. * Old interface to modifying bitrate management settings.
  364. *
  365. * deprecated after move to bit-reservoir style management in 1.1 rendered
  366. * this interface partially obsolete.
  367. *
  368. * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.
  369. *
  370. * Argument: <tt>struct ovectl_ratemanage_arg *</tt>
  371. */
  372. #define OV_ECTL_RATEMANAGE_SET 0x11
  373. /**
  374. * Old interface to setting average-bitrate encoding mode.
  375. *
  376. * Deprecated after move to bit-reservoir style management in 1.1 rendered
  377. * this interface partially obsolete.
  378. *
  379. * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.
  380. *
  381. * Argument: <tt>struct ovectl_ratemanage_arg *</tt>
  382. */
  383. #define OV_ECTL_RATEMANAGE_AVG 0x12
  384. /**
  385. * Old interface to setting bounded-bitrate encoding modes.
  386. *
  387. * deprecated after move to bit-reservoir style management in 1.1 rendered
  388. * this interface partially obsolete.
  389. *
  390. * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.
  391. *
  392. * Argument: <tt>struct ovectl_ratemanage_arg *</tt>
  393. */
  394. #define OV_ECTL_RATEMANAGE_HARD 0x13
  395. /*@}*/
  396. #ifdef __cplusplus
  397. }
  398. #endif /* __cplusplus */
  399. #endif