opus_defines.h 27 KB

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