celt.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. int bandwidth;
  52. }AnalysisInfo;
  53. #define __celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (const CELTMode**)(ptr)))
  54. #define __celt_check_analysis_ptr(ptr) ((ptr) + ((ptr) - (const AnalysisInfo*)(ptr)))
  55. /* Encoder/decoder Requests */
  56. /* Expose this option again when variable framesize actually works */
  57. #define OPUS_FRAMESIZE_VARIABLE 5010 /**< Optimize the frame size dynamically */
  58. #define CELT_SET_PREDICTION_REQUEST 10002
  59. /** Controls the use of interframe prediction.
  60. 0=Independent frames
  61. 1=Short term interframe prediction allowed
  62. 2=Long term prediction allowed
  63. */
  64. #define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, __opus_check_int(x)
  65. #define CELT_SET_INPUT_CLIPPING_REQUEST 10004
  66. #define CELT_SET_INPUT_CLIPPING(x) CELT_SET_INPUT_CLIPPING_REQUEST, __opus_check_int(x)
  67. #define CELT_GET_AND_CLEAR_ERROR_REQUEST 10007
  68. #define CELT_GET_AND_CLEAR_ERROR(x) CELT_GET_AND_CLEAR_ERROR_REQUEST, __opus_check_int_ptr(x)
  69. #define CELT_SET_CHANNELS_REQUEST 10008
  70. #define CELT_SET_CHANNELS(x) CELT_SET_CHANNELS_REQUEST, __opus_check_int(x)
  71. /* Internal */
  72. #define CELT_SET_START_BAND_REQUEST 10010
  73. #define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, __opus_check_int(x)
  74. #define CELT_SET_END_BAND_REQUEST 10012
  75. #define CELT_SET_END_BAND(x) CELT_SET_END_BAND_REQUEST, __opus_check_int(x)
  76. #define CELT_GET_MODE_REQUEST 10015
  77. /** Get the CELTMode used by an encoder or decoder */
  78. #define CELT_GET_MODE(x) CELT_GET_MODE_REQUEST, __celt_check_mode_ptr_ptr(x)
  79. #define CELT_SET_SIGNALLING_REQUEST 10016
  80. #define CELT_SET_SIGNALLING(x) CELT_SET_SIGNALLING_REQUEST, __opus_check_int(x)
  81. #define CELT_SET_TONALITY_REQUEST 10018
  82. #define CELT_SET_TONALITY(x) CELT_SET_TONALITY_REQUEST, __opus_check_int(x)
  83. #define CELT_SET_TONALITY_SLOPE_REQUEST 10020
  84. #define CELT_SET_TONALITY_SLOPE(x) CELT_SET_TONALITY_SLOPE_REQUEST, __opus_check_int(x)
  85. #define CELT_SET_ANALYSIS_REQUEST 10022
  86. #define CELT_SET_ANALYSIS(x) CELT_SET_ANALYSIS_REQUEST, __celt_check_analysis_ptr(x)
  87. #define OPUS_SET_LFE_REQUEST 10024
  88. #define OPUS_SET_LFE(x) OPUS_SET_LFE_REQUEST, __opus_check_int(x)
  89. #define OPUS_SET_ENERGY_MASK_REQUEST 10026
  90. #define OPUS_SET_ENERGY_MASK(x) OPUS_SET_ENERGY_MASK_REQUEST, __opus_check_val16_ptr(x)
  91. /* Encoder stuff */
  92. int celt_encoder_get_size(int channels);
  93. int celt_encode_with_ec(OpusCustomEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc);
  94. int celt_encoder_init(CELTEncoder *st, opus_int32 sampling_rate, int channels,
  95. int arch);
  96. /* Decoder stuff */
  97. int celt_decoder_get_size(int channels);
  98. int celt_decoder_init(CELTDecoder *st, opus_int32 sampling_rate, int channels);
  99. int celt_decode_with_ec(OpusCustomDecoder * OPUS_RESTRICT st, const unsigned char *data,
  100. int len, opus_val16 * OPUS_RESTRICT pcm, int frame_size, ec_dec *dec, int accum);
  101. #define celt_encoder_ctl opus_custom_encoder_ctl
  102. #define celt_decoder_ctl opus_custom_decoder_ctl
  103. #ifdef CUSTOM_MODES
  104. #define OPUS_CUSTOM_NOSTATIC
  105. #else
  106. #define OPUS_CUSTOM_NOSTATIC static OPUS_INLINE
  107. #endif
  108. static const unsigned char trim_icdf[11] = {126, 124, 119, 109, 87, 41, 19, 9, 4, 2, 0};
  109. /* Probs: NONE: 21.875%, LIGHT: 6.25%, NORMAL: 65.625%, AGGRESSIVE: 6.25% */
  110. static const unsigned char spread_icdf[4] = {25, 23, 2, 0};
  111. static const unsigned char tapset_icdf[3]={2,1,0};
  112. #ifdef CUSTOM_MODES
  113. static const unsigned char toOpusTable[20] = {
  114. 0xE0, 0xE8, 0xF0, 0xF8,
  115. 0xC0, 0xC8, 0xD0, 0xD8,
  116. 0xA0, 0xA8, 0xB0, 0xB8,
  117. 0x00, 0x00, 0x00, 0x00,
  118. 0x80, 0x88, 0x90, 0x98,
  119. };
  120. static const unsigned char fromOpusTable[16] = {
  121. 0x80, 0x88, 0x90, 0x98,
  122. 0x40, 0x48, 0x50, 0x58,
  123. 0x20, 0x28, 0x30, 0x38,
  124. 0x00, 0x08, 0x10, 0x18
  125. };
  126. static OPUS_INLINE int toOpus(unsigned char c)
  127. {
  128. int ret=0;
  129. if (c<0xA0)
  130. ret = toOpusTable[c>>3];
  131. if (ret == 0)
  132. return -1;
  133. else
  134. return ret|(c&0x7);
  135. }
  136. static OPUS_INLINE int fromOpus(unsigned char c)
  137. {
  138. if (c<0x80)
  139. return -1;
  140. else
  141. return fromOpusTable[(c>>3)-16] | (c&0x7);
  142. }
  143. #endif /* CUSTOM_MODES */
  144. #define COMBFILTER_MAXPERIOD 1024
  145. #define COMBFILTER_MINPERIOD 15
  146. extern const signed char tf_select_table[4][8];
  147. int resampling_factor(opus_int32 rate);
  148. void celt_preemphasis(const opus_val16 * OPUS_RESTRICT pcmp, celt_sig * OPUS_RESTRICT inp,
  149. int N, int CC, int upsample, const opus_val16 *coef, celt_sig *mem, int clip);
  150. void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N,
  151. opus_val16 g0, opus_val16 g1, int tapset0, int tapset1,
  152. const opus_val16 *window, int overlap, int arch);
  153. #ifdef NON_STATIC_COMB_FILTER_CONST_C
  154. void comb_filter_const_c(opus_val32 *y, opus_val32 *x, int T, int N,
  155. opus_val16 g10, opus_val16 g11, opus_val16 g12);
  156. #endif
  157. #ifndef OVERRIDE_COMB_FILTER_CONST
  158. # define comb_filter_const(y, x, T, N, g10, g11, g12, arch) \
  159. ((void)(arch),comb_filter_const_c(y, x, T, N, g10, g11, g12))
  160. #endif
  161. void init_caps(const CELTMode *m,int *cap,int LM,int C);
  162. #ifdef RESYNTH
  163. void deemphasis(celt_sig *in[], opus_val16 *pcm, int N, int C, int downsample, const opus_val16 *coef, celt_sig *mem);
  164. void celt_synthesis(const CELTMode *mode, celt_norm *X, celt_sig * out_syn[],
  165. opus_val16 *oldBandE, int start, int effEnd, int C, int CC, int isTransient,
  166. int LM, int downsample, int silence);
  167. #endif
  168. #ifdef __cplusplus
  169. }
  170. #endif
  171. #endif /* CELT_H */