cannam@88: /******************************************************************** cannam@88: * * cannam@88: * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * cannam@88: * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * cannam@88: * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * cannam@88: * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * cannam@88: * * cannam@88: * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 * cannam@88: * by the Xiph.Org Foundation http://www.xiph.org/ * cannam@88: * * cannam@88: ******************************************************************** cannam@88: cannam@88: function: vorbis encode-engine setup cannam@88: last mod: $Id: vorbisenc.h 17021 2010-03-24 09:29:41Z xiphmont $ cannam@88: cannam@88: ********************************************************************/ cannam@88: cannam@88: /** \file cannam@88: * Libvorbisenc is a convenient API for setting up an encoding cannam@88: * environment using libvorbis. Libvorbisenc encapsulates the cannam@88: * actions needed to set up the encoder properly. cannam@88: */ cannam@88: cannam@88: #ifndef _OV_ENC_H_ cannam@88: #define _OV_ENC_H_ cannam@88: cannam@88: #ifdef __cplusplus cannam@88: extern "C" cannam@88: { cannam@88: #endif /* __cplusplus */ cannam@88: cannam@88: #include "codec.h" cannam@88: cannam@88: /** cannam@88: * This is the primary function within libvorbisenc for setting up managed cannam@88: * bitrate modes. cannam@88: * cannam@88: * Before this function is called, the \ref vorbis_info cannam@88: * struct should be initialized by using vorbis_info_init() from the libvorbis cannam@88: * API. After encoding, vorbis_info_clear() should be called. cannam@88: * cannam@88: * The max_bitrate, nominal_bitrate, and min_bitrate settings are used to set cannam@88: * constraints for the encoded file. This function uses these settings to cannam@88: * select the appropriate encoding mode and set it up. cannam@88: * cannam@88: * \param vi Pointer to an initialized \ref vorbis_info struct. cannam@88: * \param channels The number of channels to be encoded. cannam@88: * \param rate The sampling rate of the source audio. cannam@88: * \param max_bitrate Desired maximum bitrate (limit). -1 indicates unset. cannam@88: * \param nominal_bitrate Desired average, or central, bitrate. -1 indicates unset. cannam@88: * \param min_bitrate Desired minimum bitrate. -1 indicates unset. cannam@88: * cannam@88: * \return Zero for success, and negative values for failure. cannam@88: * cannam@88: * \retval 0 Success. cannam@88: * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption. cannam@88: * \retval OV_EINVAL Invalid setup request, eg, out of range argument. cannam@88: * \retval OV_EIMPL Unimplemented mode; unable to comply with bitrate request. cannam@88: */ cannam@88: extern int vorbis_encode_init(vorbis_info *vi, cannam@88: long channels, cannam@88: long rate, cannam@88: cannam@88: long max_bitrate, cannam@88: long nominal_bitrate, cannam@88: long min_bitrate); cannam@88: cannam@88: /** cannam@88: * This function performs step-one of a three-step bitrate-managed encode cannam@88: * setup. It functions similarly to the one-step setup performed by \ref cannam@88: * vorbis_encode_init but allows an application to make further encode setup cannam@88: * tweaks using \ref vorbis_encode_ctl before finally calling \ref cannam@88: * vorbis_encode_setup_init to complete the setup process. cannam@88: * cannam@88: * Before this function is called, the \ref vorbis_info struct should be cannam@88: * initialized by using vorbis_info_init() from the libvorbis API. After cannam@88: * encoding, vorbis_info_clear() should be called. cannam@88: * cannam@88: * The max_bitrate, nominal_bitrate, and min_bitrate settings are used to set cannam@88: * constraints for the encoded file. This function uses these settings to cannam@88: * select the appropriate encoding mode and set it up. cannam@88: * cannam@88: * \param vi Pointer to an initialized vorbis_info struct. cannam@88: * \param channels The number of channels to be encoded. cannam@88: * \param rate The sampling rate of the source audio. cannam@88: * \param max_bitrate Desired maximum bitrate (limit). -1 indicates unset. cannam@88: * \param nominal_bitrate Desired average, or central, bitrate. -1 indicates unset. cannam@88: * \param min_bitrate Desired minimum bitrate. -1 indicates unset. cannam@88: * cannam@88: * \return Zero for success, and negative for failure. cannam@88: * cannam@88: * \retval 0 Success cannam@88: * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption. cannam@88: * \retval OV_EINVAL Invalid setup request, eg, out of range argument. cannam@88: * \retval OV_EIMPL Unimplemented mode; unable to comply with bitrate request. cannam@88: */ cannam@88: extern int vorbis_encode_setup_managed(vorbis_info *vi, cannam@88: long channels, cannam@88: long rate, cannam@88: cannam@88: long max_bitrate, cannam@88: long nominal_bitrate, cannam@88: long min_bitrate); cannam@88: cannam@88: /** cannam@88: * This function performs step-one of a three-step variable bitrate cannam@88: * (quality-based) encode setup. It functions similarly to the one-step setup cannam@88: * performed by \ref vorbis_encode_init_vbr() but allows an application to cannam@88: * make further encode setup tweaks using \ref vorbis_encode_ctl() before cannam@88: * finally calling \ref vorbis_encode_setup_init to complete the setup cannam@88: * process. cannam@88: * cannam@88: * Before this function is called, the \ref vorbis_info struct should be cannam@88: * initialized by using \ref vorbis_info_init() from the libvorbis API. After cannam@88: * encoding, vorbis_info_clear() should be called. cannam@88: * cannam@88: * \param vi Pointer to an initialized vorbis_info struct. cannam@88: * \param channels The number of channels to be encoded. cannam@88: * \param rate The sampling rate of the source audio. cannam@88: * \param quality Desired quality level, currently from -0.1 to 1.0 (lo to hi). cannam@88: * cannam@88: * \return Zero for success, and negative values for failure. cannam@88: * cannam@88: * \retval 0 Success cannam@88: * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption. cannam@88: * \retval OV_EINVAL Invalid setup request, eg, out of range argument. cannam@88: * \retval OV_EIMPL Unimplemented mode; unable to comply with quality level request. cannam@88: */ cannam@88: extern int vorbis_encode_setup_vbr(vorbis_info *vi, cannam@88: long channels, cannam@88: long rate, cannam@88: cannam@88: float quality cannam@88: ); cannam@88: cannam@88: /** cannam@88: * This is the primary function within libvorbisenc for setting up variable cannam@88: * bitrate ("quality" based) modes. cannam@88: * cannam@88: * cannam@88: * Before this function is called, the vorbis_info struct should be cannam@88: * initialized by using vorbis_info_init() from the libvorbis API. After cannam@88: * encoding, vorbis_info_clear() should be called. cannam@88: * cannam@88: * \param vi Pointer to an initialized vorbis_info struct. cannam@88: * \param channels The number of channels to be encoded. cannam@88: * \param rate The sampling rate of the source audio. cannam@88: * \param base_quality Desired quality level, currently from -0.1 to 1.0 (lo to hi). cannam@88: * cannam@88: * cannam@88: * \return Zero for success, or a negative number for failure. cannam@88: * cannam@88: * \retval 0 Success cannam@88: * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption. cannam@88: * \retval OV_EINVAL Invalid setup request, eg, out of range argument. cannam@88: * \retval OV_EIMPL Unimplemented mode; unable to comply with quality level request. cannam@88: */ cannam@88: extern int vorbis_encode_init_vbr(vorbis_info *vi, cannam@88: long channels, cannam@88: long rate, cannam@88: cannam@88: float base_quality cannam@88: ); cannam@88: cannam@88: /** cannam@88: * This function performs the last stage of three-step encoding setup, as cannam@88: * described in the API overview under managed bitrate modes. cannam@88: * cannam@88: * Before this function is called, the \ref vorbis_info struct should be cannam@88: * initialized by using vorbis_info_init() from the libvorbis API, one of cannam@88: * \ref vorbis_encode_setup_managed() or \ref vorbis_encode_setup_vbr() called to cannam@88: * initialize the high-level encoding setup, and \ref vorbis_encode_ctl() cannam@88: * called if necessary to make encoding setup changes. cannam@88: * vorbis_encode_setup_init() finalizes the highlevel encoding structure into cannam@88: * a complete encoding setup after which the application may make no further cannam@88: * setup changes. cannam@88: * cannam@88: * After encoding, vorbis_info_clear() should be called. cannam@88: * cannam@88: * \param vi Pointer to an initialized \ref vorbis_info struct. cannam@88: * cannam@88: * \return Zero for success, and negative values for failure. cannam@88: * cannam@88: * \retval 0 Success. cannam@88: * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption. cannam@88: * cannam@88: * \retval OV_EINVAL Attempt to use vorbis_encode_setup_init() without first cannam@88: * calling one of vorbis_encode_setup_managed() or vorbis_encode_setup_vbr() to cannam@88: * initialize the high-level encoding setup cannam@88: * cannam@88: */ cannam@88: extern int vorbis_encode_setup_init(vorbis_info *vi); cannam@88: cannam@88: /** cannam@88: * This function implements a generic interface to miscellaneous encoder cannam@88: * settings similar to the classic UNIX 'ioctl()' system call. Applications cannam@88: * may use vorbis_encode_ctl() to query or set bitrate management or quality cannam@88: * mode details by using one of several \e request arguments detailed below. cannam@88: * vorbis_encode_ctl() must be called after one of cannam@88: * vorbis_encode_setup_managed() or vorbis_encode_setup_vbr(). When used cannam@88: * to modify settings, \ref vorbis_encode_ctl() must be called before \ref cannam@88: * vorbis_encode_setup_init(). cannam@88: * cannam@88: * \param vi Pointer to an initialized vorbis_info struct. cannam@88: * cannam@88: * \param number Specifies the desired action; See \ref encctlcodes "the list cannam@88: * of available requests". cannam@88: * cannam@88: * \param arg void * pointing to a data structure matching the request cannam@88: * argument. cannam@88: * cannam@88: * \retval 0 Success. Any further return information (such as the result of a cannam@88: * query) is placed into the storage pointed to by *arg. cannam@88: * cannam@88: * \retval OV_EINVAL Invalid argument, or an attempt to modify a setting after cannam@88: * calling vorbis_encode_setup_init(). cannam@88: * cannam@88: * \retval OV_EIMPL Unimplemented or unknown request cannam@88: */ cannam@88: extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg); cannam@88: cannam@88: /** cannam@88: * \deprecated This is a deprecated interface. Please use vorbis_encode_ctl() cannam@88: * with the \ref ovectl_ratemanage2_arg struct and \ref cannam@88: * OV_ECTL_RATEMANAGE2_GET and \ref OV_ECTL_RATEMANAGE2_SET calls in new code. cannam@88: * cannam@88: * The \ref ovectl_ratemanage_arg structure is used with vorbis_encode_ctl() cannam@88: * and the \ref OV_ECTL_RATEMANAGE_GET, \ref OV_ECTL_RATEMANAGE_SET, \ref cannam@88: * OV_ECTL_RATEMANAGE_AVG, \ref OV_ECTL_RATEMANAGE_HARD calls in order to cannam@88: * query and modify specifics of the encoder's bitrate management cannam@88: * configuration. cannam@88: */ cannam@88: struct ovectl_ratemanage_arg { cannam@88: int management_active; /**< nonzero if bitrate management is active*/ cannam@88: /** hard lower limit (in kilobits per second) below which the stream bitrate cannam@88: will never be allowed for any given bitrate_hard_window seconds of time.*/ cannam@88: long bitrate_hard_min; cannam@88: /** hard upper limit (in kilobits per second) above which the stream bitrate cannam@88: will never be allowed for any given bitrate_hard_window seconds of time.*/ cannam@88: long bitrate_hard_max; cannam@88: /** the window period (in seconds) used to regulate the hard bitrate minimum cannam@88: and maximum*/ cannam@88: double bitrate_hard_window; cannam@88: /** soft lower limit (in kilobits per second) below which the average bitrate cannam@88: tracker will start nudging the bitrate higher.*/ cannam@88: long bitrate_av_lo; cannam@88: /** soft upper limit (in kilobits per second) above which the average bitrate cannam@88: tracker will start nudging the bitrate lower.*/ cannam@88: long bitrate_av_hi; cannam@88: /** the window period (in seconds) used to regulate the average bitrate cannam@88: minimum and maximum.*/ cannam@88: double bitrate_av_window; cannam@88: /** Regulates the relative centering of the average and hard windows; in cannam@88: libvorbis 1.0 and 1.0.1, the hard window regulation overlapped but cannam@88: followed the average window regulation. In libvorbis 1.1 a bit-reservoir cannam@88: interface replaces the old windowing interface; the older windowing cannam@88: interface is simulated and this field has no effect.*/ cannam@88: double bitrate_av_window_center; cannam@88: }; cannam@88: cannam@88: /** cannam@88: * \name struct ovectl_ratemanage2_arg cannam@88: * cannam@88: * The ovectl_ratemanage2_arg structure is used with vorbis_encode_ctl() and cannam@88: * the OV_ECTL_RATEMANAGE2_GET and OV_ECTL_RATEMANAGE2_SET calls in order to cannam@88: * query and modify specifics of the encoder's bitrate management cannam@88: * configuration. cannam@88: * cannam@88: */ cannam@88: struct ovectl_ratemanage2_arg { cannam@88: int management_active; /**< nonzero if bitrate management is active */ cannam@88: /** Lower allowed bitrate limit in kilobits per second */ cannam@88: long bitrate_limit_min_kbps; cannam@88: /** Upper allowed bitrate limit in kilobits per second */ cannam@88: long bitrate_limit_max_kbps; cannam@88: long bitrate_limit_reservoir_bits; /**struct ovectl_ratemanage2_arg * cannam@88: * cannam@88: * Used to query the current encoder bitrate management setting. Also used to cannam@88: * initialize fields of an ovectl_ratemanage2_arg structure for use with cannam@88: * \ref OV_ECTL_RATEMANAGE2_SET. cannam@88: */ cannam@88: #define OV_ECTL_RATEMANAGE2_GET 0x14 cannam@88: cannam@88: /** cannam@88: * Set the current encoder bitrate management settings. cannam@88: * cannam@88: * Argument: struct ovectl_ratemanage2_arg * cannam@88: * cannam@88: * Used to set the current encoder bitrate management settings to the values cannam@88: * listed in the ovectl_ratemanage2_arg. Passing a NULL pointer will disable cannam@88: * bitrate management. cannam@88: */ cannam@88: #define OV_ECTL_RATEMANAGE2_SET 0x15 cannam@88: cannam@88: /** cannam@88: * Returns the current encoder hard-lowpass setting (kHz) in the double cannam@88: * pointed to by arg. cannam@88: * cannam@88: * Argument: double * cannam@88: */ cannam@88: #define OV_ECTL_LOWPASS_GET 0x20 cannam@88: cannam@88: /** cannam@88: * Sets the encoder hard-lowpass to the value (kHz) pointed to by arg. Valid cannam@88: * lowpass settings range from 2 to 99. cannam@88: * cannam@88: * Argument: double * cannam@88: */ cannam@88: #define OV_ECTL_LOWPASS_SET 0x21 cannam@88: cannam@88: /** cannam@88: * Returns the current encoder impulse block setting in the double pointed cannam@88: * to by arg. cannam@88: * cannam@88: * Argument: double * cannam@88: */ cannam@88: #define OV_ECTL_IBLOCK_GET 0x30 cannam@88: cannam@88: /** cannam@88: * Sets the impulse block bias to the the value pointed to by arg. cannam@88: * cannam@88: * Argument: double * cannam@88: * cannam@88: * Valid range is -15.0 to 0.0 [default]. A negative impulse block bias will cannam@88: * direct to encoder to use more bits when incoding short blocks that contain cannam@88: * strong impulses, thus improving the accuracy of impulse encoding. cannam@88: */ cannam@88: #define OV_ECTL_IBLOCK_SET 0x31 cannam@88: cannam@88: /** cannam@88: * Returns the current encoder coupling setting in the int pointed cannam@88: * to by arg. cannam@88: * cannam@88: * Argument: int * cannam@88: */ cannam@88: #define OV_ECTL_COUPLING_GET 0x40 cannam@88: cannam@88: /** cannam@88: * Enables/disables channel coupling in multichannel encoding according to arg. cannam@88: * cannam@88: * Argument: int * cannam@88: * cannam@88: * Zero disables channel coupling for multichannel inputs, nonzer enables cannam@88: * channel coupling. Setting has no effect on monophonic encoding or cannam@88: * multichannel counts that do not offer coupling. At present, coupling is cannam@88: * available for stereo and 5.1 encoding. cannam@88: */ cannam@88: #define OV_ECTL_COUPLING_SET 0x41 cannam@88: cannam@88: /* deprecated rate management supported only for compatibility */ cannam@88: cannam@88: /** cannam@88: * Old interface to querying bitrate management settings. cannam@88: * cannam@88: * Deprecated after move to bit-reservoir style management in 1.1 rendered cannam@88: * this interface partially obsolete. cannam@88: cannam@88: * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_GET instead. cannam@88: * cannam@88: * Argument: struct ovectl_ratemanage_arg * cannam@88: */ cannam@88: #define OV_ECTL_RATEMANAGE_GET 0x10 cannam@88: /** cannam@88: * Old interface to modifying bitrate management settings. cannam@88: * cannam@88: * deprecated after move to bit-reservoir style management in 1.1 rendered cannam@88: * this interface partially obsolete. cannam@88: * cannam@88: * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead. cannam@88: * cannam@88: * Argument: struct ovectl_ratemanage_arg * cannam@88: */ cannam@88: #define OV_ECTL_RATEMANAGE_SET 0x11 cannam@88: /** cannam@88: * Old interface to setting average-bitrate encoding mode. cannam@88: * cannam@88: * Deprecated after move to bit-reservoir style management in 1.1 rendered cannam@88: * this interface partially obsolete. cannam@88: * cannam@88: * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead. cannam@88: * cannam@88: * Argument: struct ovectl_ratemanage_arg * cannam@88: */ cannam@88: #define OV_ECTL_RATEMANAGE_AVG 0x12 cannam@88: /** cannam@88: * Old interface to setting bounded-bitrate encoding modes. cannam@88: * cannam@88: * deprecated after move to bit-reservoir style management in 1.1 rendered cannam@88: * this interface partially obsolete. cannam@88: * cannam@88: * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead. cannam@88: * cannam@88: * Argument: struct ovectl_ratemanage_arg * cannam@88: */ cannam@88: #define OV_ECTL_RATEMANAGE_HARD 0x13 cannam@88: cannam@88: /*@}*/ cannam@88: cannam@88: cannam@88: cannam@88: #ifdef __cplusplus cannam@88: } cannam@88: #endif /* __cplusplus */ cannam@88: cannam@88: #endif