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