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