Path: blob/master/thirdparty/libvorbis/vorbis/vorbisenc.h
9902 views
/********************************************************************1* *2* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *3* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *4* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *5* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *6* *7* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *8* by the Xiph.Org Foundation https://xiph.org/ *9* *10********************************************************************1112function: vorbis encode-engine setup1314********************************************************************/1516/** \file17* Libvorbisenc is a convenient API for setting up an encoding18* environment using libvorbis. Libvorbisenc encapsulates the19* actions needed to set up the encoder properly.20*/2122#ifndef _OV_ENC_H_23#define _OV_ENC_H_2425#ifdef __cplusplus26extern "C"27{28#endif /* __cplusplus */2930#include "codec.h"3132/**33* This is the primary function within libvorbisenc for setting up managed34* bitrate modes.35*36* Before this function is called, the \ref vorbis_info37* struct should be initialized by using vorbis_info_init() from the libvorbis38* API. After encoding, vorbis_info_clear() should be called.39*40* The max_bitrate, nominal_bitrate, and min_bitrate settings are used to set41* constraints for the encoded file. This function uses these settings to42* select the appropriate encoding mode and set it up.43*44* \param vi Pointer to an initialized \ref vorbis_info struct.45* \param channels The number of channels to be encoded.46* \param rate The sampling rate of the source audio.47* \param max_bitrate Desired maximum bitrate (limit). -1 indicates unset.48* \param nominal_bitrate Desired average, or central, bitrate. -1 indicates unset.49* \param min_bitrate Desired minimum bitrate. -1 indicates unset.50*51* \return Zero for success, and negative values for failure.52*53* \retval 0 Success.54* \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.55* \retval OV_EINVAL Invalid setup request, eg, out of range argument.56* \retval OV_EIMPL Unimplemented mode; unable to comply with bitrate request.57*/58extern int vorbis_encode_init(vorbis_info *vi,59long channels,60long rate,6162long max_bitrate,63long nominal_bitrate,64long min_bitrate);6566/**67* This function performs step-one of a three-step bitrate-managed encode68* setup. It functions similarly to the one-step setup performed by \ref69* vorbis_encode_init but allows an application to make further encode setup70* tweaks using \ref vorbis_encode_ctl before finally calling \ref71* vorbis_encode_setup_init to complete the setup process.72*73* Before this function is called, the \ref vorbis_info struct should be74* initialized by using vorbis_info_init() from the libvorbis API. After75* encoding, vorbis_info_clear() should be called.76*77* The max_bitrate, nominal_bitrate, and min_bitrate settings are used to set78* constraints for the encoded file. This function uses these settings to79* select the appropriate encoding mode and set it up.80*81* \param vi Pointer to an initialized vorbis_info struct.82* \param channels The number of channels to be encoded.83* \param rate The sampling rate of the source audio.84* \param max_bitrate Desired maximum bitrate (limit). -1 indicates unset.85* \param nominal_bitrate Desired average, or central, bitrate. -1 indicates unset.86* \param min_bitrate Desired minimum bitrate. -1 indicates unset.87*88* \return Zero for success, and negative for failure.89*90* \retval 0 Success91* \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.92* \retval OV_EINVAL Invalid setup request, eg, out of range argument.93* \retval OV_EIMPL Unimplemented mode; unable to comply with bitrate request.94*/95extern int vorbis_encode_setup_managed(vorbis_info *vi,96long channels,97long rate,9899long max_bitrate,100long nominal_bitrate,101long min_bitrate);102103/**104* This function performs step-one of a three-step variable bitrate105* (quality-based) encode setup. It functions similarly to the one-step setup106* performed by \ref vorbis_encode_init_vbr() but allows an application to107* make further encode setup tweaks using \ref vorbis_encode_ctl() before108* finally calling \ref vorbis_encode_setup_init to complete the setup109* process.110*111* Before this function is called, the \ref vorbis_info struct should be112* initialized by using \ref vorbis_info_init() from the libvorbis API. After113* encoding, vorbis_info_clear() should be called.114*115* \param vi Pointer to an initialized vorbis_info struct.116* \param channels The number of channels to be encoded.117* \param rate The sampling rate of the source audio.118* \param quality Desired quality level, currently from -0.1 to 1.0 (lo to hi).119*120* \return Zero for success, and negative values for failure.121*122* \retval 0 Success123* \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.124* \retval OV_EINVAL Invalid setup request, eg, out of range argument.125* \retval OV_EIMPL Unimplemented mode; unable to comply with quality level request.126*/127extern int vorbis_encode_setup_vbr(vorbis_info *vi,128long channels,129long rate,130131float quality132);133134/**135* This is the primary function within libvorbisenc for setting up variable136* bitrate ("quality" based) modes.137*138*139* Before this function is called, the vorbis_info struct should be140* initialized by using vorbis_info_init() from the libvorbis API. After141* encoding, vorbis_info_clear() should be called.142*143* \param vi Pointer to an initialized vorbis_info struct.144* \param channels The number of channels to be encoded.145* \param rate The sampling rate of the source audio.146* \param base_quality Desired quality level, currently from -0.1 to 1.0 (lo to hi).147*148*149* \return Zero for success, or a negative number for failure.150*151* \retval 0 Success152* \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.153* \retval OV_EINVAL Invalid setup request, eg, out of range argument.154* \retval OV_EIMPL Unimplemented mode; unable to comply with quality level request.155*/156extern int vorbis_encode_init_vbr(vorbis_info *vi,157long channels,158long rate,159160float base_quality161);162163/**164* This function performs the last stage of three-step encoding setup, as165* described in the API overview under managed bitrate modes.166*167* Before this function is called, the \ref vorbis_info struct should be168* initialized by using vorbis_info_init() from the libvorbis API, one of169* \ref vorbis_encode_setup_managed() or \ref vorbis_encode_setup_vbr() called to170* initialize the high-level encoding setup, and \ref vorbis_encode_ctl()171* called if necessary to make encoding setup changes.172* vorbis_encode_setup_init() finalizes the highlevel encoding structure into173* a complete encoding setup after which the application may make no further174* setup changes.175*176* After encoding, vorbis_info_clear() should be called.177*178* \param vi Pointer to an initialized \ref vorbis_info struct.179*180* \return Zero for success, and negative values for failure.181*182* \retval 0 Success.183* \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption.184*185* \retval OV_EINVAL Attempt to use vorbis_encode_setup_init() without first186* calling one of vorbis_encode_setup_managed() or vorbis_encode_setup_vbr() to187* initialize the high-level encoding setup188*189*/190extern int vorbis_encode_setup_init(vorbis_info *vi);191192/**193* This function implements a generic interface to miscellaneous encoder194* settings similar to the classic UNIX 'ioctl()' system call. Applications195* may use vorbis_encode_ctl() to query or set bitrate management or quality196* mode details by using one of several \e request arguments detailed below.197* vorbis_encode_ctl() must be called after one of198* vorbis_encode_setup_managed() or vorbis_encode_setup_vbr(). When used199* to modify settings, \ref vorbis_encode_ctl() must be called before \ref200* vorbis_encode_setup_init().201*202* \param vi Pointer to an initialized vorbis_info struct.203*204* \param number Specifies the desired action; See \ref encctlcodes "the list205* of available requests".206*207* \param arg void * pointing to a data structure matching the request208* argument.209*210* \retval 0 Success. Any further return information (such as the result of a211* query) is placed into the storage pointed to by *arg.212*213* \retval OV_EINVAL Invalid argument, or an attempt to modify a setting after214* calling vorbis_encode_setup_init().215*216* \retval OV_EIMPL Unimplemented or unknown request217*/218extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);219220/**221* \deprecated This is a deprecated interface. Please use vorbis_encode_ctl()222* with the \ref ovectl_ratemanage2_arg struct and \ref223* OV_ECTL_RATEMANAGE2_GET and \ref OV_ECTL_RATEMANAGE2_SET calls in new code.224*225* The \ref ovectl_ratemanage_arg structure is used with vorbis_encode_ctl()226* and the \ref OV_ECTL_RATEMANAGE_GET, \ref OV_ECTL_RATEMANAGE_SET, \ref227* OV_ECTL_RATEMANAGE_AVG, \ref OV_ECTL_RATEMANAGE_HARD calls in order to228* query and modify specifics of the encoder's bitrate management229* configuration.230*/231struct ovectl_ratemanage_arg {232int management_active; /**< nonzero if bitrate management is active*/233/** hard lower limit (in kilobits per second) below which the stream bitrate234will never be allowed for any given bitrate_hard_window seconds of time.*/235long bitrate_hard_min;236/** hard upper limit (in kilobits per second) above which the stream bitrate237will never be allowed for any given bitrate_hard_window seconds of time.*/238long bitrate_hard_max;239/** the window period (in seconds) used to regulate the hard bitrate minimum240and maximum*/241double bitrate_hard_window;242/** soft lower limit (in kilobits per second) below which the average bitrate243tracker will start nudging the bitrate higher.*/244long bitrate_av_lo;245/** soft upper limit (in kilobits per second) above which the average bitrate246tracker will start nudging the bitrate lower.*/247long bitrate_av_hi;248/** the window period (in seconds) used to regulate the average bitrate249minimum and maximum.*/250double bitrate_av_window;251/** Regulates the relative centering of the average and hard windows; in252libvorbis 1.0 and 1.0.1, the hard window regulation overlapped but253followed the average window regulation. In libvorbis 1.1 a bit-reservoir254interface replaces the old windowing interface; the older windowing255interface is simulated and this field has no effect.*/256double bitrate_av_window_center;257};258259/**260* \name struct ovectl_ratemanage2_arg261*262* The ovectl_ratemanage2_arg structure is used with vorbis_encode_ctl() and263* the OV_ECTL_RATEMANAGE2_GET and OV_ECTL_RATEMANAGE2_SET calls in order to264* query and modify specifics of the encoder's bitrate management265* configuration.266*267*/268struct ovectl_ratemanage2_arg {269int management_active; /**< nonzero if bitrate management is active */270/** Lower allowed bitrate limit in kilobits per second */271long bitrate_limit_min_kbps;272/** Upper allowed bitrate limit in kilobits per second */273long bitrate_limit_max_kbps;274long bitrate_limit_reservoir_bits; /**<Size of the bitrate reservoir in bits */275/** Regulates the bitrate reservoir's preferred fill level in a range from 0.0276* to 1.0; 0.0 tries to bank bits to buffer against future bitrate spikes, 1.0277* buffers against future sudden drops in instantaneous bitrate. Default is278* 0.1279*/280double bitrate_limit_reservoir_bias;281/** Average bitrate setting in kilobits per second */282long bitrate_average_kbps;283/** Slew rate limit setting for average bitrate adjustment; sets the minimum284* time in seconds the bitrate tracker may swing from one extreme to the285* other when boosting or damping average bitrate.286*/287double bitrate_average_damping;288};289290291/**292* \name vorbis_encode_ctl() codes293*294* \anchor encctlcodes295*296* These values are passed as the \c number parameter of vorbis_encode_ctl().297* The type of the referent of that function's \c arg pointer depends on these298* codes.299*/300/*@{*/301302/**303* Query the current encoder bitrate management setting.304*305*Argument: <tt>struct ovectl_ratemanage2_arg *</tt>306*307* Used to query the current encoder bitrate management setting. Also used to308* initialize fields of an ovectl_ratemanage2_arg structure for use with309* \ref OV_ECTL_RATEMANAGE2_SET.310*/311#define OV_ECTL_RATEMANAGE2_GET 0x14312313/**314* Set the current encoder bitrate management settings.315*316* Argument: <tt>struct ovectl_ratemanage2_arg *</tt>317*318* Used to set the current encoder bitrate management settings to the values319* listed in the ovectl_ratemanage2_arg. Passing a NULL pointer will disable320* bitrate management.321*/322#define OV_ECTL_RATEMANAGE2_SET 0x15323324/**325* Returns the current encoder hard-lowpass setting (kHz) in the double326* pointed to by arg.327*328* Argument: <tt>double *</tt>329*/330#define OV_ECTL_LOWPASS_GET 0x20331332/**333* Sets the encoder hard-lowpass to the value (kHz) pointed to by arg. Valid334* lowpass settings range from 2 to 99.335*336* Argument: <tt>double *</tt>337*/338#define OV_ECTL_LOWPASS_SET 0x21339340/**341* Returns the current encoder impulse block setting in the double pointed342* to by arg.343*344* Argument: <tt>double *</tt>345*/346#define OV_ECTL_IBLOCK_GET 0x30347348/**349* Sets the impulse block bias to the the value pointed to by arg.350*351* Argument: <tt>double *</tt>352*353* Valid range is -15.0 to 0.0 [default]. A negative impulse block bias will354* direct to encoder to use more bits when incoding short blocks that contain355* strong impulses, thus improving the accuracy of impulse encoding.356*/357#define OV_ECTL_IBLOCK_SET 0x31358359/**360* Returns the current encoder coupling setting in the int pointed361* to by arg.362*363* Argument: <tt>int *</tt>364*/365#define OV_ECTL_COUPLING_GET 0x40366367/**368* Enables/disables channel coupling in multichannel encoding according to arg.369*370* Argument: <tt>int *</tt>371*372* Zero disables channel coupling for multichannel inputs, nonzer enables373* channel coupling. Setting has no effect on monophonic encoding or374* multichannel counts that do not offer coupling. At present, coupling is375* available for stereo and 5.1 encoding.376*/377#define OV_ECTL_COUPLING_SET 0x41378379/* deprecated rate management supported only for compatibility */380381/**382* Old interface to querying bitrate management settings.383*384* Deprecated after move to bit-reservoir style management in 1.1 rendered385* this interface partially obsolete.386387* \deprecated Please use \ref OV_ECTL_RATEMANAGE2_GET instead.388*389* Argument: <tt>struct ovectl_ratemanage_arg *</tt>390*/391#define OV_ECTL_RATEMANAGE_GET 0x10392/**393* Old interface to modifying bitrate management settings.394*395* deprecated after move to bit-reservoir style management in 1.1 rendered396* this interface partially obsolete.397*398* \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.399*400* Argument: <tt>struct ovectl_ratemanage_arg *</tt>401*/402#define OV_ECTL_RATEMANAGE_SET 0x11403/**404* Old interface to setting average-bitrate encoding mode.405*406* Deprecated after move to bit-reservoir style management in 1.1 rendered407* this interface partially obsolete.408*409* \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.410*411* Argument: <tt>struct ovectl_ratemanage_arg *</tt>412*/413#define OV_ECTL_RATEMANAGE_AVG 0x12414/**415* Old interface to setting bounded-bitrate encoding modes.416*417* deprecated after move to bit-reservoir style management in 1.1 rendered418* this interface partially obsolete.419*420* \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.421*422* Argument: <tt>struct ovectl_ratemanage_arg *</tt>423*/424#define OV_ECTL_RATEMANAGE_HARD 0x13425426/*@}*/427428429430#ifdef __cplusplus431}432#endif /* __cplusplus */433434#endif435436437