Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

331 lines
10 KiB

  1. /* Copyright (C) 2002 Jean-Marc Valin*/
  2. /**
  3. @file speex.h
  4. @brief Describes the different modes of the codec
  5. */
  6. /*
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions
  9. are met:
  10. - Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. - Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15. - Neither the name of the Xiph.org Foundation nor the names of its
  16. contributors may be used to endorse or promote products derived from
  17. this software without specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  22. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef SPEEX_H
  31. #define SPEEX_H
  32. #include "speex_bits.h"
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Values allowed for *ctl() requests */
  37. /** Set enhancement on/off (decoder only) */
  38. #define SPEEX_SET_ENH 0
  39. /** Get enhancement state (decoder only) */
  40. #define SPEEX_GET_ENH 1
  41. /*Would be SPEEX_SET_FRAME_SIZE, but it's (currently) invalid*/
  42. /** Obtain frame size used by encoder/decoder */
  43. #define SPEEX_GET_FRAME_SIZE 3
  44. /** Set quality value */
  45. #define SPEEX_SET_QUALITY 4
  46. /** Get current quality setting */
  47. #define SPEEX_GET_QUALITY 5
  48. /** Set sub-mode to use */
  49. #define SPEEX_SET_MODE 6
  50. /** Get current sub-mode in use */
  51. #define SPEEX_GET_MODE 7
  52. /** Set low-band sub-mode to use (wideband only)*/
  53. #define SPEEX_SET_LOW_MODE 8
  54. /** Get current low-band mode in use (wideband only)*/
  55. #define SPEEX_GET_LOW_MODE 9
  56. /** Set high-band sub-mode to use (wideband only)*/
  57. #define SPEEX_SET_HIGH_MODE 10
  58. /** Get current high-band mode in use (wideband only)*/
  59. #define SPEEX_GET_HIGH_MODE 11
  60. /** Set VBR on (1) or off (0) */
  61. #define SPEEX_SET_VBR 12
  62. /** Get VBR status (1 for on, 0 for off) */
  63. #define SPEEX_GET_VBR 13
  64. /** Set quality value for VBR encoding (0-10) */
  65. #define SPEEX_SET_VBR_QUALITY 14
  66. /** Get current quality value for VBR encoding (0-10) */
  67. #define SPEEX_GET_VBR_QUALITY 15
  68. /** Set complexity of the encoder (0-10) */
  69. #define SPEEX_SET_COMPLEXITY 16
  70. /** Get current complexity of the encoder (0-10) */
  71. #define SPEEX_GET_COMPLEXITY 17
  72. /** Set bit-rate used by the encoder (or lower) */
  73. #define SPEEX_SET_BITRATE 18
  74. /** Get current bit-rate used by the encoder or decoder */
  75. #define SPEEX_GET_BITRATE 19
  76. /**Define a handler function for in-band Speex request*/
  77. #define SPEEX_SET_HANDLER 20
  78. /**Define a handler function for in-band user-defined request*/
  79. #define SPEEX_SET_USER_HANDLER 22
  80. /** Set sampling rate used in bit-rate computation */
  81. #define SPEEX_SET_SAMPLING_RATE 24
  82. /** Get sampling rate used in bit-rate computation */
  83. #define SPEEX_GET_SAMPLING_RATE 25
  84. /** Reset the encoder/decoder memories to zero*/
  85. #define SPEEX_RESET_STATE 26
  86. /** Get VBR info (mostly used internally) */
  87. #define SPEEX_GET_RELATIVE_QUALITY 29
  88. /** Set VAD status (1 for on, 0 for off) */
  89. #define SPEEX_SET_VAD 30
  90. /** Get VAD status (1 for on, 0 for off) */
  91. #define SPEEX_GET_VAD 31
  92. /** Set Average Bit-Rate (ABR) to n bits per seconds */
  93. #define SPEEX_SET_ABR 32
  94. /** Get Average Bit-Rate (ABR) setting (in bps) */
  95. #define SPEEX_GET_ABR 33
  96. /** Set DTX status (1 for on, 0 for off) */
  97. #define SPEEX_SET_DTX 34
  98. /** Get DTX status (1 for on, 0 for off) */
  99. #define SPEEX_GET_DTX 35
  100. /* Used internally, not to be used in applications */
  101. /** Used internally*/
  102. #define SPEEX_GET_PI_GAIN 100
  103. /** Used internally*/
  104. #define SPEEX_GET_EXC 101
  105. /** Used internally*/
  106. #define SPEEX_GET_INNOV 102
  107. /** Used internally*/
  108. #define SPEEX_GET_DTX_STATUS 103
  109. /* Preserving compatibility:*/
  110. /** Equivalent to SPEEX_SET_ENH */
  111. #define SPEEX_SET_PF 0
  112. /** Equivalent to SPEEX_GET_ENH */
  113. #define SPEEX_GET_PF 1
  114. /* Values allowed for mode queries */
  115. /** Query the frame size of a mode */
  116. #define SPEEX_MODE_FRAME_SIZE 0
  117. /** Query the size of an encoded frame for a particular sub-mode */
  118. #define SPEEX_SUBMODE_BITS_PER_FRAME 1
  119. /** Number of defined modes in Speex */
  120. #define SPEEX_NB_MODES 3
  121. struct SpeexMode;
  122. /* Prototypes for mode function pointers */
  123. /** Encoder state initialization function */
  124. typedef void *(*encoder_init_func)(struct SpeexMode *mode);
  125. /** Encoder state destruction function */
  126. typedef void (*encoder_destroy_func)(void *st);
  127. /** Main encoding function */
  128. typedef int (*encode_func)(void *state, float *in, SpeexBits *bits);
  129. /** Function for controlling the encoder options */
  130. typedef int (*encoder_ctl_func)(void *state, int request, void *ptr);
  131. /** Decoder state initialization function */
  132. typedef void *(*decoder_init_func)(struct SpeexMode *mode);
  133. /** Decoder state destruction function */
  134. typedef void (*decoder_destroy_func)(void *st);
  135. /** Main decoding function */
  136. typedef int (*decode_func)(void *state, SpeexBits *bits, float *out);
  137. /** Function for controlling the decoder options */
  138. typedef int (*decoder_ctl_func)(void *state, int request, void *ptr);
  139. /** Query function for a mode */
  140. typedef int (*mode_query_func)(void *mode, int request, void *ptr);
  141. /** Struct defining a Speex mode */
  142. typedef struct SpeexMode {
  143. /** Pointer to the low-level mode data */
  144. void *mode;
  145. /** Pointer to the mode query function */
  146. mode_query_func query;
  147. /** The name of the mode (you should not rely on this to identify the mode)*/
  148. char *modeName;
  149. /**ID of the mode*/
  150. int modeID;
  151. /**Version number of the bitstream (incremented every time we break
  152. bitstream compatibility*/
  153. int bitstream_version;
  154. /** Pointer to encoder initialization function */
  155. encoder_init_func enc_init;
  156. /** Pointer to encoder destruction function */
  157. encoder_destroy_func enc_destroy;
  158. /** Pointer to frame encoding function */
  159. encode_func enc;
  160. /** Pointer to decoder initialization function */
  161. decoder_init_func dec_init;
  162. /** Pointer to decoder destruction function */
  163. decoder_destroy_func dec_destroy;
  164. /** Pointer to frame decoding function */
  165. decode_func dec;
  166. /** ioctl-like requests for encoder */
  167. encoder_ctl_func enc_ctl;
  168. /** ioctl-like requests for decoder */
  169. decoder_ctl_func dec_ctl;
  170. } SpeexMode;
  171. /**
  172. * Returns a handle to a newly created Speex encoder state structure. For now,
  173. * the "mode" argument can be &nb_mode or &wb_mode . In the future, more modes
  174. * may be added. Note that for now if you have more than one channels to
  175. * encode, you need one state per channel.
  176. *
  177. * @param mode The mode to use (either speex_nb_mode or speex_wb.mode)
  178. * @return A newly created encoder
  179. */
  180. void *speex_encoder_init(SpeexMode *mode);
  181. /** Frees all resources associated to an existing Speex encoder state.
  182. * @param state Encoder state to be destroyed */
  183. void speex_encoder_destroy(void *state);
  184. /** Uses an existing encoder state to encode one frame of speech pointed to by
  185. "in". The encoded bit-stream is saved in "bits".
  186. @param state Encoder state
  187. @param in Frame that will be encoded with a +-2^16 range
  188. @param bits Bit-stream where the data will be written
  189. */
  190. int speex_encode(void *state, float *in, SpeexBits *bits);
  191. /** Used like the ioctl function to control the encoder parameters
  192. *
  193. * @param state Encoder state
  194. * @param request ioctl-type request (one of the SPEEX_* macros)
  195. * @param ptr Data exchanged to-from function
  196. * @return 0 if frame needs not be transmitted (DTX only), 1 otherwise
  197. */
  198. int speex_encoder_ctl(void *state, int request, void *ptr);
  199. /** Returns a handle to a newly created decoder state structure. For now,
  200. * the mode argument can be &nb_mode or &wb_mode . In the future, more modes
  201. * may be added. Note that for now if you have more than one channels to
  202. * decode, you need one state per channel.
  203. *
  204. * @param mode Speex mode (one of speex_nb_mode or speex_wb_mode)
  205. * @return A newly created decoder state
  206. */
  207. void *speex_decoder_init(SpeexMode *mode);
  208. /** Frees all resources associated to an existing decoder state.
  209. *
  210. * @param state State to be destroyed
  211. */
  212. void speex_decoder_destroy(void *state);
  213. /** Uses an existing decoder state to decode one frame of speech from
  214. * bit-stream bits. The output speech is saved written to out.
  215. *
  216. * @param state Decoder state
  217. * @param bits Bit-stream from which to decode the frame (NULL if the packet was lost)
  218. * @param out Where to write the decoded frame
  219. * @return return status (0 for no error, -1 for end of stream, -2 other)
  220. */
  221. int speex_decode(void *state, SpeexBits *bits, float *out);
  222. /** Used like the ioctl function to control the encoder parameters
  223. *
  224. * @param state Decoder state
  225. * @param request ioctl-type request (one of the SPEEX_* macros)
  226. * @param ptr Data exchanged to-from function
  227. * @return 0 for no error, 1 if a terminator is reached, 2 for another error
  228. */
  229. int speex_decoder_ctl(void *state, int request, void *ptr);
  230. /** Query function for mode information
  231. *
  232. * @param mode Speex mode
  233. * @param request ioctl-type request (one of the SPEEX_* macros)
  234. * @param ptr Data exchanged to-from function
  235. */
  236. int speex_mode_query(SpeexMode *mode, int request, void *ptr);
  237. /** Default narrowband mode */
  238. extern SpeexMode speex_nb_mode;
  239. /** Default wideband mode */
  240. extern SpeexMode speex_wb_mode;
  241. /** Default "ultra-wideband" mode */
  242. extern SpeexMode speex_uwb_mode;
  243. /** List of all modes available */
  244. extern SpeexMode *speex_mode_list[SPEEX_NB_MODES];
  245. #ifdef __cplusplus
  246. }
  247. #endif
  248. #endif