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 /** Not enough bytes allocated in the buffer @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(WIN32)
     68 #  if defined(OPUS_BUILD) && defined(DLL_EXPORT)
     69 #   define OPUS_EXPORT __declspec(dllexport)
     70 #  else
     71 #   define OPUS_EXPORT
     72 #  endif
     73 # elif defined(__GNUC__) && defined(OPUS_BUILD)
     74 #  define OPUS_EXPORT __attribute__ ((visibility ("default")))
     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 #if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) )
    102 # if OPUS_GNUC_PREREQ(2,7)
    103 #  define OPUS_INLINE __inline__
    104 # elif (defined(_MSC_VER))
    105 #  define OPUS_INLINE __inline
    106 # else
    107 #  define OPUS_INLINE
    108 # endif
    109 #else
    110 # define OPUS_INLINE inline
    111 #endif
    112 
    113 /**Warning attributes for opus functions
    114   * NONNULL is not used in OPUS_BUILD to avoid the compiler optimizing out
    115   * some paranoid null checks. */
    116 #if defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4)
    117 # define OPUS_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
    118 #else
    119 # define OPUS_WARN_UNUSED_RESULT
    120 #endif
    121 #if !defined(OPUS_BUILD) && defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4)
    122 # define OPUS_ARG_NONNULL(_x)  __attribute__ ((__nonnull__(_x)))
    123 #else
    124 # define OPUS_ARG_NONNULL(_x)
    125 #endif
    126 
    127 /** These are the actual Encoder CTL ID numbers.
    128   * They should not be used directly by applications.
    129   * In general, SETs should be even and GETs should be odd.*/
    130 #define OPUS_SET_APPLICATION_REQUEST         4000
    131 #define OPUS_GET_APPLICATION_REQUEST         4001
    132 #define OPUS_SET_BITRATE_REQUEST             4002
    133 #define OPUS_GET_BITRATE_REQUEST             4003
    134 #define OPUS_SET_MAX_BANDWIDTH_REQUEST       4004
    135 #define OPUS_GET_MAX_BANDWIDTH_REQUEST       4005
    136 #define OPUS_SET_VBR_REQUEST                 4006
    137 #define OPUS_GET_VBR_REQUEST                 4007
    138 #define OPUS_SET_BANDWIDTH_REQUEST           4008
    139 #define OPUS_GET_BANDWIDTH_REQUEST           4009
    140 #define OPUS_SET_COMPLEXITY_REQUEST          4010
    141 #define OPUS_GET_COMPLEXITY_REQUEST          4011
    142 #define OPUS_SET_INBAND_FEC_REQUEST          4012
    143 #define OPUS_GET_INBAND_FEC_REQUEST          4013
    144 #define OPUS_SET_PACKET_LOSS_PERC_REQUEST    4014
    145 #define OPUS_GET_PACKET_LOSS_PERC_REQUEST    4015
    146 #define OPUS_SET_DTX_REQUEST                 4016
    147 #define OPUS_GET_DTX_REQUEST                 4017
    148 #define OPUS_SET_VBR_CONSTRAINT_REQUEST      4020
    149 #define OPUS_GET_VBR_CONSTRAINT_REQUEST      4021
    150 #define OPUS_SET_FORCE_CHANNELS_REQUEST      4022
    151 #define OPUS_GET_FORCE_CHANNELS_REQUEST      4023
    152 #define OPUS_SET_SIGNAL_REQUEST              4024
    153 #define OPUS_GET_SIGNAL_REQUEST              4025
    154 #define OPUS_GET_LOOKAHEAD_REQUEST           4027
    155 /* #define OPUS_RESET_STATE 4028 */
    156 #define OPUS_GET_SAMPLE_RATE_REQUEST         4029
    157 #define OPUS_GET_FINAL_RANGE_REQUEST         4031
    158 #define OPUS_GET_PITCH_REQUEST               4033
    159 #define OPUS_SET_GAIN_REQUEST                4034
    160 #define OPUS_GET_GAIN_REQUEST                4045 /* Should have been 4035 */
    161 #define OPUS_SET_LSB_DEPTH_REQUEST           4036
    162 #define OPUS_GET_LSB_DEPTH_REQUEST           4037
    163 #define OPUS_GET_LAST_PACKET_DURATION_REQUEST 4039
    164 #define OPUS_SET_EXPERT_FRAME_DURATION_REQUEST 4040
    165 #define OPUS_GET_EXPERT_FRAME_DURATION_REQUEST 4041
    166 #define OPUS_SET_PREDICTION_DISABLED_REQUEST 4042
    167 #define OPUS_GET_PREDICTION_DISABLED_REQUEST 4043
    168 /* Don't use 4045, it's already taken by OPUS_GET_GAIN_REQUEST */
    169 #define OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST 4046
    170 #define OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST 4047
    171 
    172 /** Defines for the presence of extended APIs. */
    173 #define OPUS_HAVE_OPUS_PROJECTION_H
    174 
    175 /* Macros to trigger compilation errors when the wrong types are provided to a CTL */
    176 #define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x))
    177 #define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr)))
    178 #define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr)))
    179 #define __opus_check_val16_ptr(ptr) ((ptr) + ((ptr) - (opus_val16*)(ptr)))
    180 /** @endcond */
    181 
    182 /** @defgroup opus_ctlvalues Pre-defined values for CTL interface
    183   * @see opus_genericctls, opus_encoderctls
    184   * @{
    185   */
    186 /* Values for the various encoder CTLs */
    187 #define OPUS_AUTO                           -1000 /**<Auto/default setting @hideinitializer*/
    188 #define OPUS_BITRATE_MAX                       -1 /**<Maximum bitrate @hideinitializer*/
    189 
    190 /** Best for most VoIP/videoconference applications where listening quality and intelligibility matter most
    191  * @hideinitializer */
    192 #define OPUS_APPLICATION_VOIP                2048
    193 /** Best for broadcast/high-fidelity application where the decoded audio should be as close as possible to the input
    194  * @hideinitializer */
    195 #define OPUS_APPLICATION_AUDIO               2049
    196 /** Only use when lowest-achievable latency is what matters most. Voice-optimized modes cannot be used.
    197  * @hideinitializer */
    198 #define OPUS_APPLICATION_RESTRICTED_LOWDELAY 2051
    199 
    200 #define OPUS_SIGNAL_VOICE                    3001 /**< Signal being encoded is voice */
    201 #define OPUS_SIGNAL_MUSIC                    3002 /**< Signal being encoded is music */
    202 #define OPUS_BANDWIDTH_NARROWBAND            1101 /**< 4 kHz bandpass @hideinitializer*/
    203 #define OPUS_BANDWIDTH_MEDIUMBAND            1102 /**< 6 kHz bandpass @hideinitializer*/
    204 #define OPUS_BANDWIDTH_WIDEBAND              1103 /**< 8 kHz bandpass @hideinitializer*/
    205 #define OPUS_BANDWIDTH_SUPERWIDEBAND         1104 /**<12 kHz bandpass @hideinitializer*/
    206 #define OPUS_BANDWIDTH_FULLBAND              1105 /**<20 kHz bandpass @hideinitializer*/
    207 
    208 #define OPUS_FRAMESIZE_ARG                   5000 /**< Select frame size from the argument (default) */
    209 #define OPUS_FRAMESIZE_2_5_MS                5001 /**< Use 2.5 ms frames */
    210 #define OPUS_FRAMESIZE_5_MS                  5002 /**< Use 5 ms frames */
    211 #define OPUS_FRAMESIZE_10_MS                 5003 /**< Use 10 ms frames */
    212 #define OPUS_FRAMESIZE_20_MS                 5004 /**< Use 20 ms frames */
    213 #define OPUS_FRAMESIZE_40_MS                 5005 /**< Use 40 ms frames */
    214 #define OPUS_FRAMESIZE_60_MS                 5006 /**< Use 60 ms frames */
    215 #define OPUS_FRAMESIZE_80_MS                 5007 /**< Use 80 ms frames */
    216 #define OPUS_FRAMESIZE_100_MS                5008 /**< Use 100 ms frames */
    217 #define OPUS_FRAMESIZE_120_MS                5009 /**< Use 120 ms frames */
    218 
    219 /**@}*/
    220 
    221 
    222 /** @defgroup opus_encoderctls Encoder related CTLs
    223   *
    224   * These are convenience macros for use with the \c opus_encode_ctl
    225   * interface. They are used to generate the appropriate series of
    226   * arguments for that call, passing the correct type, size and so
    227   * on as expected for each particular request.
    228   *
    229   * Some usage examples:
    230   *
    231   * @code
    232   * int ret;
    233   * ret = opus_encoder_ctl(enc_ctx, OPUS_SET_BANDWIDTH(OPUS_AUTO));
    234   * if (ret != OPUS_OK) return ret;
    235   *
    236   * opus_int32 rate;
    237   * opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&rate));
    238   *
    239   * opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE);
    240   * @endcode
    241   *
    242   * @see opus_genericctls, opus_encoder
    243   * @{
    244   */
    245 
    246 /** Configures the encoder's computational complexity.
    247   * The supported range is 0-10 inclusive with 10 representing the highest complexity.
    248   * @see OPUS_GET_COMPLEXITY
    249   * @param[in] x <tt>opus_int32</tt>: Allowed values: 0-10, inclusive.
    250   *
    251   * @hideinitializer */
    252 #define OPUS_SET_COMPLEXITY(x) OPUS_SET_COMPLEXITY_REQUEST, __opus_check_int(x)
    253 /** Gets the encoder's complexity configuration.
    254   * @see OPUS_SET_COMPLEXITY
    255   * @param[out] x <tt>opus_int32 *</tt>: Returns a value in the range 0-10,
    256   *                                      inclusive.
    257   * @hideinitializer */
    258 #define OPUS_GET_COMPLEXITY(x) OPUS_GET_COMPLEXITY_REQUEST, __opus_check_int_ptr(x)
    259 
    260 /** Configures the bitrate in the encoder.
    261   * Rates from 500 to 512000 bits per second are meaningful, as well as the
    262   * special values #OPUS_AUTO and #OPUS_BITRATE_MAX.
    263   * The value #OPUS_BITRATE_MAX can be used to cause the codec to use as much
    264   * rate as it can, which is useful for controlling the rate by adjusting the
    265   * output buffer size.
    266   * @see OPUS_GET_BITRATE
    267   * @param[in] x <tt>opus_int32</tt>: Bitrate in bits per second. The default
    268   *                                   is determined based on the number of
    269   *                                   channels and the input sampling rate.
    270   * @hideinitializer */
    271 #define OPUS_SET_BITRATE(x) OPUS_SET_BITRATE_REQUEST, __opus_check_int(x)
    272 /** Gets the encoder's bitrate configuration.
    273   * @see OPUS_SET_BITRATE
    274   * @param[out] x <tt>opus_int32 *</tt>: Returns the bitrate in bits per second.
    275   *                                      The default is determined based on the
    276   *                                      number of channels and the input
    277   *                                      sampling rate.
    278   * @hideinitializer */
    279 #define OPUS_GET_BITRATE(x) OPUS_GET_BITRATE_REQUEST, __opus_check_int_ptr(x)
    280 
    281 /** Enables or disables variable bitrate (VBR) in the encoder.
    282   * The configured bitrate may not be met exactly because frames must
    283   * be an integer number of bytes in length.
    284   * @see OPUS_GET_VBR
    285   * @see OPUS_SET_VBR_CONSTRAINT
    286   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    287   * <dl>
    288   * <dt>0</dt><dd>Hard CBR. For LPC/hybrid modes at very low bit-rate, this can
    289   *               cause noticeable quality degradation.</dd>
    290   * <dt>1</dt><dd>VBR (default). The exact type of VBR is controlled by
    291   *               #OPUS_SET_VBR_CONSTRAINT.</dd>
    292   * </dl>
    293   * @hideinitializer */
    294 #define OPUS_SET_VBR(x) OPUS_SET_VBR_REQUEST, __opus_check_int(x)
    295 /** Determine if variable bitrate (VBR) is enabled in the encoder.
    296   * @see OPUS_SET_VBR
    297   * @see OPUS_GET_VBR_CONSTRAINT
    298   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    299   * <dl>
    300   * <dt>0</dt><dd>Hard CBR.</dd>
    301   * <dt>1</dt><dd>VBR (default). The exact type of VBR may be retrieved via
    302   *               #OPUS_GET_VBR_CONSTRAINT.</dd>
    303   * </dl>
    304   * @hideinitializer */
    305 #define OPUS_GET_VBR(x) OPUS_GET_VBR_REQUEST, __opus_check_int_ptr(x)
    306 
    307 /** Enables or disables constrained VBR in the encoder.
    308   * This setting is ignored when the encoder is in CBR mode.
    309   * @warning Only the MDCT mode of Opus currently heeds the constraint.
    310   *  Speech mode ignores it completely, hybrid mode may fail to obey it
    311   *  if the LPC layer uses more bitrate than the constraint would have
    312   *  permitted.
    313   * @see OPUS_GET_VBR_CONSTRAINT
    314   * @see OPUS_SET_VBR
    315   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    316   * <dl>
    317   * <dt>0</dt><dd>Unconstrained VBR.</dd>
    318   * <dt>1</dt><dd>Constrained VBR (default). This creates a maximum of one
    319   *               frame of buffering delay assuming a transport with a
    320   *               serialization speed of the nominal bitrate.</dd>
    321   * </dl>
    322   * @hideinitializer */
    323 #define OPUS_SET_VBR_CONSTRAINT(x) OPUS_SET_VBR_CONSTRAINT_REQUEST, __opus_check_int(x)
    324 /** Determine if constrained VBR is enabled in the encoder.
    325   * @see OPUS_SET_VBR_CONSTRAINT
    326   * @see OPUS_GET_VBR
    327   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    328   * <dl>
    329   * <dt>0</dt><dd>Unconstrained VBR.</dd>
    330   * <dt>1</dt><dd>Constrained VBR (default).</dd>
    331   * </dl>
    332   * @hideinitializer */
    333 #define OPUS_GET_VBR_CONSTRAINT(x) OPUS_GET_VBR_CONSTRAINT_REQUEST, __opus_check_int_ptr(x)
    334 
    335 /** Configures mono/stereo forcing in the encoder.
    336   * This can force the encoder to produce packets encoded as either mono or
    337   * stereo, regardless of the format of the input audio. This is useful when
    338   * the caller knows that the input signal is currently a mono source embedded
    339   * in a stereo stream.
    340   * @see OPUS_GET_FORCE_CHANNELS
    341   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    342   * <dl>
    343   * <dt>#OPUS_AUTO</dt><dd>Not forced (default)</dd>
    344   * <dt>1</dt>         <dd>Forced mono</dd>
    345   * <dt>2</dt>         <dd>Forced stereo</dd>
    346   * </dl>
    347   * @hideinitializer */
    348 #define OPUS_SET_FORCE_CHANNELS(x) OPUS_SET_FORCE_CHANNELS_REQUEST, __opus_check_int(x)
    349 /** Gets the encoder's forced channel configuration.
    350   * @see OPUS_SET_FORCE_CHANNELS
    351   * @param[out] x <tt>opus_int32 *</tt>:
    352   * <dl>
    353   * <dt>#OPUS_AUTO</dt><dd>Not forced (default)</dd>
    354   * <dt>1</dt>         <dd>Forced mono</dd>
    355   * <dt>2</dt>         <dd>Forced stereo</dd>
    356   * </dl>
    357   * @hideinitializer */
    358 #define OPUS_GET_FORCE_CHANNELS(x) OPUS_GET_FORCE_CHANNELS_REQUEST, __opus_check_int_ptr(x)
    359 
    360 /** Configures the maximum bandpass that the encoder will select automatically.
    361   * Applications should normally use this instead of #OPUS_SET_BANDWIDTH
    362   * (leaving that set to the default, #OPUS_AUTO). This allows the
    363   * application to set an upper bound based on the type of input it is
    364   * providing, but still gives the encoder the freedom to reduce the bandpass
    365   * when the bitrate becomes too low, for better overall quality.
    366   * @see OPUS_GET_MAX_BANDWIDTH
    367   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    368   * <dl>
    369   * <dt>OPUS_BANDWIDTH_NARROWBAND</dt>    <dd>4 kHz passband</dd>
    370   * <dt>OPUS_BANDWIDTH_MEDIUMBAND</dt>    <dd>6 kHz passband</dd>
    371   * <dt>OPUS_BANDWIDTH_WIDEBAND</dt>      <dd>8 kHz passband</dd>
    372   * <dt>OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
    373   * <dt>OPUS_BANDWIDTH_FULLBAND</dt>     <dd>20 kHz passband (default)</dd>
    374   * </dl>
    375   * @hideinitializer */
    376 #define OPUS_SET_MAX_BANDWIDTH(x) OPUS_SET_MAX_BANDWIDTH_REQUEST, __opus_check_int(x)
    377 
    378 /** Gets the encoder's configured maximum allowed bandpass.
    379   * @see OPUS_SET_MAX_BANDWIDTH
    380   * @param[out] x <tt>opus_int32 *</tt>: Allowed values:
    381   * <dl>
    382   * <dt>#OPUS_BANDWIDTH_NARROWBAND</dt>    <dd>4 kHz passband</dd>
    383   * <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt>    <dd>6 kHz passband</dd>
    384   * <dt>#OPUS_BANDWIDTH_WIDEBAND</dt>      <dd>8 kHz passband</dd>
    385   * <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
    386   * <dt>#OPUS_BANDWIDTH_FULLBAND</dt>     <dd>20 kHz passband (default)</dd>
    387   * </dl>
    388   * @hideinitializer */
    389 #define OPUS_GET_MAX_BANDWIDTH(x) OPUS_GET_MAX_BANDWIDTH_REQUEST, __opus_check_int_ptr(x)
    390 
    391 /** Sets the encoder's bandpass to a specific value.
    392   * This prevents the encoder from automatically selecting the bandpass based
    393   * on the available bitrate. If an application knows the bandpass of the input
    394   * audio it is providing, it should normally use #OPUS_SET_MAX_BANDWIDTH
    395   * instead, which still gives the encoder the freedom to reduce the bandpass
    396   * when the bitrate becomes too low, for better overall quality.
    397   * @see OPUS_GET_BANDWIDTH
    398   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    399   * <dl>
    400   * <dt>#OPUS_AUTO</dt>                    <dd>(default)</dd>
    401   * <dt>#OPUS_BANDWIDTH_NARROWBAND</dt>    <dd>4 kHz passband</dd>
    402   * <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt>    <dd>6 kHz passband</dd>
    403   * <dt>#OPUS_BANDWIDTH_WIDEBAND</dt>      <dd>8 kHz passband</dd>
    404   * <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
    405   * <dt>#OPUS_BANDWIDTH_FULLBAND</dt>     <dd>20 kHz passband</dd>
    406   * </dl>
    407   * @hideinitializer */
    408 #define OPUS_SET_BANDWIDTH(x) OPUS_SET_BANDWIDTH_REQUEST, __opus_check_int(x)
    409 
    410 /** Configures the type of signal being encoded.
    411   * This is a hint which helps the encoder's mode selection.
    412   * @see OPUS_GET_SIGNAL
    413   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    414   * <dl>
    415   * <dt>#OPUS_AUTO</dt>        <dd>(default)</dd>
    416   * <dt>#OPUS_SIGNAL_VOICE</dt><dd>Bias thresholds towards choosing LPC or Hybrid modes.</dd>
    417   * <dt>#OPUS_SIGNAL_MUSIC</dt><dd>Bias thresholds towards choosing MDCT modes.</dd>
    418   * </dl>
    419   * @hideinitializer */
    420 #define OPUS_SET_SIGNAL(x) OPUS_SET_SIGNAL_REQUEST, __opus_check_int(x)
    421 /** Gets the encoder's configured signal type.
    422   * @see OPUS_SET_SIGNAL
    423   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    424   * <dl>
    425   * <dt>#OPUS_AUTO</dt>        <dd>(default)</dd>
    426   * <dt>#OPUS_SIGNAL_VOICE</dt><dd>Bias thresholds towards choosing LPC or Hybrid modes.</dd>
    427   * <dt>#OPUS_SIGNAL_MUSIC</dt><dd>Bias thresholds towards choosing MDCT modes.</dd>
    428   * </dl>
    429   * @hideinitializer */
    430 #define OPUS_GET_SIGNAL(x) OPUS_GET_SIGNAL_REQUEST, __opus_check_int_ptr(x)
    431 
    432 
    433 /** Configures the encoder's intended application.
    434   * The initial value is a mandatory argument to the encoder_create function.
    435   * @see OPUS_GET_APPLICATION
    436   * @param[in] x <tt>opus_int32</tt>: Returns one of the following values:
    437   * <dl>
    438   * <dt>#OPUS_APPLICATION_VOIP</dt>
    439   * <dd>Process signal for improved speech intelligibility.</dd>
    440   * <dt>#OPUS_APPLICATION_AUDIO</dt>
    441   * <dd>Favor faithfulness to the original input.</dd>
    442   * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
    443   * <dd>Configure the minimum possible coding delay by disabling certain modes
    444   * of operation.</dd>
    445   * </dl>
    446   * @hideinitializer */
    447 #define OPUS_SET_APPLICATION(x) OPUS_SET_APPLICATION_REQUEST, __opus_check_int(x)
    448 /** Gets the encoder's configured application.
    449   * @see OPUS_SET_APPLICATION
    450   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    451   * <dl>
    452   * <dt>#OPUS_APPLICATION_VOIP</dt>
    453   * <dd>Process signal for improved speech intelligibility.</dd>
    454   * <dt>#OPUS_APPLICATION_AUDIO</dt>
    455   * <dd>Favor faithfulness to the original input.</dd>
    456   * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
    457   * <dd>Configure the minimum possible coding delay by disabling certain modes
    458   * of operation.</dd>
    459   * </dl>
    460   * @hideinitializer */
    461 #define OPUS_GET_APPLICATION(x) OPUS_GET_APPLICATION_REQUEST, __opus_check_int_ptr(x)
    462 
    463 /** Gets the total samples of delay added by the entire codec.
    464   * This can be queried by the encoder and then the provided number of samples can be
    465   * skipped on from the start of the decoder's output to provide time aligned input
    466   * and output. From the perspective of a decoding application the real data begins this many
    467   * samples late.
    468   *
    469   * The decoder contribution to this delay is identical for all decoders, but the
    470   * encoder portion of the delay may vary from implementation to implementation,
    471   * version to version, or even depend on the encoder's initial configuration.
    472   * Applications needing delay compensation should call this CTL rather than
    473   * hard-coding a value.
    474   * @param[out] x <tt>opus_int32 *</tt>:   Number of lookahead samples
    475   * @hideinitializer */
    476 #define OPUS_GET_LOOKAHEAD(x) OPUS_GET_LOOKAHEAD_REQUEST, __opus_check_int_ptr(x)
    477 
    478 /** Configures the encoder's use of inband forward error correction (FEC).
    479   * @note This is only applicable to the LPC layer
    480   * @see OPUS_GET_INBAND_FEC
    481   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    482   * <dl>
    483   * <dt>0</dt><dd>Disable inband FEC (default).</dd>
    484   * <dt>1</dt><dd>Enable inband FEC.</dd>
    485   * </dl>
    486   * @hideinitializer */
    487 #define OPUS_SET_INBAND_FEC(x) OPUS_SET_INBAND_FEC_REQUEST, __opus_check_int(x)
    488 /** Gets encoder's configured use of inband forward error correction.
    489   * @see OPUS_SET_INBAND_FEC
    490   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    491   * <dl>
    492   * <dt>0</dt><dd>Inband FEC disabled (default).</dd>
    493   * <dt>1</dt><dd>Inband FEC enabled.</dd>
    494   * </dl>
    495   * @hideinitializer */
    496 #define OPUS_GET_INBAND_FEC(x) OPUS_GET_INBAND_FEC_REQUEST, __opus_check_int_ptr(x)
    497 
    498 /** Configures the encoder's expected packet loss percentage.
    499   * Higher values trigger progressively more loss resistant behavior in the encoder
    500   * at the expense of quality at a given bitrate in the absence of packet loss, but
    501   * greater quality under loss.
    502   * @see OPUS_GET_PACKET_LOSS_PERC
    503   * @param[in] x <tt>opus_int32</tt>:   Loss percentage in the range 0-100, inclusive (default: 0).
    504   * @hideinitializer */
    505 #define OPUS_SET_PACKET_LOSS_PERC(x) OPUS_SET_PACKET_LOSS_PERC_REQUEST, __opus_check_int(x)
    506 /** Gets the encoder's configured packet loss percentage.
    507   * @see OPUS_SET_PACKET_LOSS_PERC
    508   * @param[out] x <tt>opus_int32 *</tt>: Returns the configured loss percentage
    509   *                                      in the range 0-100, inclusive (default: 0).
    510   * @hideinitializer */
    511 #define OPUS_GET_PACKET_LOSS_PERC(x) OPUS_GET_PACKET_LOSS_PERC_REQUEST, __opus_check_int_ptr(x)
    512 
    513 /** Configures the encoder's use of discontinuous transmission (DTX).
    514   * @note This is only applicable to the LPC layer
    515   * @see OPUS_GET_DTX
    516   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    517   * <dl>
    518   * <dt>0</dt><dd>Disable DTX (default).</dd>
    519   * <dt>1</dt><dd>Enabled DTX.</dd>
    520   * </dl>
    521   * @hideinitializer */
    522 #define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __opus_check_int(x)
    523 /** Gets encoder's configured use of discontinuous transmission.
    524   * @see OPUS_SET_DTX
    525   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    526   * <dl>
    527   * <dt>0</dt><dd>DTX disabled (default).</dd>
    528   * <dt>1</dt><dd>DTX enabled.</dd>
    529   * </dl>
    530   * @hideinitializer */
    531 #define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __opus_check_int_ptr(x)
    532 /** Configures the depth of signal being encoded.
    533   *
    534   * This is a hint which helps the encoder identify silence and near-silence.
    535   * It represents the number of significant bits of linear intensity below
    536   * which the signal contains ignorable quantization or other noise.
    537   *
    538   * For example, OPUS_SET_LSB_DEPTH(14) would be an appropriate setting
    539   * for G.711 u-law input. OPUS_SET_LSB_DEPTH(16) would be appropriate
    540   * for 16-bit linear pcm input with opus_encode_float().
    541   *
    542   * When using opus_encode() instead of opus_encode_float(), or when libopus
    543   * is compiled for fixed-point, the encoder uses the minimum of the value
    544   * set here and the value 16.
    545   *
    546   * @see OPUS_GET_LSB_DEPTH
    547   * @param[in] x <tt>opus_int32</tt>: Input precision in bits, between 8 and 24
    548   *                                   (default: 24).
    549   * @hideinitializer */
    550 #define OPUS_SET_LSB_DEPTH(x) OPUS_SET_LSB_DEPTH_REQUEST, __opus_check_int(x)
    551 /** Gets the encoder's configured signal depth.
    552   * @see OPUS_SET_LSB_DEPTH
    553   * @param[out] x <tt>opus_int32 *</tt>: Input precision in bits, between 8 and
    554   *                                      24 (default: 24).
    555   * @hideinitializer */
    556 #define OPUS_GET_LSB_DEPTH(x) OPUS_GET_LSB_DEPTH_REQUEST, __opus_check_int_ptr(x)
    557 
    558 /** Configures the encoder's use of variable duration frames.
    559   * When variable duration is enabled, the encoder is free to use a shorter frame
    560   * size than the one requested in the opus_encode*() call.
    561   * It is then the user's responsibility
    562   * to verify how much audio was encoded by checking the ToC byte of the encoded
    563   * packet. The part of the audio that was not encoded needs to be resent to the
    564   * encoder for the next call. Do not use this option unless you <b>really</b>
    565   * know what you are doing.
    566   * @see OPUS_GET_EXPERT_FRAME_DURATION
    567   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    568   * <dl>
    569   * <dt>OPUS_FRAMESIZE_ARG</dt><dd>Select frame size from the argument (default).</dd>
    570   * <dt>OPUS_FRAMESIZE_2_5_MS</dt><dd>Use 2.5 ms frames.</dd>
    571   * <dt>OPUS_FRAMESIZE_5_MS</dt><dd>Use 5 ms frames.</dd>
    572   * <dt>OPUS_FRAMESIZE_10_MS</dt><dd>Use 10 ms frames.</dd>
    573   * <dt>OPUS_FRAMESIZE_20_MS</dt><dd>Use 20 ms frames.</dd>
    574   * <dt>OPUS_FRAMESIZE_40_MS</dt><dd>Use 40 ms frames.</dd>
    575   * <dt>OPUS_FRAMESIZE_60_MS</dt><dd>Use 60 ms frames.</dd>
    576   * <dt>OPUS_FRAMESIZE_80_MS</dt><dd>Use 80 ms frames.</dd>
    577   * <dt>OPUS_FRAMESIZE_100_MS</dt><dd>Use 100 ms frames.</dd>
    578   * <dt>OPUS_FRAMESIZE_120_MS</dt><dd>Use 120 ms frames.</dd>
    579   * </dl>
    580   * @hideinitializer */
    581 #define OPUS_SET_EXPERT_FRAME_DURATION(x) OPUS_SET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int(x)
    582 /** Gets the encoder's configured use of variable duration frames.
    583   * @see OPUS_SET_EXPERT_FRAME_DURATION
    584   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    585   * <dl>
    586   * <dt>OPUS_FRAMESIZE_ARG</dt><dd>Select frame size from the argument (default).</dd>
    587   * <dt>OPUS_FRAMESIZE_2_5_MS</dt><dd>Use 2.5 ms frames.</dd>
    588   * <dt>OPUS_FRAMESIZE_5_MS</dt><dd>Use 5 ms frames.</dd>
    589   * <dt>OPUS_FRAMESIZE_10_MS</dt><dd>Use 10 ms frames.</dd>
    590   * <dt>OPUS_FRAMESIZE_20_MS</dt><dd>Use 20 ms frames.</dd>
    591   * <dt>OPUS_FRAMESIZE_40_MS</dt><dd>Use 40 ms frames.</dd>
    592   * <dt>OPUS_FRAMESIZE_60_MS</dt><dd>Use 60 ms frames.</dd>
    593   * <dt>OPUS_FRAMESIZE_80_MS</dt><dd>Use 80 ms frames.</dd>
    594   * <dt>OPUS_FRAMESIZE_100_MS</dt><dd>Use 100 ms frames.</dd>
    595   * <dt>OPUS_FRAMESIZE_120_MS</dt><dd>Use 120 ms frames.</dd>
    596   * </dl>
    597   * @hideinitializer */
    598 #define OPUS_GET_EXPERT_FRAME_DURATION(x) OPUS_GET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int_ptr(x)
    599 
    600 /** If set to 1, disables almost all use of prediction, making frames almost
    601   * completely independent. This reduces quality.
    602   * @see OPUS_GET_PREDICTION_DISABLED
    603   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    604   * <dl>
    605   * <dt>0</dt><dd>Enable prediction (default).</dd>
    606   * <dt>1</dt><dd>Disable prediction.</dd>
    607   * </dl>
    608   * @hideinitializer */
    609 #define OPUS_SET_PREDICTION_DISABLED(x) OPUS_SET_PREDICTION_DISABLED_REQUEST, __opus_check_int(x)
    610 /** Gets the encoder's configured prediction status.
    611   * @see OPUS_SET_PREDICTION_DISABLED
    612   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    613   * <dl>
    614   * <dt>0</dt><dd>Prediction enabled (default).</dd>
    615   * <dt>1</dt><dd>Prediction disabled.</dd>
    616   * </dl>
    617   * @hideinitializer */
    618 #define OPUS_GET_PREDICTION_DISABLED(x) OPUS_GET_PREDICTION_DISABLED_REQUEST, __opus_check_int_ptr(x)
    619 
    620 /**@}*/
    621 
    622 /** @defgroup opus_genericctls Generic CTLs
    623   *
    624   * These macros are used with the \c opus_decoder_ctl and
    625   * \c opus_encoder_ctl calls to generate a particular
    626   * request.
    627   *
    628   * When called on an \c OpusDecoder they apply to that
    629   * particular decoder instance. When called on an
    630   * \c OpusEncoder they apply to the corresponding setting
    631   * on that encoder instance, if present.
    632   *
    633   * Some usage examples:
    634   *
    635   * @code
    636   * int ret;
    637   * opus_int32 pitch;
    638   * ret = opus_decoder_ctl(dec_ctx, OPUS_GET_PITCH(&pitch));
    639   * if (ret == OPUS_OK) return ret;
    640   *
    641   * opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE);
    642   * opus_decoder_ctl(dec_ctx, OPUS_RESET_STATE);
    643   *
    644   * opus_int32 enc_bw, dec_bw;
    645   * opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&enc_bw));
    646   * opus_decoder_ctl(dec_ctx, OPUS_GET_BANDWIDTH(&dec_bw));
    647   * if (enc_bw != dec_bw) {
    648   *   printf("packet bandwidth mismatch!\n");
    649   * }
    650   * @endcode
    651   *
    652   * @see opus_encoder, opus_decoder_ctl, opus_encoder_ctl, opus_decoderctls, opus_encoderctls
    653   * @{
    654   */
    655 
    656 /** Resets the codec state to be equivalent to a freshly initialized state.
    657   * This should be called when switching streams in order to prevent
    658   * the back to back decoding from giving different results from
    659   * one at a time decoding.
    660   * @hideinitializer */
    661 #define OPUS_RESET_STATE 4028
    662 
    663 /** Gets the final state of the codec's entropy coder.
    664   * This is used for testing purposes,
    665   * The encoder and decoder state should be identical after coding a payload
    666   * (assuming no data corruption or software bugs)
    667   *
    668   * @param[out] x <tt>opus_uint32 *</tt>: Entropy coder state
    669   *
    670   * @hideinitializer */
    671 #define OPUS_GET_FINAL_RANGE(x) OPUS_GET_FINAL_RANGE_REQUEST, __opus_check_uint_ptr(x)
    672 
    673 /** Gets the encoder's configured bandpass or the decoder's last bandpass.
    674   * @see OPUS_SET_BANDWIDTH
    675   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    676   * <dl>
    677   * <dt>#OPUS_AUTO</dt>                    <dd>(default)</dd>
    678   * <dt>#OPUS_BANDWIDTH_NARROWBAND</dt>    <dd>4 kHz passband</dd>
    679   * <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt>    <dd>6 kHz passband</dd>
    680   * <dt>#OPUS_BANDWIDTH_WIDEBAND</dt>      <dd>8 kHz passband</dd>
    681   * <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
    682   * <dt>#OPUS_BANDWIDTH_FULLBAND</dt>     <dd>20 kHz passband</dd>
    683   * </dl>
    684   * @hideinitializer */
    685 #define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __opus_check_int_ptr(x)
    686 
    687 /** Gets the sampling rate the encoder or decoder was initialized with.
    688   * This simply returns the <code>Fs</code> value passed to opus_encoder_init()
    689   * or opus_decoder_init().
    690   * @param[out] x <tt>opus_int32 *</tt>: Sampling rate of encoder or decoder.
    691   * @hideinitializer
    692   */
    693 #define OPUS_GET_SAMPLE_RATE(x) OPUS_GET_SAMPLE_RATE_REQUEST, __opus_check_int_ptr(x)
    694 
    695 /** If set to 1, disables the use of phase inversion for intensity stereo,
    696   * improving the quality of mono downmixes, but slightly reducing normal
    697   * stereo quality. Disabling phase inversion in the decoder does not comply
    698   * with RFC 6716, although it does not cause any interoperability issue and
    699   * is expected to become part of the Opus standard once RFC 6716 is updated
    700   * by draft-ietf-codec-opus-update.
    701   * @see OPUS_GET_PHASE_INVERSION_DISABLED
    702   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    703   * <dl>
    704   * <dt>0</dt><dd>Enable phase inversion (default).</dd>
    705   * <dt>1</dt><dd>Disable phase inversion.</dd>
    706   * </dl>
    707   * @hideinitializer */
    708 #define OPUS_SET_PHASE_INVERSION_DISABLED(x) OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST, __opus_check_int(x)
    709 /** Gets the encoder's configured phase inversion status.
    710   * @see OPUS_SET_PHASE_INVERSION_DISABLED
    711   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    712   * <dl>
    713   * <dt>0</dt><dd>Stereo phase inversion enabled (default).</dd>
    714   * <dt>1</dt><dd>Stereo phase inversion disabled.</dd>
    715   * </dl>
    716   * @hideinitializer */
    717 #define OPUS_GET_PHASE_INVERSION_DISABLED(x) OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST, __opus_check_int_ptr(x)
    718 
    719 /**@}*/
    720 
    721 /** @defgroup opus_decoderctls Decoder related CTLs
    722   * @see opus_genericctls, opus_encoderctls, opus_decoder
    723   * @{
    724   */
    725 
    726 /** Configures decoder gain adjustment.
    727   * Scales the decoded output by a factor specified in Q8 dB units.
    728   * This has a maximum range of -32768 to 32767 inclusive, and returns
    729   * OPUS_BAD_ARG otherwise. The default is zero indicating no adjustment.
    730   * This setting survives decoder reset.
    731   *
    732   * gain = pow(10, x/(20.0*256))
    733   *
    734   * @param[in] x <tt>opus_int32</tt>:   Amount to scale PCM signal by in Q8 dB units.
    735   * @hideinitializer */
    736 #define OPUS_SET_GAIN(x) OPUS_SET_GAIN_REQUEST, __opus_check_int(x)
    737 /** Gets the decoder's configured gain adjustment. @see OPUS_SET_GAIN
    738   *
    739   * @param[out] x <tt>opus_int32 *</tt>: Amount to scale PCM signal by in Q8 dB units.
    740   * @hideinitializer */
    741 #define OPUS_GET_GAIN(x) OPUS_GET_GAIN_REQUEST, __opus_check_int_ptr(x)
    742 
    743 /** Gets the duration (in samples) of the last packet successfully decoded or concealed.
    744   * @param[out] x <tt>opus_int32 *</tt>: Number of samples (at current sampling rate).
    745   * @hideinitializer */
    746 #define OPUS_GET_LAST_PACKET_DURATION(x) OPUS_GET_LAST_PACKET_DURATION_REQUEST, __opus_check_int_ptr(x)
    747 
    748 /** Gets the pitch of the last decoded frame, if available.
    749   * This can be used for any post-processing algorithm requiring the use of pitch,
    750   * e.g. time stretching/shortening. If the last frame was not voiced, or if the
    751   * pitch was not coded in the frame, then zero is returned.
    752   *
    753   * This CTL is only implemented for decoder instances.
    754   *
    755   * @param[out] x <tt>opus_int32 *</tt>: pitch period at 48 kHz (or 0 if not available)
    756   *
    757   * @hideinitializer */
    758 #define OPUS_GET_PITCH(x) OPUS_GET_PITCH_REQUEST, __opus_check_int_ptr(x)
    759 
    760 /**@}*/
    761 
    762 /** @defgroup opus_libinfo Opus library information functions
    763   * @{
    764   */
    765 
    766 /** Converts an opus error code into a human readable string.
    767   *
    768   * @param[in] error <tt>int</tt>: Error number
    769   * @returns Error string
    770   */
    771 OPUS_EXPORT const char *opus_strerror(int error);
    772 
    773 /** Gets the libopus version string.
    774   *
    775   * Applications may look for the substring "-fixed" in the version string to
    776   * determine whether they have a fixed-point or floating-point build at
    777   * runtime.
    778   *
    779   * @returns Version string
    780   */
    781 OPUS_EXPORT const char *opus_get_version_string(void);
    782 /**@}*/
    783 
    784 #ifdef __cplusplus
    785 }
    786 #endif
    787 
    788 #endif /* OPUS_DEFINES_H */
    789