opus_defines.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 FOUNDATION OR
  16. 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 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. #if defined(__GNUC__) && defined(OPUS_BUILD)
  57. # define OPUS_EXPORT __attribute__ ((visibility ("default")))
  58. #elif defined(WIN32)
  59. # ifdef OPUS_BUILD
  60. # define OPUS_EXPORT __declspec(dllexport)
  61. # else
  62. # define OPUS_EXPORT __declspec(dllimport)
  63. # endif
  64. #else
  65. # define OPUS_EXPORT
  66. #endif
  67. /** These are the actual Encoder CTL ID numbers.
  68. * They should not be used directly by applications. */
  69. #define OPUS_SET_COMPLEXITY_REQUEST 4010
  70. #define OPUS_GET_COMPLEXITY_REQUEST 4011
  71. #define OPUS_SET_BITRATE_REQUEST 4002
  72. #define OPUS_GET_BITRATE_REQUEST 4003
  73. #define OPUS_SET_VBR_REQUEST 4006
  74. #define OPUS_GET_VBR_REQUEST 4007
  75. #define OPUS_SET_VBR_CONSTRAINT_REQUEST 4020
  76. #define OPUS_GET_VBR_CONSTRAINT_REQUEST 4021
  77. #define OPUS_SET_FORCE_CHANNELS_REQUEST 4022
  78. #define OPUS_GET_FORCE_CHANNELS_REQUEST 4023
  79. #define OPUS_SET_BANDWIDTH_REQUEST 4008
  80. #define OPUS_GET_BANDWIDTH_REQUEST 4009
  81. #define OPUS_SET_SIGNAL_REQUEST 4024
  82. #define OPUS_GET_SIGNAL_REQUEST 4025
  83. #define OPUS_SET_VOICE_RATIO_REQUEST 4018
  84. #define OPUS_GET_VOICE_RATIO_REQUEST 4019
  85. #define OPUS_SET_APPLICATION_REQUEST 4000
  86. #define OPUS_GET_APPLICATION_REQUEST 4001
  87. #define OPUS_GET_LOOKAHEAD_REQUEST 4027
  88. #define OPUS_SET_INBAND_FEC_REQUEST 4012
  89. #define OPUS_GET_INBAND_FEC_REQUEST 4013
  90. #define OPUS_SET_PACKET_LOSS_PERC_REQUEST 4014
  91. #define OPUS_GET_PACKET_LOSS_PERC_REQUEST 4015
  92. #define OPUS_SET_DTX_REQUEST 4016
  93. #define OPUS_GET_DTX_REQUEST 4017
  94. #define OPUS_GET_FINAL_RANGE_REQUEST 4031
  95. #define OPUS_GET_PITCH_REQUEST 4033
  96. /* Macros to trigger compilation errors when the wrong types are provided to a CTL */
  97. #define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x))
  98. #define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr)))
  99. #define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr)))
  100. /** @endcond */
  101. /** @defgroup encoderctls Encoder related CTLs
  102. * @see genericctls,opusencoder
  103. * @{
  104. */
  105. /** @cond DOXYGEN_EXCLUDE */
  106. /* Values for the various encoder CTLs */
  107. #define OPUS_AUTO -1000 /**<Auto bitrate @hideinitializer*/
  108. #define OPUS_BITRATE_MAX -1 /**<Maximum bitrate @hideinitializer*/
  109. #define OPUS_APPLICATION_VOIP 2048
  110. #define OPUS_APPLICATION_AUDIO 2049
  111. #define OPUS_APPLICATION_RESTRICTED_LOWDELAY 2051
  112. #define OPUS_SIGNAL_VOICE 3001
  113. #define OPUS_SIGNAL_MUSIC 3002
  114. #define OPUS_BANDWIDTH_NARROWBAND 1101 /**< 4kHz bandpass @hideinitializer*/
  115. #define OPUS_BANDWIDTH_MEDIUMBAND 1102 /**< 6kHz bandpass @hideinitializer*/
  116. #define OPUS_BANDWIDTH_WIDEBAND 1103 /**< 8kHz bandpass @hideinitializer*/
  117. #define OPUS_BANDWIDTH_SUPERWIDEBAND 1104 /**<12kHz bandpass @hideinitializer*/
  118. #define OPUS_BANDWIDTH_FULLBAND 1105 /**<20kHz bandpass @hideinitializer*/
  119. /** @endcond */
  120. /** Configures the encoder's computational complexity.
  121. * The supported range is 0-10 inclusive with 10 representing the highest complexity.
  122. * The default value is 10.
  123. * @param[in] x <tt>int</tt>: 0-10, inclusive
  124. * @hideinitializer */
  125. #define OPUS_SET_COMPLEXITY(x) OPUS_SET_COMPLEXITY_REQUEST, __opus_check_int(x)
  126. /** Gets the encoder's complexity configuration, @see OPUS_SET_COMPLEXITY
  127. * @param[out] x <tt>int*</tt>: 0-10, inclusive
  128. * @hideinitializer */
  129. #define OPUS_GET_COMPLEXITY(x) OPUS_GET_COMPLEXITY_REQUEST, __opus_check_int_ptr(x)
  130. /** Configures the bitrate in the encoder.
  131. * Rates from 500 to 512000 bits per second are meaningful as well as the
  132. * special values OPUS_BITRATE_AUTO and OPUS_BITRATE_MAX.
  133. * The value OPUS_BITRATE_MAX can be used to cause the codec to use as much rate
  134. * as it can, which is useful for controlling the rate by adjusting the output
  135. * buffer size.
  136. * @param[in] x <tt>opus_int32</tt>: bitrate in bits per second.
  137. * @hideinitializer */
  138. #define OPUS_SET_BITRATE(x) OPUS_SET_BITRATE_REQUEST, __opus_check_int(x)
  139. /** Gets the encoder's bitrate configuration, @see OPUS_SET_BITRATE
  140. * @param[out] x <tt>opus_int32*</tt>: bitrate in bits per second.
  141. * @hideinitializer */
  142. #define OPUS_GET_BITRATE(x) OPUS_GET_BITRATE_REQUEST, __opus_check_int_ptr(x)
  143. /** Configures VBR in the encoder.
  144. * The following values are currently supported:
  145. * - 0 CBR
  146. * - 1 VBR (default)
  147. * The configured bitrate may not be met exactly because frames must
  148. * be an integer number of bytes in length.
  149. * @warning Only the MDCT mode of Opus can provide hard CBR behavior.
  150. * @param[in] x <tt>int</tt>: 0; 1 (default)
  151. * @hideinitializer */
  152. #define OPUS_SET_VBR(x) OPUS_SET_VBR_REQUEST, __opus_check_int(x)
  153. /** Gets the encoder's VBR configuration, @see OPUS_SET_VBR
  154. * @param[out] x <tt>int*</tt>: 0; 1
  155. * @hideinitializer */
  156. #define OPUS_GET_VBR(x) OPUS_GET_VBR_REQUEST, __opus_check_int_ptr(x)
  157. /** Configures constrained VBR in the encoder.
  158. * The following values are currently supported:
  159. * - 0 Unconstrained VBR (default)
  160. * - 1 Maximum one frame buffering delay assuming transport with a serialization speed of the nominal bitrate
  161. * This setting is irrelevant when the encoder is in CBR mode.
  162. * @warning Only the MDCT mode of Opus currently heeds the constraint.
  163. * Speech mode ignores it completely, hybrid mode may fail to obey it
  164. * if the LPC layer uses more bitrate than the constraint would have
  165. * permitted.
  166. * @param[in] x <tt>int</tt>: 0 (default); 1
  167. * @hideinitializer */
  168. #define OPUS_SET_VBR_CONSTRAINT(x) OPUS_SET_VBR_CONSTRAINT_REQUEST, __opus_check_int(x)
  169. /** Gets the encoder's constrained VBR configuration @see OPUS_SET_VBR_CONSTRAINT
  170. * @param[out] x <tt>int*</tt>: 0; 1
  171. * @hideinitializer */
  172. #define OPUS_GET_VBR_CONSTRAINT(x) OPUS_GET_VBR_CONSTRAINT_REQUEST, __opus_check_int_ptr(x)
  173. /** Configures mono/stereo forcing in the encoder.
  174. * This is useful when the caller knows that the input signal is currently a mono
  175. * source embedded in a stereo stream.
  176. * @param[in] x <tt>int</tt>: OPUS_AUTO (default); 1 (forced mono); 2 (forced stereo)
  177. * @hideinitializer */
  178. #define OPUS_SET_FORCE_CHANNELS(x) OPUS_SET_FORCE_CHANNELS_REQUEST, __opus_check_int(x)
  179. /** Gets the encoder's forced channel configuration, @see OPUS_SET_FORCE_CHANNELS
  180. * @param[out] x <tt>int*</tt>: OPUS_AUTO; 0; 1
  181. * @hideinitializer */
  182. #define OPUS_GET_FORCE_CHANNELS(x) OPUS_GET_FORCE_CHANNELS_REQUEST, __opus_check_int_ptr(x)
  183. /** Configures the encoder's bandpass, @see OPUS_GET_BANDWIDTH
  184. * The supported values are:
  185. * - OPUS_BANDWIDTH_AUTO (default)
  186. * - OPUS_BANDWIDTH_NARROWBAND 4kHz passband
  187. * - OPUS_BANDWIDTH_MEDIUMBAND 6kHz passband
  188. * - OPUS_BANDWIDTH_WIDEBAND 8kHz passband
  189. * - OPUS_BANDWIDTH_SUPERWIDEBAND 12kHz passband
  190. * - OPUS_BANDWIDTH_FULLBAND 20kHz passband
  191. * @param[in] x <tt>int</tt>: Bandwidth value
  192. * @hideinitializer */
  193. #define OPUS_SET_BANDWIDTH(x) OPUS_SET_BANDWIDTH_REQUEST, __opus_check_int(x)
  194. /** Configures the type of signal being encoded.
  195. * This is a hint which helps the encoder's mode selection.
  196. * The supported values are:
  197. * - OPUS_SIGNAL_AUTO (default)
  198. * - OPUS_SIGNAL_VOICE
  199. * - OPUS_SIGNAL_MUSIC
  200. * @param[in] x <tt>int</tt>: Signal type
  201. * @hideinitializer */
  202. #define OPUS_SET_SIGNAL(x) OPUS_SET_SIGNAL_REQUEST, __opus_check_int(x)
  203. /** Gets the encoder's configured signal type, @see OPUS_SET_SIGNAL
  204. *
  205. * @param[out] x <tt>int*</tt>: Signal type
  206. * @hideinitializer */
  207. #define OPUS_GET_SIGNAL(x) OPUS_GET_SIGNAL_REQUEST, __opus_check_int_ptr(x)
  208. /** Configures the encoder's expected percentage of voice
  209. * opposed to music or other signals.
  210. *
  211. * @note This interface is currently more aspiration than actuality. It's
  212. * ultimately expected to bias an automatic signal classifier, but it currently
  213. * just shifts the static bitrate to mode mapping around a little bit.
  214. *
  215. * @param[in] x <tt>int</tt>: Voice percentage in the range 0-100, inclusive.
  216. * @hideinitializer */
  217. #define OPUS_SET_VOICE_RATIO(x) OPUS_SET_VOICE_RATIO_REQUEST, __opus_check_int(x)
  218. /** Gets the encoder's configured voice ratio value, @see OPUS_SET_VOICE_RATIO
  219. *
  220. * @param[out] x <tt>int*</tt>: Voice percentage in the range 0-100, inclusive.
  221. * @hideinitializer */
  222. #define OPUS_GET_VOICE_RATIO(x) OPUS_GET_VOICE_RATIO_REQUEST, __opus_check_int_ptr(x)
  223. /** Configures the encoder's intended application.
  224. * The initial value is a mandatory argument to the encoder_create function.
  225. * The supported values are:
  226. * - OPUS_APPLICATION_VOIP Process signal for improved speech intelligibility
  227. * - OPUS_APPLICATION_AUDIO Favor faithfulness to the original input
  228. * @param[in] x <tt>int</tt>: Application value
  229. * @hideinitializer */
  230. #define OPUS_SET_APPLICATION(x) OPUS_SET_APPLICATION_REQUEST, __opus_check_int(x)
  231. /** Gets the encoder's configured application, @see OPUS_SET_APPLICATION
  232. *
  233. * @param[out] x <tt>int*</tt>: Application value
  234. * @hideinitializer */
  235. #define OPUS_GET_APPLICATION(x) OPUS_GET_APPLICATION_REQUEST, __opus_check_int_ptr(x)
  236. /** Configures low-delay mode that disables the speech-optimized mode in exchange for slightly reduced delay.
  237. * This is useful when the caller knows that the speech-optimized modes will not be needed (use with caution).
  238. * The setting can only be changed right after initialization or after a reset and changes the lookahead.
  239. * @param[in] x <tt>int</tt>: 0 (default); 1 (lowdelay)
  240. * @hideinitializer */
  241. #define OPUS_SET_RESTRICTED_LOWDELAY(x) OPUS_SET_RESTRICTED_LOWDELAY_REQUEST, __opus_check_int(x)
  242. /** Gets the encoder's forced channel configuration, @see OPUS_SET_RESTRICTED_LOWDELAY
  243. * @param[out] x <tt>int*</tt>: 0; 1
  244. * @hideinitializer */
  245. #define OPUS_GET_RESTRICTED_LOWDELAY(x) OPUS_GET_RESTRICTED_LOWDELAY_REQUEST, __opus_check_int_ptr(x)
  246. /** Gets the total samples of delay added by the entire codec.
  247. * This can be queried by the encoder and then the provided number of samples can be
  248. * skipped on from the start of the decoder's output to provide time aligned input
  249. * and output. From the perspective of a decoding application the real data begins this many
  250. * samples late.
  251. *
  252. * The decoder contribution to this delay is identical for all decoders, but the
  253. * encoder portion of the delay may vary from implementation to implementation,
  254. * version to version, or even depend on the encoder's initial configuration.
  255. * Applications needing delay compensation should call this CTL rather than
  256. * hard-coding a value.
  257. * @param[out] x <tt>int*</tt>: Number of lookahead samples
  258. * @hideinitializer */
  259. #define OPUS_GET_LOOKAHEAD(x) OPUS_GET_LOOKAHEAD_REQUEST, __opus_check_int_ptr(x)
  260. /** Configures the encoder's use of inband forward error correction.
  261. * @note This is only applicable to the LPC layer
  262. *
  263. * @param[in] x <tt>int</tt>: FEC flag, 0 (disabled) is default
  264. * @hideinitializer */
  265. #define OPUS_SET_INBAND_FEC(x) OPUS_SET_INBAND_FEC_REQUEST, __opus_check_int(x)
  266. /** Gets encoder's configured use of inband forward error correction, @see OPUS_SET_INBAND_FEC
  267. *
  268. * @param[out] x <tt>int*</tt>: FEC flag
  269. * @hideinitializer */
  270. #define OPUS_GET_INBAND_FEC(x) OPUS_GET_INBAND_FEC_REQUEST, __opus_check_int_ptr(x)
  271. /** Configures the encoder's expected packet loss percentage.
  272. * Higher values with trigger progressively more loss resistant behavior in the encoder
  273. * at the expense of quality at a given bitrate in the lossless case, but greater quality
  274. * under loss.
  275. *
  276. * @param[in] x <tt>int</tt>: Loss percentage in the range 0-100, inclusive.
  277. * @hideinitializer */
  278. #define OPUS_SET_PACKET_LOSS_PERC(x) OPUS_SET_PACKET_LOSS_PERC_REQUEST, __opus_check_int(x)
  279. /** Gets the encoder's configured packet loss percentage, @see OPUS_SET_PACKET_LOSS_PERC
  280. *
  281. * @param[out] x <tt>int*</tt>: Loss percentage in the range 0-100, inclusive.
  282. * @hideinitializer */
  283. #define OPUS_GET_PACKET_LOSS_PERC(x) OPUS_GET_PACKET_LOSS_PERC_REQUEST, __opus_check_int_ptr(x)
  284. /** Configures the encoder's use of discontinuous transmission.
  285. * @note This is only applicable to the LPC layer
  286. *
  287. * @param[in] x <tt>int</tt>: DTX flag, 0 (disabled) is default
  288. * @hideinitializer */
  289. #define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __opus_check_int(x)
  290. /** Gets encoder's configured use of discontinuous transmission, @see OPUS_SET_DTX
  291. *
  292. * @param[out] x <tt>int*</tt>: DTX flag
  293. * @hideinitializer */
  294. #define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __opus_check_int_ptr(x)
  295. /**@}*/
  296. /** @defgroup genericctls Generic CTLs
  297. * @see opus_encoder_ctl,opusencoder,opusdecoder
  298. * @{
  299. */
  300. /** Resets the codec state to be equivalent to a freshly initialized state.
  301. * This should be called when switching streams in order to prevent
  302. * the back to back decoding from giving different results from
  303. * one at a time decoding.
  304. * @hideinitializer */
  305. #define OPUS_RESET_STATE 4028
  306. /** Gets the final state of the codec's entropy coder.
  307. * This is used for testing purposes,
  308. * The encoder and decoder state should be identical after coding a payload
  309. * (assuming no data corruption or software bugs)
  310. *
  311. * @param[out] x <tt>opus_uint32*</tt>: Entropy coder state
  312. *
  313. * @hideinitializer */
  314. #define OPUS_GET_FINAL_RANGE(x) OPUS_GET_FINAL_RANGE_REQUEST, __opus_check_uint_ptr(x)
  315. /** Gets the pitch of the last decoded frame, if available.
  316. * This can be used for any post-processing algorithm requiring the use of pitch,
  317. * e.g. time stretching/shortening. If the last frame was not voiced, or if the
  318. * pitch was not coded in the frame, then zero is returned.
  319. *
  320. * @param[out] x <tt>opus_int32*</tt>: pitch period at 48 kHz (or 0 if not available)
  321. *
  322. * @hideinitializer */
  323. #define OPUS_GET_PITCH(x) OPUS_GET_PITCH_REQUEST, __opus_check_int_ptr(x)
  324. /** Gets the encoder's configured bandpass or the decoder's last bandpass, @see OPUS_SET_BANDWIDTH
  325. * @param[out] x <tt>int*</tt>: Bandwidth value
  326. * @hideinitializer */
  327. #define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __opus_check_int_ptr(x)
  328. /**@}*/
  329. /** @defgroup libinfo Opus library information functions
  330. * @{
  331. */
  332. /** Converts an opus error code into a human readable string.
  333. *
  334. * @param[in] error <tt>int</tt>: Error number
  335. * @returns Error string
  336. */
  337. OPUS_EXPORT const char *opus_strerror(int error);
  338. /** Gets the libopus version string.
  339. *
  340. * @returns Version string
  341. */
  342. OPUS_EXPORT const char *opus_get_version_string(void);
  343. /**@}*/
  344. #ifdef __cplusplus
  345. }
  346. #endif
  347. #endif /* OPUS_DEFINES_H */