modes.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* Copyright (C) 2002-2006 Jean-Marc Valin */
  2. /**
  3. @file modes.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 MODES_H
  31. #define MODES_H
  32. #include "speex/speex.h"
  33. #include "arch.h"
  34. #define NB_SUBMODES 16
  35. #define NB_SUBMODE_BITS 4
  36. #define SB_SUBMODES 8
  37. #define SB_SUBMODE_BITS 3
  38. /* Used internally, NOT TO BE USED in applications */
  39. /** Used internally*/
  40. #define SPEEX_GET_PI_GAIN 100
  41. /** Used internally*/
  42. #define SPEEX_GET_EXC 101
  43. /** Used internally*/
  44. #define SPEEX_GET_INNOV 102
  45. /** Used internally*/
  46. #define SPEEX_GET_DTX_STATUS 103
  47. /** Used internally*/
  48. #define SPEEX_SET_INNOVATION_SAVE 104
  49. /** Used internally*/
  50. #define SPEEX_SET_WIDEBAND 105
  51. /** Used internally*/
  52. #define SPEEX_GET_STACK 106
  53. /** Quantizes LSPs */
  54. typedef void (*lsp_quant_func)(spx_lsp_t *, spx_lsp_t *, int, SpeexBits *);
  55. /** Decodes quantized LSPs */
  56. typedef void (*lsp_unquant_func)(spx_lsp_t *, int, SpeexBits *);
  57. /** Long-term predictor quantization */
  58. typedef int (*ltp_quant_func)(spx_word16_t *, spx_word16_t *, spx_coef_t *, spx_coef_t *,
  59. spx_coef_t *, spx_sig_t *, const void *, int, int, spx_word16_t,
  60. int, int, SpeexBits*, char *, spx_word16_t *, spx_word16_t *, int, int, int, spx_word32_t *);
  61. /** Long-term un-quantize */
  62. typedef void (*ltp_unquant_func)(spx_word16_t *, spx_word32_t *, int, int, spx_word16_t, const void *, int, int *,
  63. spx_word16_t *, SpeexBits*, char*, int, int, spx_word16_t, int);
  64. /** Innovation quantization function */
  65. typedef void (*innovation_quant_func)(spx_word16_t *, spx_coef_t *, spx_coef_t *, spx_coef_t *, const void *, int, int,
  66. spx_sig_t *, spx_word16_t *, SpeexBits *, char *, int, int);
  67. /** Innovation unquantization function */
  68. typedef void (*innovation_unquant_func)(spx_sig_t *, const void *, int, SpeexBits*, char *, spx_uint32_t *);
  69. /** Description of a Speex sub-mode (either narrowband or wideband) */
  70. typedef struct SpeexSubmode {
  71. int lbr_pitch; /**< Set to -1 for "normal" modes, otherwise encode pitch using a global pitch and allowing a +- lbr_pitch variation (for low not-rates)*/
  72. int forced_pitch_gain; /**< Use the same (forced) pitch gain for all sub-frames */
  73. int have_subframe_gain; /**< Number of bits to use as sub-frame innovation gain */
  74. int double_codebook; /**< Apply innovation quantization twice for higher quality (and higher bit-rate)*/
  75. /*LSP functions*/
  76. lsp_quant_func lsp_quant; /**< LSP quantization function */
  77. lsp_unquant_func lsp_unquant; /**< LSP unquantization function */
  78. /*Long-term predictor functions*/
  79. ltp_quant_func ltp_quant; /**< Long-term predictor (pitch) quantizer */
  80. ltp_unquant_func ltp_unquant; /**< Long-term predictor (pitch) un-quantizer */
  81. const void *ltp_params; /**< Pitch parameters (options) */
  82. /*Quantization of innovation*/
  83. innovation_quant_func innovation_quant; /**< Innovation quantization */
  84. innovation_unquant_func innovation_unquant; /**< Innovation un-quantization */
  85. const void *innovation_params; /**< Innovation quantization parameters*/
  86. spx_word16_t comb_gain; /**< Gain of enhancer comb filter */
  87. int bits_per_frame; /**< Number of bits per frame after encoding*/
  88. } SpeexSubmode;
  89. /** Struct defining the encoding/decoding mode*/
  90. typedef struct SpeexNBMode {
  91. int frameSize; /**< Size of frames used for encoding */
  92. int subframeSize; /**< Size of sub-frames used for encoding */
  93. int lpcSize; /**< Order of LPC filter */
  94. int pitchStart; /**< Smallest pitch value allowed */
  95. int pitchEnd; /**< Largest pitch value allowed */
  96. spx_word16_t gamma1; /**< Perceptual filter parameter #1 */
  97. spx_word16_t gamma2; /**< Perceptual filter parameter #2 */
  98. spx_word16_t lpc_floor; /**< Noise floor for LPC analysis */
  99. const SpeexSubmode *submodes[NB_SUBMODES]; /**< Sub-mode data for the mode */
  100. int defaultSubmode; /**< Default sub-mode to use when encoding */
  101. int quality_map[11]; /**< Mode corresponding to each quality setting */
  102. } SpeexNBMode;
  103. /** Struct defining the encoding/decoding mode for SB-CELP (wideband) */
  104. typedef struct SpeexSBMode {
  105. const SpeexMode *nb_mode; /**< Embedded narrowband mode */
  106. int frameSize; /**< Size of frames used for encoding */
  107. int subframeSize; /**< Size of sub-frames used for encoding */
  108. int lpcSize; /**< Order of LPC filter */
  109. spx_word16_t gamma1; /**< Perceptual filter parameter #1 */
  110. spx_word16_t gamma2; /**< Perceptual filter parameter #1 */
  111. spx_word16_t lpc_floor; /**< Noise floor for LPC analysis */
  112. spx_word16_t folding_gain;
  113. const SpeexSubmode *submodes[SB_SUBMODES]; /**< Sub-mode data for the mode */
  114. int defaultSubmode; /**< Default sub-mode to use when encoding */
  115. int low_quality_map[11]; /**< Mode corresponding to each quality setting */
  116. int quality_map[11]; /**< Mode corresponding to each quality setting */
  117. #ifndef DISABLE_VBR
  118. const float (*vbr_thresh)[11];
  119. #endif
  120. int nb_modes;
  121. } SpeexSBMode;
  122. int speex_encode_native(void *state, spx_word16_t *in, SpeexBits *bits);
  123. int speex_decode_native(void *state, SpeexBits *bits, spx_word16_t *out);
  124. int nb_mode_query(const void *mode, int request, void *ptr);
  125. int wb_mode_query(const void *mode, int request, void *ptr);
  126. #endif