Home | History | Annotate | Download | only in include
      1 /* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited
      2    Written by Jean-Marc Valin and Koen Vos */
      3 /*
      4    Redistribution and use in source and binary forms, with or without
      5    modification, are permitted provided that the following conditions
      6    are met:
      7 
      8    - Redistributions of source code must retain the above copyright
      9    notice, this list of conditions and the following disclaimer.
     10 
     11    - Redistributions in binary form must reproduce the above copyright
     12    notice, this list of conditions and the following disclaimer in the
     13    documentation and/or other materials provided with the distribution.
     14 
     15    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     16    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     17    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     18    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
     19    OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     20    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     21    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     22    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     23    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     24    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     25    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26 */
     27 
     28 /**
     29  * @file opus_defines.h
     30  * @brief Opus reference implementation constants
     31  */
     32 
     33 #ifndef OPUS_DEFINES_H
     34 #define OPUS_DEFINES_H
     35 
     36 #include "opus_types.h"
     37 
     38 #ifdef __cplusplus
     39 extern "C" {
     40 #endif
     41 
     42 /** @defgroup opus_errorcodes Error codes
     43  * @{
     44  */
     45 /** No error @hideinitializer*/
     46 #define OPUS_OK                0
     47 /** One or more invalid/out of range arguments @hideinitializer*/
     48 #define OPUS_BAD_ARG          -1
     49 /** The mode struct passed is invalid @hideinitializer*/
     50 #define OPUS_BUFFER_TOO_SMALL -2
     51 /** An internal error was detected @hideinitializer*/
     52 #define OPUS_INTERNAL_ERROR   -3
     53 /** The compressed data passed is corrupted @hideinitializer*/
     54 #define OPUS_INVALID_PACKET   -4
     55 /** Invalid/unsupported request number @hideinitializer*/
     56 #define OPUS_UNIMPLEMENTED    -5
     57 /** An encoder or decoder structure is invalid or already freed @hideinitializer*/
     58 #define OPUS_INVALID_STATE    -6
     59 /** Memory allocation has failed @hideinitializer*/
     60 #define OPUS_ALLOC_FAIL       -7
     61 /**@}*/
     62 
     63 /** @cond OPUS_INTERNAL_DOC */
     64 /**Export control for opus functions */
     65 
     66 #ifndef OPUS_EXPORT
     67 # if defined(__GNUC__) && defined(OPUS_BUILD)
     68 #  define OPUS_EXPORT __attribute__ ((visibility ("default")))
     69 # elif defined(WIN32) && !defined(__MINGW32__)
     70 #  ifdef OPUS_BUILD
     71 #   define OPUS_EXPORT __declspec(dllexport)
     72 #  else
     73 #   define OPUS_EXPORT
     74 #  endif
     75 # else
     76 #  define OPUS_EXPORT
     77 # endif
     78 #endif
     79 
     80 # if !defined(OPUS_GNUC_PREREQ)
     81 #  if defined(__GNUC__)&&defined(__GNUC_MINOR__)
     82 #   define OPUS_GNUC_PREREQ(_maj,_min) \
     83  ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
     84 #  else
     85 #   define OPUS_GNUC_PREREQ(_maj,_min) 0
     86 #  endif
     87 # endif
     88 
     89 #if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) )
     90 # if OPUS_GNUC_PREREQ(3,0)
     91 #  define OPUS_RESTRICT __restrict__
     92 # elif (defined(_MSC_VER) && _MSC_VER >= 1400)
     93 #  define OPUS_RESTRICT __restrict
     94 # else
     95 #  define OPUS_RESTRICT
     96 # endif
     97 #else
     98 # define OPUS_RESTRICT restrict
     99 #endif
    100 
    101 /**Warning attributes for opus functions
    102   * NONNULL is not used in OPUS_BUILD to avoid the compiler optimizing out
    103   * some paranoid null checks. */
    104 #if defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4)
    105 # define OPUS_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
    106 #else
    107 # define OPUS_WARN_UNUSED_RESULT
    108 #endif
    109 #if !defined(OPUS_BUILD) && defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4)
    110 # define OPUS_ARG_NONNULL(_x)  __attribute__ ((__nonnull__(_x)))
    111 #else
    112 # define OPUS_ARG_NONNULL(_x)
    113 #endif
    114 
    115 /** These are the actual Encoder CTL ID numbers.
    116   * They should not be used directly by applications.
    117   * In general, SETs should be even and GETs should be odd.*/
    118 #define OPUS_SET_APPLICATION_REQUEST         4000
    119 #define OPUS_GET_APPLICATION_REQUEST         4001
    120 #define OPUS_SET_BITRATE_REQUEST             4002
    121 #define OPUS_GET_BITRATE_REQUEST             4003
    122 #define OPUS_SET_MAX_BANDWIDTH_REQUEST       4004
    123 #define OPUS_GET_MAX_BANDWIDTH_REQUEST       4005
    124 #define OPUS_SET_VBR_REQUEST                 4006
    125 #define OPUS_GET_VBR_REQUEST                 4007
    126 #define OPUS_SET_BANDWIDTH_REQUEST           4008
    127 #define OPUS_GET_BANDWIDTH_REQUEST           4009
    128 #define OPUS_SET_COMPLEXITY_REQUEST          4010
    129 #define OPUS_GET_COMPLEXITY_REQUEST          4011
    130 #define OPUS_SET_INBAND_FEC_REQUEST          4012
    131 #define OPUS_GET_INBAND_FEC_REQUEST          4013
    132 #define OPUS_SET_PACKET_LOSS_PERC_REQUEST    4014
    133 #define OPUS_GET_PACKET_LOSS_PERC_REQUEST    4015
    134 #define OPUS_SET_DTX_REQUEST                 4016
    135 #define OPUS_GET_DTX_REQUEST                 4017
    136 #define OPUS_SET_VBR_CONSTRAINT_REQUEST      4020
    137 #define OPUS_GET_VBR_CONSTRAINT_REQUEST      4021
    138 #define OPUS_SET_FORCE_CHANNELS_REQUEST      4022
    139 #define OPUS_GET_FORCE_CHANNELS_REQUEST      4023
    140 #define OPUS_SET_SIGNAL_REQUEST              4024
    141 #define OPUS_GET_SIGNAL_REQUEST              4025
    142 #define OPUS_GET_LOOKAHEAD_REQUEST           4027
    143 /* #define OPUS_RESET_STATE 4028 */
    144 #define OPUS_GET_SAMPLE_RATE_REQUEST         4029
    145 #define OPUS_GET_FINAL_RANGE_REQUEST         4031
    146 #define OPUS_GET_PITCH_REQUEST               4033
    147 #define OPUS_SET_GAIN_REQUEST                4034
    148 #define OPUS_GET_GAIN_REQUEST                4045 /* Should have been 4035 */
    149 #define OPUS_SET_LSB_DEPTH_REQUEST           4036
    150 #define OPUS_GET_LSB_DEPTH_REQUEST           4037
    151 
    152 #define OPUS_GET_LAST_PACKET_DURATION_REQUEST 4039
    153 
    154 /* Don't use 4045, it's already taken by OPUS_GET_GAIN_REQUEST */
    155 
    156 /* Macros to trigger compilation errors when the wrong types are provided to a CTL */
    157 #define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x))
    158 #define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr)))
    159 #define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr)))
    160 /** @endcond */
    161 
    162 /** @defgroup opus_ctlvalues Pre-defined values for CTL interface
    163   * @see opus_genericctls, opus_encoderctls
    164   * @{
    165   */
    166 /* Values for the various encoder CTLs */
    167 #define OPUS_AUTO                           -1000 /**<Auto/default setting @hideinitializer*/
    168 #define OPUS_BITRATE_MAX                       -1 /**<Maximum bitrate @hideinitializer*/
    169 
    170 /** Best for most VoIP/videoconference applications where listening quality and intelligibility matter most
    171  * @hideinitializer */
    172 #define OPUS_APPLICATION_VOIP                2048
    173 /** Best for broadcast/high-fidelity application where the decoded audio should be as close as possible to the input
    174  * @hideinitializer */
    175 #define OPUS_APPLICATION_AUDIO               2049
    176 /** Only use when lowest-achievable latency is what matters most. Voice-optimized modes cannot be used.
    177  * @hideinitializer */
    178 #define OPUS_APPLICATION_RESTRICTED_LOWDELAY 2051
    179 
    180 #define OPUS_SIGNAL_VOICE                    3001 /**< Signal being encoded is voice */
    181 #define OPUS_SIGNAL_MUSIC                    3002 /**< Signal being encoded is music */
    182 #define OPUS_BANDWIDTH_NARROWBAND            1101 /**< 4 kHz bandpass @hideinitializer*/
    183 #define OPUS_BANDWIDTH_MEDIUMBAND            1102 /**< 6 kHz bandpass @hideinitializer*/
    184 #define OPUS_BANDWIDTH_WIDEBAND              1103 /**< 8 kHz bandpass @hideinitializer*/
    185 #define OPUS_BANDWIDTH_SUPERWIDEBAND         1104 /**<12 kHz bandpass @hideinitializer*/
    186 #define OPUS_BANDWIDTH_FULLBAND              1105 /**<20 kHz bandpass @hideinitializer*/
    187 
    188 /**@}*/
    189 
    190 
    191 /** @defgroup opus_encoderctls Encoder related CTLs
    192   *
    193   * These are convenience macros for use with the \c opus_encode_ctl
    194   * interface. They are used to generate the appropriate series of
    195   * arguments for that call, passing the correct type, size and so
    196   * on as expected for each particular request.
    197   *
    198   * Some usage examples:
    199   *
    200   * @code
    201   * int ret;
    202   * ret = opus_encoder_ctl(enc_ctx, OPUS_SET_BANDWIDTH(OPUS_AUTO));
    203   * if (ret != OPUS_OK) return ret;
    204   *
    205   * opus_int32 rate;
    206   * opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&rate));
    207   *
    208   * opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE);
    209   * @endcode
    210   *
    211   * @see opus_genericctls, opus_encoder
    212   * @{
    213   */
    214 
    215 /** Configures the encoder's computational complexity.
    216   * The supported range is 0-10 inclusive with 10 representing the highest complexity.
    217   * @see OPUS_GET_COMPLEXITY
    218   * @param[in] x <tt>opus_int32</tt>: Allowed values: 0-10, inclusive.
    219   *
    220   * @hideinitializer */
    221 #define OPUS_SET_COMPLEXITY(x) OPUS_SET_COMPLEXITY_REQUEST, __opus_check_int(x)
    222 /** Gets the encoder's complexity configuration.
    223   * @see OPUS_SET_COMPLEXITY
    224   * @param[out] x <tt>opus_int32 *</tt>: Returns a value in the range 0-10,
    225   *                                      inclusive.
    226   * @hideinitializer */
    227 #define OPUS_GET_COMPLEXITY(x) OPUS_GET_COMPLEXITY_REQUEST, __opus_check_int_ptr(x)
    228 
    229 /** Configures the bitrate in the encoder.
    230   * Rates from 500 to 512000 bits per second are meaningful, as well as the
    231   * special values #OPUS_AUTO and #OPUS_BITRATE_MAX.
    232   * The value #OPUS_BITRATE_MAX can be used to cause the codec to use as much
    233   * rate as it can, which is useful for controlling the rate by adjusting the
    234   * output buffer size.
    235   * @see OPUS_GET_BITRATE
    236   * @param[in] x <tt>opus_int32</tt>: Bitrate in bits per second. The default
    237   *                                   is determined based on the number of
    238   *                                   channels and the input sampling rate.
    239   * @hideinitializer */
    240 #define OPUS_SET_BITRATE(x) OPUS_SET_BITRATE_REQUEST, __opus_check_int(x)
    241 /** Gets the encoder's bitrate configuration.
    242   * @see OPUS_SET_BITRATE
    243   * @param[out] x <tt>opus_int32 *</tt>: Returns the bitrate in bits per second.
    244   *                                      The default is determined based on the
    245   *                                      number of channels and the input
    246   *                                      sampling rate.
    247   * @hideinitializer */
    248 #define OPUS_GET_BITRATE(x) OPUS_GET_BITRATE_REQUEST, __opus_check_int_ptr(x)
    249 
    250 /** Enables or disables variable bitrate (VBR) in the encoder.
    251   * The configured bitrate may not be met exactly because frames must
    252   * be an integer number of bytes in length.
    253   * @warning Only the MDCT mode of Opus can provide hard CBR behavior.
    254   * @see OPUS_GET_VBR
    255   * @see OPUS_SET_VBR_CONSTRAINT
    256   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    257   * <dl>
    258   * <dt>0</dt><dd>Hard CBR. For LPC/hybrid modes at very low bit-rate, this can
    259   *               cause noticeable quality degradation.</dd>
    260   * <dt>1</dt><dd>VBR (default). The exact type of VBR is controlled by
    261   *               #OPUS_SET_VBR_CONSTRAINT.</dd>
    262   * </dl>
    263   * @hideinitializer */
    264 #define OPUS_SET_VBR(x) OPUS_SET_VBR_REQUEST, __opus_check_int(x)
    265 /** Determine if variable bitrate (VBR) is enabled in the encoder.
    266   * @see OPUS_SET_VBR
    267   * @see OPUS_GET_VBR_CONSTRAINT
    268   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    269   * <dl>
    270   * <dt>0</dt><dd>Hard CBR.</dd>
    271   * <dt>1</dt><dd>VBR (default). The exact type of VBR may be retrieved via
    272   *               #OPUS_GET_VBR_CONSTRAINT.</dd>
    273   * </dl>
    274   * @hideinitializer */
    275 #define OPUS_GET_VBR(x) OPUS_GET_VBR_REQUEST, __opus_check_int_ptr(x)
    276 
    277 /** Enables or disables constrained VBR in the encoder.
    278   * This setting is ignored when the encoder is in CBR mode.
    279   * @warning Only the MDCT mode of Opus currently heeds the constraint.
    280   *  Speech mode ignores it completely, hybrid mode may fail to obey it
    281   *  if the LPC layer uses more bitrate than the constraint would have
    282   *  permitted.
    283   * @see OPUS_GET_VBR_CONSTRAINT
    284   * @see OPUS_SET_VBR
    285   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    286   * <dl>
    287   * <dt>0</dt><dd>Unconstrained VBR.</dd>
    288   * <dt>1</dt><dd>Constrained VBR (default). This creates a maximum of one
    289   *               frame of buffering delay assuming a transport with a
    290   *               serialization speed of the nominal bitrate.</dd>
    291   * </dl>
    292   * @hideinitializer */
    293 #define OPUS_SET_VBR_CONSTRAINT(x) OPUS_SET_VBR_CONSTRAINT_REQUEST, __opus_check_int(x)
    294 /** Determine if constrained VBR is enabled in the encoder.
    295   * @see OPUS_SET_VBR_CONSTRAINT
    296   * @see OPUS_GET_VBR
    297   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    298   * <dl>
    299   * <dt>0</dt><dd>Unconstrained VBR.</dd>
    300   * <dt>1</dt><dd>Constrained VBR (default).</dd>
    301   * </dl>
    302   * @hideinitializer */
    303 #define OPUS_GET_VBR_CONSTRAINT(x) OPUS_GET_VBR_CONSTRAINT_REQUEST, __opus_check_int_ptr(x)
    304 
    305 /** Configures mono/stereo forcing in the encoder.
    306   * This can force the encoder to produce packets encoded as either mono or
    307   * stereo, regardless of the format of the input audio. This is useful when
    308   * the caller knows that the input signal is currently a mono source embedded
    309   * in a stereo stream.
    310   * @see OPUS_GET_FORCE_CHANNELS
    311   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    312   * <dl>
    313   * <dt>#OPUS_AUTO</dt><dd>Not forced (default)</dd>
    314   * <dt>1</dt>         <dd>Forced mono</dd>
    315   * <dt>2</dt>         <dd>Forced stereo</dd>
    316   * </dl>
    317   * @hideinitializer */
    318 #define OPUS_SET_FORCE_CHANNELS(x) OPUS_SET_FORCE_CHANNELS_REQUEST, __opus_check_int(x)
    319 /** Gets the encoder's forced channel configuration.
    320   * @see OPUS_SET_FORCE_CHANNELS
    321   * @param[out] x <tt>opus_int32 *</tt>:
    322   * <dl>
    323   * <dt>#OPUS_AUTO</dt><dd>Not forced (default)</dd>
    324   * <dt>1</dt>         <dd>Forced mono</dd>
    325   * <dt>2</dt>         <dd>Forced stereo</dd>
    326   * </dl>
    327   * @hideinitializer */
    328 #define OPUS_GET_FORCE_CHANNELS(x) OPUS_GET_FORCE_CHANNELS_REQUEST, __opus_check_int_ptr(x)
    329 
    330 /** Configures the maximum bandpass that the encoder will select automatically.
    331   * Applications should normally use this instead of #OPUS_SET_BANDWIDTH
    332   * (leaving that set to the default, #OPUS_AUTO). This allows the
    333   * application to set an upper bound based on the type of input it is
    334   * providing, but still gives the encoder the freedom to reduce the bandpass
    335   * when the bitrate becomes too low, for better overall quality.
    336   * @see OPUS_GET_MAX_BANDWIDTH
    337   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    338   * <dl>
    339   * <dt>OPUS_BANDWIDTH_NARROWBAND</dt>    <dd>4 kHz passband</dd>
    340   * <dt>OPUS_BANDWIDTH_MEDIUMBAND</dt>    <dd>6 kHz passband</dd>
    341   * <dt>OPUS_BANDWIDTH_WIDEBAND</dt>      <dd>8 kHz passband</dd>
    342   * <dt>OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
    343   * <dt>OPUS_BANDWIDTH_FULLBAND</dt>     <dd>20 kHz passband (default)</dd>
    344   * </dl>
    345   * @hideinitializer */
    346 #define OPUS_SET_MAX_BANDWIDTH(x) OPUS_SET_MAX_BANDWIDTH_REQUEST, __opus_check_int(x)
    347 
    348 /** Gets the encoder's configured maximum allowed bandpass.
    349   * @see OPUS_SET_MAX_BANDWIDTH
    350   * @param[out] x <tt>opus_int32 *</tt>: Allowed values:
    351   * <dl>
    352   * <dt>#OPUS_BANDWIDTH_NARROWBAND</dt>    <dd>4 kHz passband</dd>
    353   * <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt>    <dd>6 kHz passband</dd>
    354   * <dt>#OPUS_BANDWIDTH_WIDEBAND</dt>      <dd>8 kHz passband</dd>
    355   * <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
    356   * <dt>#OPUS_BANDWIDTH_FULLBAND</dt>     <dd>20 kHz passband (default)</dd>
    357   * </dl>
    358   * @hideinitializer */
    359 #define OPUS_GET_MAX_BANDWIDTH(x) OPUS_GET_MAX_BANDWIDTH_REQUEST, __opus_check_int_ptr(x)
    360 
    361 /** Sets the encoder's bandpass to a specific value.
    362   * This prevents the encoder from automatically selecting the bandpass based
    363   * on the available bitrate. If an application knows the bandpass of the input
    364   * audio it is providing, it should normally use #OPUS_SET_MAX_BANDWIDTH
    365   * instead, which still gives the encoder the freedom to reduce the bandpass
    366   * when the bitrate becomes too low, for better overall quality.
    367   * @see OPUS_GET_BANDWIDTH
    368   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    369   * <dl>
    370   * <dt>#OPUS_AUTO</dt>                    <dd>(default)</dd>
    371   * <dt>#OPUS_BANDWIDTH_NARROWBAND</dt>    <dd>4 kHz passband</dd>
    372   * <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt>    <dd>6 kHz passband</dd>
    373   * <dt>#OPUS_BANDWIDTH_WIDEBAND</dt>      <dd>8 kHz passband</dd>
    374   * <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
    375   * <dt>#OPUS_BANDWIDTH_FULLBAND</dt>     <dd>20 kHz passband</dd>
    376   * </dl>
    377   * @hideinitializer */
    378 #define OPUS_SET_BANDWIDTH(x) OPUS_SET_BANDWIDTH_REQUEST, __opus_check_int(x)
    379 
    380 /** Configures the type of signal being encoded.
    381   * This is a hint which helps the encoder's mode selection.
    382   * @see OPUS_GET_SIGNAL
    383   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    384   * <dl>
    385   * <dt>#OPUS_AUTO</dt>        <dd>(default)</dd>
    386   * <dt>#OPUS_SIGNAL_VOICE</dt><dd>Bias thresholds towards choosing LPC or Hybrid modes.</dd>
    387   * <dt>#OPUS_SIGNAL_MUSIC</dt><dd>Bias thresholds towards choosing MDCT modes.</dd>
    388   * </dl>
    389   * @hideinitializer */
    390 #define OPUS_SET_SIGNAL(x) OPUS_SET_SIGNAL_REQUEST, __opus_check_int(x)
    391 /** Gets the encoder's configured signal type.
    392   * @see OPUS_SET_SIGNAL
    393   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    394   * <dl>
    395   * <dt>#OPUS_AUTO</dt>        <dd>(default)</dd>
    396   * <dt>#OPUS_SIGNAL_VOICE</dt><dd>Bias thresholds towards choosing LPC or Hybrid modes.</dd>
    397   * <dt>#OPUS_SIGNAL_MUSIC</dt><dd>Bias thresholds towards choosing MDCT modes.</dd>
    398   * </dl>
    399   * @hideinitializer */
    400 #define OPUS_GET_SIGNAL(x) OPUS_GET_SIGNAL_REQUEST, __opus_check_int_ptr(x)
    401 
    402 
    403 /** Configures the encoder's intended application.
    404   * The initial value is a mandatory argument to the encoder_create function.
    405   * @see OPUS_GET_APPLICATION
    406   * @param[in] x <tt>opus_int32</tt>: Returns one of the following values:
    407   * <dl>
    408   * <dt>#OPUS_APPLICATION_VOIP</dt>
    409   * <dd>Process signal for improved speech intelligibility.</dd>
    410   * <dt>#OPUS_APPLICATION_AUDIO</dt>
    411   * <dd>Favor faithfulness to the original input.</dd>
    412   * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
    413   * <dd>Configure the minimum possible coding delay by disabling certain modes
    414   * of operation.</dd>
    415   * </dl>
    416   * @hideinitializer */
    417 #define OPUS_SET_APPLICATION(x) OPUS_SET_APPLICATION_REQUEST, __opus_check_int(x)
    418 /** Gets the encoder's configured application.
    419   * @see OPUS_SET_APPLICATION
    420   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    421   * <dl>
    422   * <dt>#OPUS_APPLICATION_VOIP</dt>
    423   * <dd>Process signal for improved speech intelligibility.</dd>
    424   * <dt>#OPUS_APPLICATION_AUDIO</dt>
    425   * <dd>Favor faithfulness to the original input.</dd>
    426   * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
    427   * <dd>Configure the minimum possible coding delay by disabling certain modes
    428   * of operation.</dd>
    429   * </dl>
    430   * @hideinitializer */
    431 #define OPUS_GET_APPLICATION(x) OPUS_GET_APPLICATION_REQUEST, __opus_check_int_ptr(x)
    432 
    433 /** Gets the sampling rate the encoder or decoder was initialized with.
    434   * This simply returns the <code>Fs</code> value passed to opus_encoder_init()
    435   * or opus_decoder_init().
    436   * @param[out] x <tt>opus_int32 *</tt>: Sampling rate of encoder or decoder.
    437   * @hideinitializer
    438   */
    439 #define OPUS_GET_SAMPLE_RATE(x) OPUS_GET_SAMPLE_RATE_REQUEST, __opus_check_int_ptr(x)
    440 
    441 /** Gets the total samples of delay added by the entire codec.
    442   * This can be queried by the encoder and then the provided number of samples can be
    443   * skipped on from the start of the decoder's output to provide time aligned input
    444   * and output. From the perspective of a decoding application the real data begins this many
    445   * samples late.
    446   *
    447   * The decoder contribution to this delay is identical for all decoders, but the
    448   * encoder portion of the delay may vary from implementation to implementation,
    449   * version to version, or even depend on the encoder's initial configuration.
    450   * Applications needing delay compensation should call this CTL rather than
    451   * hard-coding a value.
    452   * @param[out] x <tt>opus_int32 *</tt>:   Number of lookahead samples
    453   * @hideinitializer */
    454 #define OPUS_GET_LOOKAHEAD(x) OPUS_GET_LOOKAHEAD_REQUEST, __opus_check_int_ptr(x)
    455 
    456 /** Configures the encoder's use of inband forward error correction (FEC).
    457   * @note This is only applicable to the LPC layer
    458   * @see OPUS_GET_INBAND_FEC
    459   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    460   * <dl>
    461   * <dt>0</dt><dd>Disable inband FEC (default).</dd>
    462   * <dt>1</dt><dd>Enable inband FEC.</dd>
    463   * </dl>
    464   * @hideinitializer */
    465 #define OPUS_SET_INBAND_FEC(x) OPUS_SET_INBAND_FEC_REQUEST, __opus_check_int(x)
    466 /** Gets encoder's configured use of inband forward error correction.
    467   * @see OPUS_SET_INBAND_FEC
    468   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    469   * <dl>
    470   * <dt>0</dt><dd>Inband FEC disabled (default).</dd>
    471   * <dt>1</dt><dd>Inband FEC enabled.</dd>
    472   * </dl>
    473   * @hideinitializer */
    474 #define OPUS_GET_INBAND_FEC(x) OPUS_GET_INBAND_FEC_REQUEST, __opus_check_int_ptr(x)
    475 
    476 /** Configures the encoder's expected packet loss percentage.
    477   * Higher values with trigger progressively more loss resistant behavior in the encoder
    478   * at the expense of quality at a given bitrate in the lossless case, but greater quality
    479   * under loss.
    480   * @see OPUS_GET_PACKET_LOSS_PERC
    481   * @param[in] x <tt>opus_int32</tt>:   Loss percentage in the range 0-100, inclusive (default: 0).
    482   * @hideinitializer */
    483 #define OPUS_SET_PACKET_LOSS_PERC(x) OPUS_SET_PACKET_LOSS_PERC_REQUEST, __opus_check_int(x)
    484 /** Gets the encoder's configured packet loss percentage.
    485   * @see OPUS_SET_PACKET_LOSS_PERC
    486   * @param[out] x <tt>opus_int32 *</tt>: Returns the configured loss percentage
    487   *                                      in the range 0-100, inclusive (default: 0).
    488   * @hideinitializer */
    489 #define OPUS_GET_PACKET_LOSS_PERC(x) OPUS_GET_PACKET_LOSS_PERC_REQUEST, __opus_check_int_ptr(x)
    490 
    491 /** Configures the encoder's use of discontinuous transmission (DTX).
    492   * @note This is only applicable to the LPC layer
    493   * @see OPUS_GET_DTX
    494   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    495   * <dl>
    496   * <dt>0</dt><dd>Disable DTX (default).</dd>
    497   * <dt>1</dt><dd>Enabled DTX.</dd>
    498   * </dl>
    499   * @hideinitializer */
    500 #define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __opus_check_int(x)
    501 /** Gets encoder's configured use of discontinuous transmission.
    502   * @see OPUS_SET_DTX
    503   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    504   * <dl>
    505   * <dt>0</dt><dd>DTX disabled (default).</dd>
    506   * <dt>1</dt><dd>DTX enabled.</dd>
    507   * </dl>
    508   * @hideinitializer */
    509 #define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __opus_check_int_ptr(x)
    510 /** Configures the depth of signal being encoded.
    511   * This is a hint which helps the encoder identify silence and near-silence.
    512   * @see OPUS_GET_LSB_DEPTH
    513   * @param[in] x <tt>opus_int32</tt>: Input precision in bits, between 8 and 24
    514   *                                   (default: 24).
    515   * @hideinitializer */
    516 #define OPUS_SET_LSB_DEPTH(x) OPUS_SET_LSB_DEPTH_REQUEST, __opus_check_int(x)
    517 /** Gets the encoder's configured signal depth.
    518   * @see OPUS_SET_LSB_DEPTH
    519   * @param[out] x <tt>opus_int32 *</tt>: Input precision in bits, between 8 and
    520   *                                      24 (default: 24).
    521   * @hideinitializer */
    522 #define OPUS_GET_LSB_DEPTH(x) OPUS_GET_LSB_DEPTH_REQUEST, __opus_check_int_ptr(x)
    523 
    524 /** Gets the duration (in samples) of the last packet successfully decoded or concealed.
    525   * @param[out] x <tt>opus_int32 *</tt>: Number of samples (at current sampling rate).
    526   * @hideinitializer */
    527 #define OPUS_GET_LAST_PACKET_DURATION(x) OPUS_GET_LAST_PACKET_DURATION_REQUEST, __opus_check_int_ptr(x)
    528 /**@}*/
    529 
    530 /** @defgroup opus_genericctls Generic CTLs
    531   *
    532   * These macros are used with the \c opus_decoder_ctl and
    533   * \c opus_encoder_ctl calls to generate a particular
    534   * request.
    535   *
    536   * When called on an \c OpusDecoder they apply to that
    537   * particular decoder instance. When called on an
    538   * \c OpusEncoder they apply to the corresponding setting
    539   * on that encoder instance, if present.
    540   *
    541   * Some usage examples:
    542   *
    543   * @code
    544   * int ret;
    545   * opus_int32 pitch;
    546   * ret = opus_decoder_ctl(dec_ctx, OPUS_GET_PITCH(&pitch));
    547   * if (ret == OPUS_OK) return ret;
    548   *
    549   * opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE);
    550   * opus_decoder_ctl(dec_ctx, OPUS_RESET_STATE);
    551   *
    552   * opus_int32 enc_bw, dec_bw;
    553   * opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&enc_bw));
    554   * opus_decoder_ctl(dec_ctx, OPUS_GET_BANDWIDTH(&dec_bw));
    555   * if (enc_bw != dec_bw) {
    556   *   printf("packet bandwidth mismatch!\n");
    557   * }
    558   * @endcode
    559   *
    560   * @see opus_encoder, opus_decoder_ctl, opus_encoder_ctl, opus_decoderctls, opus_encoderctls
    561   * @{
    562   */
    563 
    564 /** Resets the codec state to be equivalent to a freshly initialized state.
    565   * This should be called when switching streams in order to prevent
    566   * the back to back decoding from giving different results from
    567   * one at a time decoding.
    568   * @hideinitializer */
    569 #define OPUS_RESET_STATE 4028
    570 
    571 /** Gets the final state of the codec's entropy coder.
    572   * This is used for testing purposes,
    573   * The encoder and decoder state should be identical after coding a payload
    574   * (assuming no data corruption or software bugs)
    575   *
    576   * @param[out] x <tt>opus_uint32 *</tt>: Entropy coder state
    577   *
    578   * @hideinitializer */
    579 #define OPUS_GET_FINAL_RANGE(x) OPUS_GET_FINAL_RANGE_REQUEST, __opus_check_uint_ptr(x)
    580 
    581 /** Gets the pitch of the last decoded frame, if available.
    582   * This can be used for any post-processing algorithm requiring the use of pitch,
    583   * e.g. time stretching/shortening. If the last frame was not voiced, or if the
    584   * pitch was not coded in the frame, then zero is returned.
    585   *
    586   * This CTL is only implemented for decoder instances.
    587   *
    588   * @param[out] x <tt>opus_int32 *</tt>: pitch period at 48 kHz (or 0 if not available)
    589   *
    590   * @hideinitializer */
    591 #define OPUS_GET_PITCH(x) OPUS_GET_PITCH_REQUEST, __opus_check_int_ptr(x)
    592 
    593 /** Gets the encoder's configured bandpass or the decoder's last bandpass.
    594   * @see OPUS_SET_BANDWIDTH
    595   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    596   * <dl>
    597   * <dt>#OPUS_AUTO</dt>                    <dd>(default)</dd>
    598   * <dt>#OPUS_BANDWIDTH_NARROWBAND</dt>    <dd>4 kHz passband</dd>
    599   * <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt>    <dd>6 kHz passband</dd>
    600   * <dt>#OPUS_BANDWIDTH_WIDEBAND</dt>      <dd>8 kHz passband</dd>
    601   * <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
    602   * <dt>#OPUS_BANDWIDTH_FULLBAND</dt>     <dd>20 kHz passband</dd>
    603   * </dl>
    604   * @hideinitializer */
    605 #define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __opus_check_int_ptr(x)
    606 
    607 /**@}*/
    608 
    609 /** @defgroup opus_decoderctls Decoder related CTLs
    610   * @see opus_genericctls, opus_encoderctls, opus_decoder
    611   * @{
    612   */
    613 
    614 /** Configures decoder gain adjustment.
    615   * Scales the decoded output by a factor specified in Q8 dB units.
    616   * This has a maximum range of -32768 to 32767 inclusive, and returns
    617   * OPUS_BAD_ARG otherwise. The default is zero indicating no adjustment.
    618   * This setting survives decoder reset.
    619   *
    620   * gain = pow(10, x/(20.0*256))
    621   *
    622   * @param[in] x <tt>opus_int32</tt>:   Amount to scale PCM signal by in Q8 dB units.
    623   * @hideinitializer */
    624 #define OPUS_SET_GAIN(x) OPUS_SET_GAIN_REQUEST, __opus_check_int(x)
    625 /** Gets the decoder's configured gain adjustment. @see OPUS_SET_GAIN
    626   *
    627   * @param[out] x <tt>opus_int32 *</tt>: Amount to scale PCM signal by in Q8 dB units.
    628   * @hideinitializer */
    629 #define OPUS_GET_GAIN(x) OPUS_GET_GAIN_REQUEST, __opus_check_int_ptr(x)
    630 
    631 /**@}*/
    632 
    633 /** @defgroup opus_libinfo Opus library information functions
    634   * @{
    635   */
    636 
    637 /** Converts an opus error code into a human readable string.
    638   *
    639   * @param[in] error <tt>int</tt>: Error number
    640   * @returns Error string
    641   */
    642 OPUS_EXPORT const char *opus_strerror(int error);
    643 
    644 /** Gets the libopus version string.
    645   *
    646   * @returns Version string
    647   */
    648 OPUS_EXPORT const char *opus_get_version_string(void);
    649 /**@}*/
    650 
    651 #ifdef __cplusplus
    652 }
    653 #endif
    654 
    655 #endif /* OPUS_DEFINES_H */
    656