celt.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. opus_val16 tonality;
  47. opus_val16 tonality_slope;
  48. opus_val16 noisiness;
  49. opus_val16 activity;
  50. opus_val16 music_prob;
  51. }AnalysisInfo;
  52. #define __celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (const CELTMode**)(ptr)))
  53. #define __celt_check_analysis_ptr(ptr) ((ptr) + ((ptr) - (const AnalysisInfo*)(ptr)))
  54. /* Encoder/decoder Requests */
  55. #define CELT_SET_PREDICTION_REQUEST 10002
  56. /** Controls the use of interframe prediction.
  57. 0=Independent frames
  58. 1=Short term interframe prediction allowed
  59. 2=Long term prediction allowed
  60. */
  61. #define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, __opus_check_int(x)
  62. #define CELT_SET_INPUT_CLIPPING_REQUEST 10004
  63. #define CELT_SET_INPUT_CLIPPING(x) CELT_SET_INPUT_CLIPPING_REQUEST, __opus_check_int(x)
  64. #define CELT_GET_AND_CLEAR_ERROR_REQUEST 10007
  65. #define CELT_GET_AND_CLEAR_ERROR(x) CELT_GET_AND_CLEAR_ERROR_REQUEST, __opus_check_int_ptr(x)
  66. #define CELT_SET_CHANNELS_REQUEST 10008
  67. #define CELT_SET_CHANNELS(x) CELT_SET_CHANNELS_REQUEST, __opus_check_int(x)
  68. /* Internal */
  69. #define CELT_SET_START_BAND_REQUEST 10010
  70. #define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, __opus_check_int(x)
  71. #define CELT_SET_END_BAND_REQUEST 10012
  72. #define CELT_SET_END_BAND(x) CELT_SET_END_BAND_REQUEST, __opus_check_int(x)
  73. #define CELT_GET_MODE_REQUEST 10015
  74. /** Get the CELTMode used by an encoder or decoder */
  75. #define CELT_GET_MODE(x) CELT_GET_MODE_REQUEST, __celt_check_mode_ptr_ptr(x)
  76. #define CELT_SET_SIGNALLING_REQUEST 10016
  77. #define CELT_SET_SIGNALLING(x) CELT_SET_SIGNALLING_REQUEST, __opus_check_int(x)
  78. #define CELT_SET_TONALITY_REQUEST 10018
  79. #define CELT_SET_TONALITY(x) CELT_SET_TONALITY_REQUEST, __opus_check_int(x)
  80. #define CELT_SET_TONALITY_SLOPE_REQUEST 10020
  81. #define CELT_SET_TONALITY_SLOPE(x) CELT_SET_TONALITY_SLOPE_REQUEST, __opus_check_int(x)
  82. #define CELT_SET_ANALYSIS_REQUEST 10022
  83. #define CELT_SET_ANALYSIS(x) CELT_SET_ANALYSIS_REQUEST, __celt_check_analysis_ptr(x)
  84. /* Encoder stuff */
  85. int celt_encoder_get_size(int channels);
  86. int celt_encode_with_ec(OpusCustomEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc);
  87. int celt_encoder_init(CELTEncoder *st, opus_int32 sampling_rate, int channels);
  88. /* Decoder stuff */
  89. int celt_decoder_get_size(int channels);
  90. int celt_decoder_init(CELTDecoder *st, opus_int32 sampling_rate, int channels);
  91. int celt_decode_with_ec(OpusCustomDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, opus_val16 * OPUS_RESTRICT pcm, int frame_size, ec_dec *dec);
  92. #define celt_encoder_ctl opus_custom_encoder_ctl
  93. #define celt_decoder_ctl opus_custom_decoder_ctl
  94. #ifndef OPUS_VERSION
  95. #define OPUS_VERSION "unknown"
  96. #endif
  97. #ifdef CUSTOM_MODES
  98. #define OPUS_CUSTOM_NOSTATIC
  99. #else
  100. #define OPUS_CUSTOM_NOSTATIC static inline
  101. #endif
  102. static const unsigned char trim_icdf[11] = {126, 124, 119, 109, 87, 41, 19, 9, 4, 2, 0};
  103. /* Probs: NONE: 21.875%, LIGHT: 6.25%, NORMAL: 65.625%, AGGRESSIVE: 6.25% */
  104. static const unsigned char spread_icdf[4] = {25, 23, 2, 0};
  105. static const unsigned char tapset_icdf[3]={2,1,0};
  106. #ifdef CUSTOM_MODES
  107. static const unsigned char toOpusTable[20] = {
  108. 0xE0, 0xE8, 0xF0, 0xF8,
  109. 0xC0, 0xC8, 0xD0, 0xD8,
  110. 0xA0, 0xA8, 0xB0, 0xB8,
  111. 0x00, 0x00, 0x00, 0x00,
  112. 0x80, 0x88, 0x90, 0x98,
  113. };
  114. static const unsigned char fromOpusTable[16] = {
  115. 0x80, 0x88, 0x90, 0x98,
  116. 0x40, 0x48, 0x50, 0x58,
  117. 0x20, 0x28, 0x30, 0x38,
  118. 0x00, 0x08, 0x10, 0x18
  119. };
  120. static inline int toOpus(unsigned char c)
  121. {
  122. int ret=0;
  123. if (c<0xA0)
  124. ret = toOpusTable[c>>3];
  125. if (ret == 0)
  126. return -1;
  127. else
  128. return ret|(c&0x7);
  129. }
  130. static inline int fromOpus(unsigned char c)
  131. {
  132. if (c<0x80)
  133. return -1;
  134. else
  135. return fromOpusTable[(c>>3)-16] | (c&0x7);
  136. }
  137. #endif /* CUSTOM_MODES */
  138. #define COMBFILTER_MAXPERIOD 1024
  139. #define COMBFILTER_MINPERIOD 15
  140. extern const signed char tf_select_table[4][8];
  141. int resampling_factor(opus_int32 rate);
  142. void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N,
  143. opus_val16 g0, opus_val16 g1, int tapset0, int tapset1,
  144. const opus_val16 *window, int overlap);
  145. void init_caps(const CELTMode *m,int *cap,int LM,int C);
  146. #ifdef RESYNTH
  147. void deemphasis(celt_sig *in[], opus_val16 *pcm, int N, int C, int downsample, const opus_val16 *coef, celt_sig *mem, celt_sig * OPUS_RESTRICT scratch);
  148. void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X,
  149. celt_sig * OPUS_RESTRICT out_mem[], int C, int LM);
  150. #endif
  151. #ifdef __cplusplus
  152. }
  153. #endif
  154. #endif /* CELT_H */