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(WIN32)
     68 #  ifdef OPUS_BUILD
     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 /**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 #define OPUS_GET_LAST_PACKET_DURATION_REQUEST 4039
    152 #define OPUS_SET_EXPERT_FRAME_DURATION_REQUEST 4040
    153 #define OPUS_GET_EXPERT_FRAME_DURATION_REQUEST 4041
    154 
    155 /* Don't use 4045, it's already taken by OPUS_GET_GAIN_REQUEST */
    156 
    157 /* Macros to trigger compilation errors when the wrong types are provided to a CTL */
    158 #define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x))
    159 #define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr)))
    160 #define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr)))
    161 #define __opus_check_val16_ptr(ptr) ((ptr) + ((ptr) - (opus_val16*)(ptr)))
    162 /** @endcond */
    163 
    164 /** @defgroup opus_ctlvalues Pre-defined values for CTL interface
    165   * @see opus_genericctls, opus_encoderctls
    166   * @{
    167   */
    168 /* Values for the various encoder CTLs */
    169 #define OPUS_AUTO                           -1000 /**<Auto/default setting @hideinitializer*/
    170 #define OPUS_BITRATE_MAX                       -1 /**<Maximum bitrate @hideinitializer*/
    171 
    172 /** Best for most VoIP/videoconference applications where listening quality and intelligibility matter most
    173  * @hideinitializer */
    174 #define OPUS_APPLICATION_VOIP                2048
    175 /** Best for broadcast/high-fidelity application where the decoded audio should be as close as possible to the input
    176  * @hideinitializer */
    177 #define OPUS_APPLICATION_AUDIO               2049
    178 /** Only use when lowest-achievable latency is what matters most. Voice-optimized modes cannot be used.
    179  * @hideinitializer */
    180 #define OPUS_APPLICATION_RESTRICTED_LOWDELAY 2051
    181 
    182 #define OPUS_SIGNAL_VOICE                    3001 /**< Signal being encoded is voice */
    183 #define OPUS_SIGNAL_MUSIC                    3002 /**< Signal being encoded is music */
    184 #define OPUS_BANDWIDTH_NARROWBAND            1101 /**< 4 kHz bandpass @hideinitializer*/
    185 #define OPUS_BANDWIDTH_MEDIUMBAND            1102 /**< 6 kHz bandpass @hideinitializer*/
    186 #define OPUS_BANDWIDTH_WIDEBAND              1103 /**< 8 kHz bandpass @hideinitializer*/
    187 #define OPUS_BANDWIDTH_SUPERWIDEBAND         1104 /**<12 kHz bandpass @hideinitializer*/
    188 #define OPUS_BANDWIDTH_FULLBAND              1105 /**<20 kHz bandpass @hideinitializer*/
    189 
    190 #define OPUS_FRAMESIZE_ARG                   5000 /**< Select frame size from the argument (default) */
    191 #define OPUS_FRAMESIZE_2_5_MS                5001 /**< Use 2.5 ms frames */
    192 #define OPUS_FRAMESIZE_5_MS                  5002 /**< Use 5 ms frames */
    193 #define OPUS_FRAMESIZE_10_MS                 5003 /**< Use 10 ms frames */
    194 #define OPUS_FRAMESIZE_20_MS                 5004 /**< Use 20 ms frames */
    195 #define OPUS_FRAMESIZE_40_MS                 5005 /**< Use 40 ms frames */
    196 #define OPUS_FRAMESIZE_60_MS                 5006 /**< Use 60 ms frames */
    197 #define OPUS_FRAMESIZE_VARIABLE              5010 /**< Optimize the frame size dynamically */
    198 
    199 /**@}*/
    200 
    201 
    202 /** @defgroup opus_encoderctls Encoder related CTLs
    203   *
    204   * These are convenience macros for use with the \c opus_encode_ctl
    205   * interface. They are used to generate the appropriate series of
    206   * arguments for that call, passing the correct type, size and so
    207   * on as expected for each particular request.
    208   *
    209   * Some usage examples:
    210   *
    211   * @code
    212   * int ret;
    213   * ret = opus_encoder_ctl(enc_ctx, OPUS_SET_BANDWIDTH(OPUS_AUTO));
    214   * if (ret != OPUS_OK) return ret;
    215   *
    216   * opus_int32 rate;
    217   * opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&rate));
    218   *
    219   * opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE);
    220   * @endcode
    221   *
    222   * @see opus_genericctls, opus_encoder
    223   * @{
    224   */
    225 
    226 /** Configures the encoder's computational complexity.
    227   * The supported range is 0-10 inclusive with 10 representing the highest complexity.
    228   * @see OPUS_GET_COMPLEXITY
    229   * @param[in] x <tt>opus_int32</tt>: Allowed values: 0-10, inclusive.
    230   *
    231   * @hideinitializer */
    232 #define OPUS_SET_COMPLEXITY(x) OPUS_SET_COMPLEXITY_REQUEST, __opus_check_int(x)
    233 /** Gets the encoder's complexity configuration.
    234   * @see OPUS_SET_COMPLEXITY
    235   * @param[out] x <tt>opus_int32 *</tt>: Returns a value in the range 0-10,
    236   *                                      inclusive.
    237   * @hideinitializer */
    238 #define OPUS_GET_COMPLEXITY(x) OPUS_GET_COMPLEXITY_REQUEST, __opus_check_int_ptr(x)
    239 
    240 /** Configures the bitrate in the encoder.
    241   * Rates from 500 to 512000 bits per second are meaningful, as well as the
    242   * special values #OPUS_AUTO and #OPUS_BITRATE_MAX.
    243   * The value #OPUS_BITRATE_MAX can be used to cause the codec to use as much
    244   * rate as it can, which is useful for controlling the rate by adjusting the
    245   * output buffer size.
    246   * @see OPUS_GET_BITRATE
    247   * @param[in] x <tt>opus_int32</tt>: Bitrate in bits per second. The default
    248   *                                   is determined based on the number of
    249   *                                   channels and the input sampling rate.
    250   * @hideinitializer */
    251 #define OPUS_SET_BITRATE(x) OPUS_SET_BITRATE_REQUEST, __opus_check_int(x)
    252 /** Gets the encoder's bitrate configuration.
    253   * @see OPUS_SET_BITRATE
    254   * @param[out] x <tt>opus_int32 *</tt>: Returns the bitrate in bits per second.
    255   *                                      The default is determined based on the
    256   *                                      number of channels and the input
    257   *                                      sampling rate.
    258   * @hideinitializer */
    259 #define OPUS_GET_BITRATE(x) OPUS_GET_BITRATE_REQUEST, __opus_check_int_ptr(x)
    260 
    261 /** Enables or disables variable bitrate (VBR) in the encoder.
    262   * The configured bitrate may not be met exactly because frames must
    263   * be an integer number of bytes in length.
    264   * @warning Only the MDCT mode of Opus can provide hard CBR behavior.
    265   * @see OPUS_GET_VBR
    266   * @see OPUS_SET_VBR_CONSTRAINT
    267   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    268   * <dl>
    269   * <dt>0</dt><dd>Hard CBR. For LPC/hybrid modes at very low bit-rate, this can
    270   *               cause noticeable quality degradation.</dd>
    271   * <dt>1</dt><dd>VBR (default). The exact type of VBR is controlled by
    272   *               #OPUS_SET_VBR_CONSTRAINT.</dd>
    273   * </dl>
    274   * @hideinitializer */
    275 #define OPUS_SET_VBR(x) OPUS_SET_VBR_REQUEST, __opus_check_int(x)
    276 /** Determine if variable bitrate (VBR) is enabled in the encoder.
    277   * @see OPUS_SET_VBR
    278   * @see OPUS_GET_VBR_CONSTRAINT
    279   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    280   * <dl>
    281   * <dt>0</dt><dd>Hard CBR.</dd>
    282   * <dt>1</dt><dd>VBR (default). The exact type of VBR may be retrieved via
    283   *               #OPUS_GET_VBR_CONSTRAINT.</dd>
    284   * </dl>
    285   * @hideinitializer */
    286 #define OPUS_GET_VBR(x) OPUS_GET_VBR_REQUEST, __opus_check_int_ptr(x)
    287 
    288 /** Enables or disables constrained VBR in the encoder.
    289   * This setting is ignored when the encoder is in CBR mode.
    290   * @warning Only the MDCT mode of Opus currently heeds the constraint.
    291   *  Speech mode ignores it completely, hybrid mode may fail to obey it
    292   *  if the LPC layer uses more bitrate than the constraint would have
    293   *  permitted.
    294   * @see OPUS_GET_VBR_CONSTRAINT
    295   * @see OPUS_SET_VBR
    296   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    297   * <dl>
    298   * <dt>0</dt><dd>Unconstrained VBR.</dd>
    299   * <dt>1</dt><dd>Constrained VBR (default). This creates a maximum of one
    300   *               frame of buffering delay assuming a transport with a
    301   *               serialization speed of the nominal bitrate.</dd>
    302   * </dl>
    303   * @hideinitializer */
    304 #define OPUS_SET_VBR_CONSTRAINT(x) OPUS_SET_VBR_CONSTRAINT_REQUEST, __opus_check_int(x)
    305 /** Determine if constrained VBR is enabled in the encoder.
    306   * @see OPUS_SET_VBR_CONSTRAINT
    307   * @see OPUS_GET_VBR
    308   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    309   * <dl>
    310   * <dt>0</dt><dd>Unconstrained VBR.</dd>
    311   * <dt>1</dt><dd>Constrained VBR (default).</dd>
    312   * </dl>
    313   * @hideinitializer */
    314 #define OPUS_GET_VBR_CONSTRAINT(x) OPUS_GET_VBR_CONSTRAINT_REQUEST, __opus_check_int_ptr(x)
    315 
    316 /** Configures mono/stereo forcing in the encoder.
    317   * This can force the encoder to produce packets encoded as either mono or
    318   * stereo, regardless of the format of the input audio. This is useful when
    319   * the caller knows that the input signal is currently a mono source embedded
    320   * in a stereo stream.
    321   * @see OPUS_GET_FORCE_CHANNELS
    322   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    323   * <dl>
    324   * <dt>#OPUS_AUTO</dt><dd>Not forced (default)</dd>
    325   * <dt>1</dt>         <dd>Forced mono</dd>
    326   * <dt>2</dt>         <dd>Forced stereo</dd>
    327   * </dl>
    328   * @hideinitializer */
    329 #define OPUS_SET_FORCE_CHANNELS(x) OPUS_SET_FORCE_CHANNELS_REQUEST, __opus_check_int(x)
    330 /** Gets the encoder's forced channel configuration.
    331   * @see OPUS_SET_FORCE_CHANNELS
    332   * @param[out] x <tt>opus_int32 *</tt>:
    333   * <dl>
    334   * <dt>#OPUS_AUTO</dt><dd>Not forced (default)</dd>
    335   * <dt>1</dt>         <dd>Forced mono</dd>
    336   * <dt>2</dt>         <dd>Forced stereo</dd>
    337   * </dl>
    338   * @hideinitializer */
    339 #define OPUS_GET_FORCE_CHANNELS(x) OPUS_GET_FORCE_CHANNELS_REQUEST, __opus_check_int_ptr(x)
    340 
    341 /** Configures the maximum bandpass that the encoder will select automatically.
    342   * Applications should normally use this instead of #OPUS_SET_BANDWIDTH
    343   * (leaving that set to the default, #OPUS_AUTO). This allows the
    344   * application to set an upper bound based on the type of input it is
    345   * providing, but still gives the encoder the freedom to reduce the bandpass
    346   * when the bitrate becomes too low, for better overall quality.
    347   * @see OPUS_GET_MAX_BANDWIDTH
    348   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    349   * <dl>
    350   * <dt>OPUS_BANDWIDTH_NARROWBAND</dt>    <dd>4 kHz passband</dd>
    351   * <dt>OPUS_BANDWIDTH_MEDIUMBAND</dt>    <dd>6 kHz passband</dd>
    352   * <dt>OPUS_BANDWIDTH_WIDEBAND</dt>      <dd>8 kHz passband</dd>
    353   * <dt>OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
    354   * <dt>OPUS_BANDWIDTH_FULLBAND</dt>     <dd>20 kHz passband (default)</dd>
    355   * </dl>
    356   * @hideinitializer */
    357 #define OPUS_SET_MAX_BANDWIDTH(x) OPUS_SET_MAX_BANDWIDTH_REQUEST, __opus_check_int(x)
    358 
    359 /** Gets the encoder's configured maximum allowed bandpass.
    360   * @see OPUS_SET_MAX_BANDWIDTH
    361   * @param[out] x <tt>opus_int32 *</tt>: Allowed values:
    362   * <dl>
    363   * <dt>#OPUS_BANDWIDTH_NARROWBAND</dt>    <dd>4 kHz passband</dd>
    364   * <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt>    <dd>6 kHz passband</dd>
    365   * <dt>#OPUS_BANDWIDTH_WIDEBAND</dt>      <dd>8 kHz passband</dd>
    366   * <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
    367   * <dt>#OPUS_BANDWIDTH_FULLBAND</dt>     <dd>20 kHz passband (default)</dd>
    368   * </dl>
    369   * @hideinitializer */
    370 #define OPUS_GET_MAX_BANDWIDTH(x) OPUS_GET_MAX_BANDWIDTH_REQUEST, __opus_check_int_ptr(x)
    371 
    372 /** Sets the encoder's bandpass to a specific value.
    373   * This prevents the encoder from automatically selecting the bandpass based
    374   * on the available bitrate. If an application knows the bandpass of the input
    375   * audio it is providing, it should normally use #OPUS_SET_MAX_BANDWIDTH
    376   * instead, which still gives the encoder the freedom to reduce the bandpass
    377   * when the bitrate becomes too low, for better overall quality.
    378   * @see OPUS_GET_BANDWIDTH
    379   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    380   * <dl>
    381   * <dt>#OPUS_AUTO</dt>                    <dd>(default)</dd>
    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</dd>
    387   * </dl>
    388   * @hideinitializer */
    389 #define OPUS_SET_BANDWIDTH(x) OPUS_SET_BANDWIDTH_REQUEST, __opus_check_int(x)
    390 
    391 /** Configures the type of signal being encoded.
    392   * This is a hint which helps the encoder's mode selection.
    393   * @see OPUS_GET_SIGNAL
    394   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    395   * <dl>
    396   * <dt>#OPUS_AUTO</dt>        <dd>(default)</dd>
    397   * <dt>#OPUS_SIGNAL_VOICE</dt><dd>Bias thresholds towards choosing LPC or Hybrid modes.</dd>
    398   * <dt>#OPUS_SIGNAL_MUSIC</dt><dd>Bias thresholds towards choosing MDCT modes.</dd>
    399   * </dl>
    400   * @hideinitializer */
    401 #define OPUS_SET_SIGNAL(x) OPUS_SET_SIGNAL_REQUEST, __opus_check_int(x)
    402 /** Gets the encoder's configured signal type.
    403   * @see OPUS_SET_SIGNAL
    404   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    405   * <dl>
    406   * <dt>#OPUS_AUTO</dt>        <dd>(default)</dd>
    407   * <dt>#OPUS_SIGNAL_VOICE</dt><dd>Bias thresholds towards choosing LPC or Hybrid modes.</dd>
    408   * <dt>#OPUS_SIGNAL_MUSIC</dt><dd>Bias thresholds towards choosing MDCT modes.</dd>
    409   * </dl>
    410   * @hideinitializer */
    411 #define OPUS_GET_SIGNAL(x) OPUS_GET_SIGNAL_REQUEST, __opus_check_int_ptr(x)
    412 
    413 
    414 /** Configures the encoder's intended application.
    415   * The initial value is a mandatory argument to the encoder_create function.
    416   * @see OPUS_GET_APPLICATION
    417   * @param[in] x <tt>opus_int32</tt>: Returns one of the following values:
    418   * <dl>
    419   * <dt>#OPUS_APPLICATION_VOIP</dt>
    420   * <dd>Process signal for improved speech intelligibility.</dd>
    421   * <dt>#OPUS_APPLICATION_AUDIO</dt>
    422   * <dd>Favor faithfulness to the original input.</dd>
    423   * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
    424   * <dd>Configure the minimum possible coding delay by disabling certain modes
    425   * of operation.</dd>
    426   * </dl>
    427   * @hideinitializer */
    428 #define OPUS_SET_APPLICATION(x) OPUS_SET_APPLICATION_REQUEST, __opus_check_int(x)
    429 /** Gets the encoder's configured application.
    430   * @see OPUS_SET_APPLICATION
    431   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    432   * <dl>
    433   * <dt>#OPUS_APPLICATION_VOIP</dt>
    434   * <dd>Process signal for improved speech intelligibility.</dd>
    435   * <dt>#OPUS_APPLICATION_AUDIO</dt>
    436   * <dd>Favor faithfulness to the original input.</dd>
    437   * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
    438   * <dd>Configure the minimum possible coding delay by disabling certain modes
    439   * of operation.</dd>
    440   * </dl>
    441   * @hideinitializer */
    442 #define OPUS_GET_APPLICATION(x) OPUS_GET_APPLICATION_REQUEST, __opus_check_int_ptr(x)
    443 
    444 /** Gets the sampling rate the encoder or decoder was initialized with.
    445   * This simply returns the <code>Fs</code> value passed to opus_encoder_init()
    446   * or opus_decoder_init().
    447   * @param[out] x <tt>opus_int32 *</tt>: Sampling rate of encoder or decoder.
    448   * @hideinitializer
    449   */
    450 #define OPUS_GET_SAMPLE_RATE(x) OPUS_GET_SAMPLE_RATE_REQUEST, __opus_check_int_ptr(x)
    451 
    452 /** Gets the total samples of delay added by the entire codec.
    453   * This can be queried by the encoder and then the provided number of samples can be
    454   * skipped on from the start of the decoder's output to provide time aligned input
    455   * and output. From the perspective of a decoding application the real data begins this many
    456   * samples late.
    457   *
    458   * The decoder contribution to this delay is identical for all decoders, but the
    459   * encoder portion of the delay may vary from implementation to implementation,
    460   * version to version, or even depend on the encoder's initial configuration.
    461   * Applications needing delay compensation should call this CTL rather than
    462   * hard-coding a value.
    463   * @param[out] x <tt>opus_int32 *</tt>:   Number of lookahead samples
    464   * @hideinitializer */
    465 #define OPUS_GET_LOOKAHEAD(x) OPUS_GET_LOOKAHEAD_REQUEST, __opus_check_int_ptr(x)
    466 
    467 /** Configures the encoder's use of inband forward error correction (FEC).
    468   * @note This is only applicable to the LPC layer
    469   * @see OPUS_GET_INBAND_FEC
    470   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    471   * <dl>
    472   * <dt>0</dt><dd>Disable inband FEC (default).</dd>
    473   * <dt>1</dt><dd>Enable inband FEC.</dd>
    474   * </dl>
    475   * @hideinitializer */
    476 #define OPUS_SET_INBAND_FEC(x) OPUS_SET_INBAND_FEC_REQUEST, __opus_check_int(x)
    477 /** Gets encoder's configured use of inband forward error correction.
    478   * @see OPUS_SET_INBAND_FEC
    479   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    480   * <dl>
    481   * <dt>0</dt><dd>Inband FEC disabled (default).</dd>
    482   * <dt>1</dt><dd>Inband FEC enabled.</dd>
    483   * </dl>
    484   * @hideinitializer */
    485 #define OPUS_GET_INBAND_FEC(x) OPUS_GET_INBAND_FEC_REQUEST, __opus_check_int_ptr(x)
    486 
    487 /** Configures the encoder's expected packet loss percentage.
    488   * Higher values with trigger progressively more loss resistant behavior in the encoder
    489   * at the expense of quality at a given bitrate in the lossless case, but greater quality
    490   * under loss.
    491   * @see OPUS_GET_PACKET_LOSS_PERC
    492   * @param[in] x <tt>opus_int32</tt>:   Loss percentage in the range 0-100, inclusive (default: 0).
    493   * @hideinitializer */
    494 #define OPUS_SET_PACKET_LOSS_PERC(x) OPUS_SET_PACKET_LOSS_PERC_REQUEST, __opus_check_int(x)
    495 /** Gets the encoder's configured packet loss percentage.
    496   * @see OPUS_SET_PACKET_LOSS_PERC
    497   * @param[out] x <tt>opus_int32 *</tt>: Returns the configured loss percentage
    498   *                                      in the range 0-100, inclusive (default: 0).
    499   * @hideinitializer */
    500 #define OPUS_GET_PACKET_LOSS_PERC(x) OPUS_GET_PACKET_LOSS_PERC_REQUEST, __opus_check_int_ptr(x)
    501 
    502 /** Configures the encoder's use of discontinuous transmission (DTX).
    503   * @note This is only applicable to the LPC layer
    504   * @see OPUS_GET_DTX
    505   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    506   * <dl>
    507   * <dt>0</dt><dd>Disable DTX (default).</dd>
    508   * <dt>1</dt><dd>Enabled DTX.</dd>
    509   * </dl>
    510   * @hideinitializer */
    511 #define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __opus_check_int(x)
    512 /** Gets encoder's configured use of discontinuous transmission.
    513   * @see OPUS_SET_DTX
    514   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    515   * <dl>
    516   * <dt>0</dt><dd>DTX disabled (default).</dd>
    517   * <dt>1</dt><dd>DTX enabled.</dd>
    518   * </dl>
    519   * @hideinitializer */
    520 #define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __opus_check_int_ptr(x)
    521 /** Configures the depth of signal being encoded.
    522   * This is a hint which helps the encoder identify silence and near-silence.
    523   * @see OPUS_GET_LSB_DEPTH
    524   * @param[in] x <tt>opus_int32</tt>: Input precision in bits, between 8 and 24
    525   *                                   (default: 24).
    526   * @hideinitializer */
    527 #define OPUS_SET_LSB_DEPTH(x) OPUS_SET_LSB_DEPTH_REQUEST, __opus_check_int(x)
    528 /** Gets the encoder's configured signal depth.
    529   * @see OPUS_SET_LSB_DEPTH
    530   * @param[out] x <tt>opus_int32 *</tt>: Input precision in bits, between 8 and
    531   *                                      24 (default: 24).
    532   * @hideinitializer */
    533 #define OPUS_GET_LSB_DEPTH(x) OPUS_GET_LSB_DEPTH_REQUEST, __opus_check_int_ptr(x)
    534 
    535 /** Gets the duration (in samples) of the last packet successfully decoded or concealed.
    536   * @param[out] x <tt>opus_int32 *</tt>: Number of samples (at current sampling rate).
    537   * @hideinitializer */
    538 #define OPUS_GET_LAST_PACKET_DURATION(x) OPUS_GET_LAST_PACKET_DURATION_REQUEST, __opus_check_int_ptr(x)
    539 
    540 /** Configures the encoder's use of variable duration frames.
    541   * When variable duration is enabled, the encoder is free to use a shorter frame
    542   * size than the one requested in the opus_encode*() call.
    543   * It is then the user's responsibility
    544   * to verify how much audio was encoded by checking the ToC byte of the encoded
    545   * packet. The part of the audio that was not encoded needs to be resent to the
    546   * encoder for the next call. Do not use this option unless you <b>really</b>
    547   * know what you are doing.
    548   * @see OPUS_GET_EXPERT_VARIABLE_DURATION
    549   * @param[in] x <tt>opus_int32</tt>: Allowed values:
    550   * <dl>
    551   * <dt>OPUS_FRAMESIZE_ARG</dt><dd>Select frame size from the argument (default).</dd>
    552   * <dt>OPUS_FRAMESIZE_2_5_MS</dt><dd>Use 2.5 ms frames.</dd>
    553   * <dt>OPUS_FRAMESIZE_5_MS</dt><dd>Use 2.5 ms frames.</dd>
    554   * <dt>OPUS_FRAMESIZE_10_MS</dt><dd>Use 10 ms frames.</dd>
    555   * <dt>OPUS_FRAMESIZE_20_MS</dt><dd>Use 20 ms frames.</dd>
    556   * <dt>OPUS_FRAMESIZE_40_MS</dt><dd>Use 40 ms frames.</dd>
    557   * <dt>OPUS_FRAMESIZE_60_MS</dt><dd>Use 60 ms frames.</dd>
    558   * <dt>OPUS_FRAMESIZE_VARIABLE</dt><dd>Optimize the frame size dynamically.</dd>
    559   * </dl>
    560   * @hideinitializer */
    561 #define OPUS_SET_EXPERT_FRAME_DURATION(x) OPUS_SET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int(x)
    562 /** Gets the encoder's configured use of variable duration frames.
    563   * @see OPUS_SET_EXPERT_VARIABLE_DURATION
    564   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    565   * <dl>
    566   * <dt>OPUS_FRAMESIZE_ARG</dt><dd>Select frame size from the argument (default).</dd>
    567   * <dt>OPUS_FRAMESIZE_2_5_MS</dt><dd>Use 2.5 ms frames.</dd>
    568   * <dt>OPUS_FRAMESIZE_5_MS</dt><dd>Use 2.5 ms frames.</dd>
    569   * <dt>OPUS_FRAMESIZE_10_MS</dt><dd>Use 10 ms frames.</dd>
    570   * <dt>OPUS_FRAMESIZE_20_MS</dt><dd>Use 20 ms frames.</dd>
    571   * <dt>OPUS_FRAMESIZE_40_MS</dt><dd>Use 40 ms frames.</dd>
    572   * <dt>OPUS_FRAMESIZE_60_MS</dt><dd>Use 60 ms frames.</dd>
    573   * <dt>OPUS_FRAMESIZE_VARIABLE</dt><dd>Optimize the frame size dynamically.</dd>
    574   * </dl>
    575   * @hideinitializer */
    576 #define OPUS_GET_EXPERT_FRAME_DURATION(x) OPUS_GET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int_ptr(x)
    577 
    578 /**@}*/
    579 
    580 /** @defgroup opus_genericctls Generic CTLs
    581   *
    582   * These macros are used with the \c opus_decoder_ctl and
    583   * \c opus_encoder_ctl calls to generate a particular
    584   * request.
    585   *
    586   * When called on an \c OpusDecoder they apply to that
    587   * particular decoder instance. When called on an
    588   * \c OpusEncoder they apply to the corresponding setting
    589   * on that encoder instance, if present.
    590   *
    591   * Some usage examples:
    592   *
    593   * @code
    594   * int ret;
    595   * opus_int32 pitch;
    596   * ret = opus_decoder_ctl(dec_ctx, OPUS_GET_PITCH(&pitch));
    597   * if (ret == OPUS_OK) return ret;
    598   *
    599   * opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE);
    600   * opus_decoder_ctl(dec_ctx, OPUS_RESET_STATE);
    601   *
    602   * opus_int32 enc_bw, dec_bw;
    603   * opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&enc_bw));
    604   * opus_decoder_ctl(dec_ctx, OPUS_GET_BANDWIDTH(&dec_bw));
    605   * if (enc_bw != dec_bw) {
    606   *   printf("packet bandwidth mismatch!\n");
    607   * }
    608   * @endcode
    609   *
    610   * @see opus_encoder, opus_decoder_ctl, opus_encoder_ctl, opus_decoderctls, opus_encoderctls
    611   * @{
    612   */
    613 
    614 /** Resets the codec state to be equivalent to a freshly initialized state.
    615   * This should be called when switching streams in order to prevent
    616   * the back to back decoding from giving different results from
    617   * one at a time decoding.
    618   * @hideinitializer */
    619 #define OPUS_RESET_STATE 4028
    620 
    621 /** Gets the final state of the codec's entropy coder.
    622   * This is used for testing purposes,
    623   * The encoder and decoder state should be identical after coding a payload
    624   * (assuming no data corruption or software bugs)
    625   *
    626   * @param[out] x <tt>opus_uint32 *</tt>: Entropy coder state
    627   *
    628   * @hideinitializer */
    629 #define OPUS_GET_FINAL_RANGE(x) OPUS_GET_FINAL_RANGE_REQUEST, __opus_check_uint_ptr(x)
    630 
    631 /** Gets the pitch of the last decoded frame, if available.
    632   * This can be used for any post-processing algorithm requiring the use of pitch,
    633   * e.g. time stretching/shortening. If the last frame was not voiced, or if the
    634   * pitch was not coded in the frame, then zero is returned.
    635   *
    636   * This CTL is only implemented for decoder instances.
    637   *
    638   * @param[out] x <tt>opus_int32 *</tt>: pitch period at 48 kHz (or 0 if not available)
    639   *
    640   * @hideinitializer */
    641 #define OPUS_GET_PITCH(x) OPUS_GET_PITCH_REQUEST, __opus_check_int_ptr(x)
    642 
    643 /** Gets the encoder's configured bandpass or the decoder's last bandpass.
    644   * @see OPUS_SET_BANDWIDTH
    645   * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
    646   * <dl>
    647   * <dt>#OPUS_AUTO</dt>                    <dd>(default)</dd>
    648   * <dt>#OPUS_BANDWIDTH_NARROWBAND</dt>    <dd>4 kHz passband</dd>
    649   * <dt>#OPUS_BANDWIDTH_MEDIUMBAND</dt>    <dd>6 kHz passband</dd>
    650   * <dt>#OPUS_BANDWIDTH_WIDEBAND</dt>      <dd>8 kHz passband</dd>
    651   * <dt>#OPUS_BANDWIDTH_SUPERWIDEBAND</dt><dd>12 kHz passband</dd>
    652   * <dt>#OPUS_BANDWIDTH_FULLBAND</dt>     <dd>20 kHz passband</dd>
    653   * </dl>
    654   * @hideinitializer */
    655 #define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __opus_check_int_ptr(x)
    656 
    657 /**@}*/
    658 
    659 /** @defgroup opus_decoderctls Decoder related CTLs
    660   * @see opus_genericctls, opus_encoderctls, opus_decoder
    661   * @{
    662   */
    663 
    664 /** Configures decoder gain adjustment.
    665   * Scales the decoded output by a factor specified in Q8 dB units.
    666   * This has a maximum range of -32768 to 32767 inclusive, and returns
    667   * OPUS_BAD_ARG otherwise. The default is zero indicating no adjustment.
    668   * This setting survives decoder reset.
    669   *
    670   * gain = pow(10, x/(20.0*256))
    671   *
    672   * @param[in] x <tt>opus_int32</tt>:   Amount to scale PCM signal by in Q8 dB units.
    673   * @hideinitializer */
    674 #define OPUS_SET_GAIN(x) OPUS_SET_GAIN_REQUEST, __opus_check_int(x)
    675 /** Gets the decoder's configured gain adjustment. @see OPUS_SET_GAIN
    676   *
    677   * @param[out] x <tt>opus_int32 *</tt>: Amount to scale PCM signal by in Q8 dB units.
    678   * @hideinitializer */
    679 #define OPUS_GET_GAIN(x) OPUS_GET_GAIN_REQUEST, __opus_check_int_ptr(x)
    680 
    681 /**@}*/
    682 
    683 /** @defgroup opus_libinfo Opus library information functions
    684   * @{
    685   */
    686 
    687 /** Converts an opus error code into a human readable string.
    688   *
    689   * @param[in] error <tt>int</tt>: Error number
    690   * @returns Error string
    691   */
    692 OPUS_EXPORT const char *opus_strerror(int error);
    693 
    694 /** Gets the libopus version string.
    695   *
    696   * @returns Version string
    697   */
    698 OPUS_EXPORT const char *opus_get_version_string(void);
    699 /**@}*/
    700 
    701 #ifdef __cplusplus
    702 }
    703 #endif
    704 
    705 #endif /* OPUS_DEFINES_H */
    706