1 /********************************************************************
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. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
11 ********************************************************************
13 function: vorbis encode-engine setup
16 ********************************************************************/
19 * Libvorbisenc is a convenient API for setting up an encoding
20 * environment using libvorbis. Libvorbisenc encapsulates the
21 * actions needed to set up the encoder properly.
30 #endif /* __cplusplus */
35 * This is the primary function within libvorbisenc for setting up managed
38 * Before this function is called, the \ref vorbis_info
39 * struct should be initialized by using vorbis_info_init() from the libvorbis
40 * API. After encoding, vorbis_info_clear() should be called.
42 * The max_bitrate, nominal_bitrate, and min_bitrate settings are used to set
43 * constraints for the encoded file. This function uses these settings to
44 * select the appropriate encoding mode and set it up.
46 * \param vi Pointer to an initialized \ref vorbis_info struct.
47 * \param channels The number of channels to be encoded.
48 * \param rate The sampling rate of the source audio.
49 * \param max_bitrate Desired maximum bitrate (limit). -1 indicates unset.
50 * \param nominal_bitrate Desired average, or central, bitrate. -1 indicates unset.
51 * \param min_bitrate Desired minimum bitrate. -1 indicates unset.
53 * \return Zero for success, and negative values for failure.
56 * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
57 * \retval OV_EINVAL Invalid setup request, eg, out of range argument.
58 * \retval OV_EIMPL Unimplemented mode; unable to comply with bitrate request.
60 extern int vorbis_encode_init(vorbis_info *vi,
69 * This function performs step-one of a three-step bitrate-managed encode
70 * setup. It functions similarly to the one-step setup performed by \ref
71 * vorbis_encode_init but allows an application to make further encode setup
72 * tweaks using \ref vorbis_encode_ctl before finally calling \ref
73 * vorbis_encode_setup_init to complete the setup process.
75 * Before this function is called, the \ref vorbis_info struct should be
76 * initialized by using vorbis_info_init() from the libvorbis API. After
77 * encoding, vorbis_info_clear() should be called.
79 * The max_bitrate, nominal_bitrate, and min_bitrate settings are used to set
80 * constraints for the encoded file. This function uses these settings to
81 * select the appropriate encoding mode and set it up.
83 * \param vi Pointer to an initialized vorbis_info struct.
84 * \param channels The number of channels to be encoded.
85 * \param rate The sampling rate of the source audio.
86 * \param max_bitrate Desired maximum bitrate (limit). -1 indicates unset.
87 * \param nominal_bitrate Desired average, or central, bitrate. -1 indicates unset.
88 * \param min_bitrate Desired minimum bitrate. -1 indicates unset.
90 * \return Zero for success, and negative for failure.
93 * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
94 * \retval OV_EINVAL Invalid setup request, eg, out of range argument.
95 * \retval OV_EIMPL Unimplemented mode; unable to comply with bitrate request.
97 extern int vorbis_encode_setup_managed(vorbis_info *vi,
102 long nominal_bitrate,
106 * This function performs step-one of a three-step variable bitrate
107 * (quality-based) encode setup. It functions similarly to the one-step setup
108 * performed by \ref vorbis_encode_init_vbr() but allows an application to
109 * make further encode setup tweaks using \ref vorbis_encode_ctl() before
110 * finally calling \ref vorbis_encode_setup_init to complete the setup
113 * Before this function is called, the \ref vorbis_info struct should be
114 * initialized by using \ref vorbis_info_init() from the libvorbis API. After
115 * encoding, vorbis_info_clear() should be called.
117 * \param vi Pointer to an initialized vorbis_info struct.
118 * \param channels The number of channels to be encoded.
119 * \param rate The sampling rate of the source audio.
120 * \param quality Desired quality level, currently from -0.1 to 1.0 (lo to hi).
122 * \return Zero for success, and negative values for failure.
125 * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
126 * \retval OV_EINVAL Invalid setup request, eg, out of range argument.
127 * \retval OV_EIMPL Unimplemented mode; unable to comply with quality level request.
129 extern int vorbis_encode_setup_vbr(vorbis_info *vi,
133 float quality /* quality level from 0. (lo) to 1. (hi) */
137 * This is the primary function within libvorbisenc for setting up variable
138 * bitrate ("quality" based) modes.
141 * Before this function is called, the vorbis_info struct should be
142 * initialized by using vorbis_info_init() from the libvorbis API. After
143 * encoding, vorbis_info_clear() should be called.
145 * \param vi Pointer to an initialized vorbis_info struct.
146 * \param channels The number of channels to be encoded.
147 * \param rate The sampling rate of the source audio.
148 * \param base_quality Desired quality level, currently from -0.1 to 1.0 (lo to hi).
151 * \return Zero for success, or a negative number for failure.
154 * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
155 * \retval OV_EINVAL Invalid setup request, eg, out of range argument.
156 * \retval OV_EIMPL Unimplemented mode; unable to comply with quality level request.
158 extern int vorbis_encode_init_vbr(vorbis_info *vi,
162 float base_quality /* quality level from 0. (lo) to 1. (hi) */
166 * This function performs the last stage of three-step encoding setup, as
167 * described in the API overview under managed bitrate modes.
169 * Before this function is called, the \ref vorbis_info struct should be
170 * initialized by using vorbis_info_init() from the libvorbis API, one of
171 * \ref vorbis_encode_setup_managed() or \ref vorbis_encode_setup_vbr() called to
172 * initialize the high-level encoding setup, and \ref vorbis_encode_ctl()
173 * called if necessary to make encoding setup changes.
174 * vorbis_encode_setup_init() finalizes the highlevel encoding structure into
175 * a complete encoding setup after which the application may make no further
178 * After encoding, vorbis_info_clear() should be called.
180 * \param vi Pointer to an initialized \ref vorbis_info struct.
182 * \return Zero for success, and negative values for failure.
185 * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.
187 * \retval OV_EINVAL Attempt to use vorbis_encode_setup_init() without first
188 * calling one of vorbis_encode_setup_managed() or vorbis_encode_setup_vbr() to
189 * initialize the high-level encoding setup
192 extern int vorbis_encode_setup_init(vorbis_info *vi);
195 * This function implements a generic interface to miscellaneous encoder
196 * settings similar to the classic UNIX 'ioctl()' system call. Applications
197 * may use vorbis_encode_ctl() to query or set bitrate management or quality
198 * mode details by using one of several \e request arguments detailed below.
199 * vorbis_encode_ctl() must be called after one of
200 * vorbis_encode_setup_managed() or vorbis_encode_setup_vbr(). When used
201 * to modify settings, \ref vorbis_encode_ctl() must be called before \ref
202 * vorbis_encode_setup_init().
204 * \param vi Pointer to an initialized vorbis_info struct.
206 * \param number Specifies the desired action; See \ref encctlcodes "the list
207 * of available requests".
209 * \param arg void * pointing to a data structure matching the request
212 * \retval 0 Success. Any further return information (such as the result of a
213 * query) is placed into the storage pointed to by *arg.
215 * \retval OV_EINVAL Invalid argument, or an attempt to modify a setting after
216 * calling vorbis_encode_setup_init().
218 * \retval OV_EIMPL Unimplemented or unknown request
220 extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
223 * \deprecated This is a deprecated interface. Please use vorbis_encode_ctl()
224 * with the \ref ovectl_ratemanage2_arg struct and \ref
225 * OV_ECTL_RATEMANAGE2_GET and \ref OV_ECTL_RATEMANAGE2_SET calls in new code.
227 * The \ref ovectl_ratemanage_arg structure is used with vorbis_encode_ctl()
228 * and the \ref OV_ECTL_RATEMANAGE_GET, \ref OV_ECTL_RATEMANAGE_SET, \ref
229 * OV_ECTL_RATEMANAGE_AVG, \ref OV_ECTL_RATEMANAGE_HARD calls in order to
230 * query and modify specifics of the encoder's bitrate management
233 struct ovectl_ratemanage_arg {
234 int management_active; /**< nonzero if bitrate management is active*/
235 /** hard lower limit (in kilobits per second) below which the stream bitrate
236 will never be allowed for any given bitrate_hard_window seconds of time.*/
237 long bitrate_hard_min;
238 /** hard upper limit (in kilobits per second) above which the stream bitrate
239 will never be allowed for any given bitrate_hard_window seconds of time.*/
240 long bitrate_hard_max;
241 /** the window period (in seconds) used to regulate the hard bitrate minimum
243 double bitrate_hard_window;
244 /** soft lower limit (in kilobits per second) below which the average bitrate
245 tracker will start nudging the bitrate higher.*/
247 /** soft upper limit (in kilobits per second) above which the average bitrate
248 tracker will start nudging the bitrate lower.*/
250 /** the window period (in seconds) used to regulate the average bitrate
251 minimum and maximum.*/
252 double bitrate_av_window;
253 /** Regulates the relative centering of the average and hard windows; in
254 libvorbis 1.0 and 1.0.1, the hard window regulation overlapped but
255 followed the average window regulation. In libvorbis 1.1 a bit-reservoir
256 interface replaces the old windowing interface; the older windowing
257 interface is simulated and this field has no effect.*/
258 double bitrate_av_window_center;
262 * \name struct ovectl_ratemanage2_arg
264 * The ovectl_ratemanage2_arg structure is used with vorbis_encode_ctl() and
265 * the OV_ECTL_RATEMANAGE2_GET and OV_ECTL_RATEMANAGE2_SET calls in order to
266 * query and modify specifics of the encoder's bitrate management
270 struct ovectl_ratemanage2_arg {
271 int management_active; /**< nonzero if bitrate management is active */
272 /** Lower allowed bitrate limit in kilobits per second */
273 long bitrate_limit_min_kbps;
274 /** Upper allowed bitrate limit in kilobits per second */
275 long bitrate_limit_max_kbps;
276 long bitrate_limit_reservoir_bits; /**<Size of the bitrate reservoir in bits */
277 /** Regulates the bitrate reservoir's preferred fill level in a range from 0.0
278 * to 1.0; 0.0 tries to bank bits to buffer against future bitrate spikes, 1.0
279 * buffers against future sudden drops in instantaneous bitrate. Default is
282 double bitrate_limit_reservoir_bias;
283 /** Average bitrate setting in kilobits per second */
284 long bitrate_average_kbps;
285 /** Slew rate limit setting for average bitrate adjustment; sets the minimum
286 * time in seconds the bitrate tracker may swing from one extreme to the
287 * other when boosting or damping average bitrate.
289 double bitrate_average_damping;
294 * \name vorbis_encode_ctl() codes
296 * \anchor encctlcodes
298 * These values are passed as the \c number parameter of vorbis_encode_ctl().
299 * The type of the referent of that function's \c arg pointer depends on these
305 * Query the current encoder bitrate management setting.
307 *Argument: <tt>struct ovectl_ratemanage2_arg *</tt>
309 * Used to query the current encoder bitrate management setting. Also used to
310 * initialize fields of an ovectl_ratemanage2_arg structure for use with
311 * \ref OV_ECTL_RATEMANAGE2_SET.
313 #define OV_ECTL_RATEMANAGE2_GET 0x14
316 * Set the current encoder bitrate management settings.
318 * Argument: <tt>struct ovectl_ratemanage2_arg *</tt>
320 * Used to set the current encoder bitrate management settings to the values
321 * listed in the ovectl_ratemanage2_arg. Passing a NULL pointer will disable
322 * bitrate management.
324 #define OV_ECTL_RATEMANAGE2_SET 0x15
327 * Returns the current encoder hard-lowpass setting (kHz) in the double
330 * Argument: <tt>double *</tt>
332 #define OV_ECTL_LOWPASS_GET 0x20
335 * Sets the encoder hard-lowpass to the value (kHz) pointed to by arg. Valid
336 * lowpass settings range from 2 to 99.
338 * Argument: <tt>double *</tt>
340 #define OV_ECTL_LOWPASS_SET 0x21
343 * Returns the current encoder impulse block setting in the double pointed
346 * Argument: <tt>double *</tt>
348 #define OV_ECTL_IBLOCK_GET 0x30
351 * Sets the impulse block bias to the the value pointed to by arg.
353 * Argument: <tt>double *</tt>
355 * Valid range is -15.0 to 0.0 [default]. A negative impulse block bias will
356 * direct to encoder to use more bits when incoding short blocks that contain
357 * strong impulses, thus improving the accuracy of impulse encoding.
359 #define OV_ECTL_IBLOCK_SET 0x31
361 /* deprecated rate management supported only for compatability */
364 * Old interface to querying bitrate management settings.
366 * Deprecated after move to bit-reservoir style management in 1.1 rendered
367 * this interface partially obsolete.
369 * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_GET instead.
371 * Argument: <tt>struct ovectl_ratemanage_arg *</tt>
373 #define OV_ECTL_RATEMANAGE_GET 0x10
375 * Old interface to modifying bitrate management settings.
377 * deprecated after move to bit-reservoir style management in 1.1 rendered
378 * this interface partially obsolete.
380 * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.
382 * Argument: <tt>struct ovectl_ratemanage_arg *</tt>
384 #define OV_ECTL_RATEMANAGE_SET 0x11
386 * Old interface to setting average-bitrate encoding mode.
388 * Deprecated after move to bit-reservoir style management in 1.1 rendered
389 * this interface partially obsolete.
391 * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.
393 * Argument: <tt>struct ovectl_ratemanage_arg *</tt>
395 #define OV_ECTL_RATEMANAGE_AVG 0x12
397 * Old interface to setting bounded-bitrate encoding modes.
399 * deprecated after move to bit-reservoir style management in 1.1 rendered
400 * this interface partially obsolete.
402 * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.
404 * Argument: <tt>struct ovectl_ratemanage_arg *</tt>
406 #define OV_ECTL_RATEMANAGE_HARD 0x13
414 #endif /* __cplusplus */