modes_wb.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /* Copyright (C) 2002-2007 Jean-Marc Valin
  2. File: modes.c
  3. Describes the wideband modes of the codec
  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. - Neither the name of the Xiph.org Foundation nor the names of its
  13. contributors may be used to endorse or promote products derived from
  14. this software without specific prior written permission.
  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 FOUNDATION OR
  19. 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. #ifdef HAVE_CONFIG_H
  28. #include "config.h"
  29. #endif
  30. #include "modes.h"
  31. #include "ltp.h"
  32. #include "quant_lsp.h"
  33. #include "cb_search.h"
  34. #include "sb_celp.h"
  35. #include "nb_celp.h"
  36. #include "vbr.h"
  37. #include "arch.h"
  38. #include <math.h>
  39. #include "os_support.h"
  40. #ifndef NULL
  41. #define NULL 0
  42. #endif
  43. EXPORT const SpeexMode * const speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode, &speex_uwb_mode};
  44. extern const signed char hexc_table[];
  45. extern const signed char hexc_10_32_table[];
  46. #ifndef DISABLE_WIDEBAND
  47. /* Split-VQ innovation for high-band wideband */
  48. static const split_cb_params split_cb_high = {
  49. 8, /*subvect_size*/
  50. 5, /*nb_subvect*/
  51. hexc_table, /*shape_cb*/
  52. 7, /*shape_bits*/
  53. 1,
  54. };
  55. /* Split-VQ innovation for high-band wideband */
  56. static const split_cb_params split_cb_high_lbr = {
  57. 10, /*subvect_size*/
  58. 4, /*nb_subvect*/
  59. hexc_10_32_table, /*shape_cb*/
  60. 5, /*shape_bits*/
  61. 0,
  62. };
  63. #endif
  64. static const SpeexSubmode wb_submode1 = {
  65. 0,
  66. 0,
  67. 1,
  68. 0,
  69. /*LSP quantization*/
  70. lsp_quant_high,
  71. lsp_unquant_high,
  72. /*Pitch quantization*/
  73. NULL,
  74. NULL,
  75. NULL,
  76. /*No innovation quantization*/
  77. NULL,
  78. NULL,
  79. NULL,
  80. -1,
  81. 36
  82. };
  83. static const SpeexSubmode wb_submode2 = {
  84. 0,
  85. 0,
  86. 1,
  87. 0,
  88. /*LSP quantization*/
  89. lsp_quant_high,
  90. lsp_unquant_high,
  91. /*Pitch quantization*/
  92. NULL,
  93. NULL,
  94. NULL,
  95. /*Innovation quantization*/
  96. split_cb_search_shape_sign,
  97. split_cb_shape_sign_unquant,
  98. #ifdef DISABLE_WIDEBAND
  99. NULL,
  100. #else
  101. &split_cb_high_lbr,
  102. #endif
  103. -1,
  104. 112
  105. };
  106. static const SpeexSubmode wb_submode3 = {
  107. 0,
  108. 0,
  109. 1,
  110. 0,
  111. /*LSP quantization*/
  112. lsp_quant_high,
  113. lsp_unquant_high,
  114. /*Pitch quantization*/
  115. NULL,
  116. NULL,
  117. NULL,
  118. /*Innovation quantization*/
  119. split_cb_search_shape_sign,
  120. split_cb_shape_sign_unquant,
  121. #ifdef DISABLE_WIDEBAND
  122. NULL,
  123. #else
  124. &split_cb_high,
  125. #endif
  126. -1,
  127. 192
  128. };
  129. static const SpeexSubmode wb_submode4 = {
  130. 0,
  131. 0,
  132. 1,
  133. 1,
  134. /*LSP quantization*/
  135. lsp_quant_high,
  136. lsp_unquant_high,
  137. /*Pitch quantization*/
  138. NULL,
  139. NULL,
  140. NULL,
  141. /*Innovation quantization*/
  142. split_cb_search_shape_sign,
  143. split_cb_shape_sign_unquant,
  144. #ifdef DISABLE_WIDEBAND
  145. NULL,
  146. #else
  147. &split_cb_high,
  148. #endif
  149. -1,
  150. 352
  151. };
  152. /* Split-band wideband CELP mode*/
  153. static const SpeexSBMode sb_wb_mode = {
  154. &speex_nb_mode,
  155. 160, /*frameSize*/
  156. 40, /*subframeSize*/
  157. 8, /*lpcSize*/
  158. #ifdef FIXED_POINT
  159. 29491, 19661, /* gamma1, gamma2 */
  160. #else
  161. 0.9, 0.6, /* gamma1, gamma2 */
  162. #endif
  163. QCONST16(.0002,15), /*lpc_floor*/
  164. QCONST16(0.9f,15),
  165. {NULL, &wb_submode1, &wb_submode2, &wb_submode3, &wb_submode4, NULL, NULL, NULL},
  166. 3,
  167. {1, 8, 2, 3, 4, 5, 5, 6, 6, 7, 7},
  168. {1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4},
  169. #ifndef DISABLE_VBR
  170. vbr_hb_thresh,
  171. #endif
  172. 5
  173. };
  174. EXPORT const SpeexMode speex_wb_mode = {
  175. &sb_wb_mode,
  176. wb_mode_query,
  177. "wideband (sub-band CELP)",
  178. 1,
  179. 4,
  180. &sb_encoder_init,
  181. &sb_encoder_destroy,
  182. &sb_encode,
  183. &sb_decoder_init,
  184. &sb_decoder_destroy,
  185. &sb_decode,
  186. &sb_encoder_ctl,
  187. &sb_decoder_ctl,
  188. };
  189. /* "Ultra-wideband" mode stuff */
  190. /* Split-band "ultra-wideband" (32 kbps) CELP mode*/
  191. static const SpeexSBMode sb_uwb_mode = {
  192. &speex_wb_mode,
  193. 320, /*frameSize*/
  194. 80, /*subframeSize*/
  195. 8, /*lpcSize*/
  196. #ifdef FIXED_POINT
  197. 29491, 19661, /* gamma1, gamma2 */
  198. #else
  199. 0.9, 0.6, /* gamma1, gamma2 */
  200. #endif
  201. QCONST16(.0002,15), /*lpc_floor*/
  202. QCONST16(0.7f,15),
  203. {NULL, &wb_submode1, NULL, NULL, NULL, NULL, NULL, NULL},
  204. 1,
  205. {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
  206. {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  207. #ifndef DISABLE_VBR
  208. vbr_uhb_thresh,
  209. #endif
  210. 2
  211. };
  212. int wb_mode_query(const void *mode, int request, void *ptr)
  213. {
  214. const SpeexSBMode *m = (const SpeexSBMode*)mode;
  215. switch (request)
  216. {
  217. case SPEEX_MODE_FRAME_SIZE:
  218. *((int*)ptr)=2*m->frameSize;
  219. break;
  220. case SPEEX_SUBMODE_BITS_PER_FRAME:
  221. if (*((int*)ptr)==0)
  222. *((int*)ptr) = SB_SUBMODE_BITS+1;
  223. else if (m->submodes[*((int*)ptr)]==NULL)
  224. *((int*)ptr) = -1;
  225. else
  226. *((int*)ptr) = m->submodes[*((int*)ptr)]->bits_per_frame;
  227. break;
  228. default:
  229. speex_warning_int("Unknown wb_mode_query request: ", request);
  230. return -1;
  231. }
  232. return 0;
  233. }
  234. EXPORT const SpeexMode speex_uwb_mode = {
  235. &sb_uwb_mode,
  236. wb_mode_query,
  237. "ultra-wideband (sub-band CELP)",
  238. 2,
  239. 4,
  240. &sb_encoder_init,
  241. &sb_encoder_destroy,
  242. &sb_encode,
  243. &sb_decoder_init,
  244. &sb_decoder_destroy,
  245. &sb_decode,
  246. &sb_encoder_ctl,
  247. &sb_decoder_ctl,
  248. };
  249. /* We have defined speex_lib_get_mode() as a macro in speex.h */
  250. #undef speex_lib_get_mode
  251. EXPORT const SpeexMode * speex_lib_get_mode (int mode)
  252. {
  253. if (mode < 0 || mode >= SPEEX_NB_MODES) return NULL;
  254. return speex_mode_list[mode];
  255. }