celt.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /* Copyright (c) 2007-2008 CSIRO
  2. Copyright (c) 2007-2009 Xiph.Org Foundation
  3. Copyright (c) 2008 Gregory Maxwell
  4. Written by Jean-Marc Valin and Gregory Maxwell */
  5. /**
  6. @file celt.h
  7. @brief Contains all the functions for encoding and decoding audio
  8. */
  9. /*
  10. Redistribution and use in source and binary forms, with or without
  11. modification, are permitted provided that the following conditions
  12. are met:
  13. - Redistributions of source code must retain the above copyright
  14. notice, this list of conditions and the following disclaimer.
  15. - Redistributions in binary form must reproduce the above copyright
  16. notice, this list of conditions and the following disclaimer in the
  17. documentation and/or other materials provided with the distribution.
  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 COPYRIGHT OWNER
  22. OR 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 CELT_H
  31. #define CELT_H
  32. #include "opus_types.h"
  33. #include "opus_defines.h"
  34. #include "opus_custom.h"
  35. #include "entenc.h"
  36. #include "entdec.h"
  37. #include "arch.h"
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. #define CELTEncoder OpusCustomEncoder
  42. #define CELTDecoder OpusCustomDecoder
  43. #define CELTMode OpusCustomMode
  44. typedef struct {
  45. int valid;
  46. float tonality;
  47. float tonality_slope;
  48. float noisiness;
  49. float activity;
  50. float music_prob;
  51. float vad_prob;
  52. int bandwidth;
  53. float activity_probability;
  54. } AnalysisInfo;
  55. typedef struct {
  56. int signalType;
  57. int offset;
  58. } SILKInfo;
  59. #define __celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (const CELTMode**)(ptr)))
  60. #define __celt_check_analysis_ptr(ptr) ((ptr) + ((ptr) - (const AnalysisInfo*)(ptr)))
  61. #define __celt_check_silkinfo_ptr(ptr) ((ptr) + ((ptr) - (const SILKInfo*)(ptr)))
  62. /* Encoder/decoder Requests */
  63. #define CELT_SET_PREDICTION_REQUEST 10002
  64. /** Controls the use of interframe prediction.
  65. 0=Independent frames
  66. 1=Short term interframe prediction allowed
  67. 2=Long term prediction allowed
  68. */
  69. #define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, __opus_check_int(x)
  70. #define CELT_SET_INPUT_CLIPPING_REQUEST 10004
  71. #define CELT_SET_INPUT_CLIPPING(x) CELT_SET_INPUT_CLIPPING_REQUEST, __opus_check_int(x)
  72. #define CELT_GET_AND_CLEAR_ERROR_REQUEST 10007
  73. #define CELT_GET_AND_CLEAR_ERROR(x) CELT_GET_AND_CLEAR_ERROR_REQUEST, __opus_check_int_ptr(x)
  74. #define CELT_SET_CHANNELS_REQUEST 10008
  75. #define CELT_SET_CHANNELS(x) CELT_SET_CHANNELS_REQUEST, __opus_check_int(x)
  76. /* Internal */
  77. #define CELT_SET_START_BAND_REQUEST 10010
  78. #define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, __opus_check_int(x)
  79. #define CELT_SET_END_BAND_REQUEST 10012
  80. #define CELT_SET_END_BAND(x) CELT_SET_END_BAND_REQUEST, __opus_check_int(x)
  81. #define CELT_GET_MODE_REQUEST 10015
  82. /** Get the CELTMode used by an encoder or decoder */
  83. #define CELT_GET_MODE(x) CELT_GET_MODE_REQUEST, __celt_check_mode_ptr_ptr(x)
  84. #define CELT_SET_SIGNALLING_REQUEST 10016
  85. #define CELT_SET_SIGNALLING(x) CELT_SET_SIGNALLING_REQUEST, __opus_check_int(x)
  86. #define CELT_SET_TONALITY_REQUEST 10018
  87. #define CELT_SET_TONALITY(x) CELT_SET_TONALITY_REQUEST, __opus_check_int(x)
  88. #define CELT_SET_TONALITY_SLOPE_REQUEST 10020
  89. #define CELT_SET_TONALITY_SLOPE(x) CELT_SET_TONALITY_SLOPE_REQUEST, __opus_check_int(x)
  90. #define CELT_SET_ANALYSIS_REQUEST 10022
  91. #define CELT_SET_ANALYSIS(x) CELT_SET_ANALYSIS_REQUEST, __celt_check_analysis_ptr(x)
  92. #define OPUS_SET_LFE_REQUEST 10024
  93. #define OPUS_SET_LFE(x) OPUS_SET_LFE_REQUEST, __opus_check_int(x)
  94. #define OPUS_SET_ENERGY_MASK_REQUEST 10026
  95. #define OPUS_SET_ENERGY_MASK(x) OPUS_SET_ENERGY_MASK_REQUEST, __opus_check_val16_ptr(x)
  96. #define CELT_SET_SILK_INFO_REQUEST 10028
  97. #define CELT_SET_SILK_INFO(x) CELT_SET_SILK_INFO_REQUEST, __celt_check_silkinfo_ptr(x)
  98. /* Encoder stuff */
  99. int celt_encoder_get_size(int channels);
  100. int celt_encode_with_ec(OpusCustomEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc);
  101. int celt_encoder_init(CELTEncoder *st, opus_int32 sampling_rate, int channels,
  102. int arch);
  103. /* Decoder stuff */
  104. int celt_decoder_get_size(int channels);
  105. int celt_decoder_init(CELTDecoder *st, opus_int32 sampling_rate, int channels);
  106. int celt_decode_with_ec(OpusCustomDecoder * OPUS_RESTRICT st, const unsigned char *data,
  107. int len, opus_val16 * OPUS_RESTRICT pcm, int frame_size, ec_dec *dec, int accum);
  108. #define celt_encoder_ctl opus_custom_encoder_ctl
  109. #define celt_decoder_ctl opus_custom_decoder_ctl
  110. #ifdef CUSTOM_MODES
  111. #define OPUS_CUSTOM_NOSTATIC
  112. #else
  113. #define OPUS_CUSTOM_NOSTATIC static OPUS_INLINE
  114. #endif
  115. static const unsigned char trim_icdf[11] = {126, 124, 119, 109, 87, 41, 19, 9, 4, 2, 0};
  116. /* Probs: NONE: 21.875%, LIGHT: 6.25%, NORMAL: 65.625%, AGGRESSIVE: 6.25% */
  117. static const unsigned char spread_icdf[4] = {25, 23, 2, 0};
  118. static const unsigned char tapset_icdf[3]={2,1,0};
  119. #ifdef CUSTOM_MODES
  120. static const unsigned char toOpusTable[20] = {
  121. 0xE0, 0xE8, 0xF0, 0xF8,
  122. 0xC0, 0xC8, 0xD0, 0xD8,
  123. 0xA0, 0xA8, 0xB0, 0xB8,
  124. 0x00, 0x00, 0x00, 0x00,
  125. 0x80, 0x88, 0x90, 0x98,
  126. };
  127. static const unsigned char fromOpusTable[16] = {
  128. 0x80, 0x88, 0x90, 0x98,
  129. 0x40, 0x48, 0x50, 0x58,
  130. 0x20, 0x28, 0x30, 0x38,
  131. 0x00, 0x08, 0x10, 0x18
  132. };
  133. static OPUS_INLINE int toOpus(unsigned char c)
  134. {
  135. int ret=0;
  136. if (c<0xA0)
  137. ret = toOpusTable[c>>3];
  138. if (ret == 0)
  139. return -1;
  140. else
  141. return ret|(c&0x7);
  142. }
  143. static OPUS_INLINE int fromOpus(unsigned char c)
  144. {
  145. if (c<0x80)
  146. return -1;
  147. else
  148. return fromOpusTable[(c>>3)-16] | (c&0x7);
  149. }
  150. #endif /* CUSTOM_MODES */
  151. #define COMBFILTER_MAXPERIOD 1024
  152. #define COMBFILTER_MINPERIOD 15
  153. extern const signed char tf_select_table[4][8];
  154. int resampling_factor(opus_int32 rate);
  155. void celt_preemphasis(const opus_val16 * OPUS_RESTRICT pcmp, celt_sig * OPUS_RESTRICT inp,
  156. int N, int CC, int upsample, const opus_val16 *coef, celt_sig *mem, int clip);
  157. void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N,
  158. opus_val16 g0, opus_val16 g1, int tapset0, int tapset1,
  159. const opus_val16 *window, int overlap, int arch);
  160. #ifdef NON_STATIC_COMB_FILTER_CONST_C
  161. void comb_filter_const_c(opus_val32 *y, opus_val32 *x, int T, int N,
  162. opus_val16 g10, opus_val16 g11, opus_val16 g12);
  163. #endif
  164. #ifndef OVERRIDE_COMB_FILTER_CONST
  165. # define comb_filter_const(y, x, T, N, g10, g11, g12, arch) \
  166. ((void)(arch),comb_filter_const_c(y, x, T, N, g10, g11, g12))
  167. #endif
  168. void init_caps(const CELTMode *m,int *cap,int LM,int C);
  169. #ifdef RESYNTH
  170. void deemphasis(celt_sig *in[], opus_val16 *pcm, int N, int C, int downsample, const opus_val16 *coef, celt_sig *mem);
  171. void celt_synthesis(const CELTMode *mode, celt_norm *X, celt_sig * out_syn[],
  172. opus_val16 *oldBandE, int start, int effEnd, int C, int CC, int isTransient,
  173. int LM, int downsample, int silence);
  174. #endif
  175. #ifdef __cplusplus
  176. }
  177. #endif
  178. #endif /* CELT_H */