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