bands.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* Copyright (c) 2007-2008 CSIRO
  2. Copyright (c) 2007-2009 Xiph.Org Foundation
  3. Copyright (c) 2008-2009 Gregory Maxwell
  4. Written by Jean-Marc Valin and Gregory Maxwell */
  5. /*
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions
  8. are met:
  9. - Redistributions of source code must retain the above copyright
  10. notice, this list of conditions and the following disclaimer.
  11. - Redistributions in binary form must reproduce the above copyright
  12. notice, this list of conditions and the following disclaimer in the
  13. documentation and/or other materials provided with the distribution.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  18. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef BANDS_H
  27. #define BANDS_H
  28. #include "arch.h"
  29. #include "modes.h"
  30. #include "entenc.h"
  31. #include "entdec.h"
  32. #include "rate.h"
  33. opus_int16 bitexact_cos(opus_int16 x);
  34. int bitexact_log2tan(int isin,int icos);
  35. /** Compute the amplitude (sqrt energy) in each of the bands
  36. * @param m Mode data
  37. * @param X Spectrum
  38. * @param bandE Square root of the energy for each band (returned)
  39. */
  40. void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bandE, int end, int C, int LM, int arch);
  41. /*void compute_noise_energies(const CELTMode *m, const celt_sig *X, const opus_val16 *tonality, celt_ener *bandE);*/
  42. /** Normalise each band of X such that the energy in each band is
  43. equal to 1
  44. * @param m Mode data
  45. * @param X Spectrum (returned normalised)
  46. * @param bandE Square root of the energy for each band
  47. */
  48. void normalise_bands(const CELTMode *m, const celt_sig * OPUS_RESTRICT freq, celt_norm * OPUS_RESTRICT X, const celt_ener *bandE, int end, int C, int M);
  49. /** Denormalise each band of X to restore full amplitude
  50. * @param m Mode data
  51. * @param X Spectrum (returned de-normalised)
  52. * @param bandE Square root of the energy for each band
  53. */
  54. void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X,
  55. celt_sig * OPUS_RESTRICT freq, const opus_val16 *bandE, int start,
  56. int end, int M, int downsample, int silence);
  57. #define SPREAD_NONE (0)
  58. #define SPREAD_LIGHT (1)
  59. #define SPREAD_NORMAL (2)
  60. #define SPREAD_AGGRESSIVE (3)
  61. int spreading_decision(const CELTMode *m, const celt_norm *X, int *average,
  62. int last_decision, int *hf_average, int *tapset_decision, int update_hf,
  63. int end, int C, int M, const int *spread_weight);
  64. #ifdef MEASURE_NORM_MSE
  65. void measure_norm_mse(const CELTMode *m, float *X, float *X0, float *bandE, float *bandE0, int M, int N, int C);
  66. #endif
  67. void haar1(celt_norm *X, int N0, int stride);
  68. /** Quantisation/encoding of the residual spectrum
  69. * @param encode flag that indicates whether we're encoding (1) or decoding (0)
  70. * @param m Mode data
  71. * @param start First band to process
  72. * @param end Last band to process + 1
  73. * @param X Residual (normalised)
  74. * @param Y Residual (normalised) for second channel (or NULL for mono)
  75. * @param collapse_masks Anti-collapse tracking mask
  76. * @param bandE Square root of the energy for each band
  77. * @param pulses Bit allocation (per band) for PVQ
  78. * @param shortBlocks Zero for long blocks, non-zero for short blocks
  79. * @param spread Amount of spreading to use
  80. * @param dual_stereo Zero for MS stereo, non-zero for dual stereo
  81. * @param intensity First band to use intensity stereo
  82. * @param tf_res Time-frequency resolution change
  83. * @param total_bits Total number of bits that can be used for the frame (including the ones already spent)
  84. * @param balance Number of unallocated bits
  85. * @param en Entropy coder state
  86. * @param LM log2() of the number of 2.5 subframes in the frame
  87. * @param codedBands Last band to receive bits + 1
  88. * @param seed Random generator seed
  89. * @param arch Run-time architecture (see opus_select_arch())
  90. */
  91. void quant_all_bands(int encode, const CELTMode *m, int start, int end,
  92. celt_norm * X, celt_norm * Y, unsigned char *collapse_masks,
  93. const celt_ener *bandE, int *pulses, int shortBlocks, int spread,
  94. int dual_stereo, int intensity, int *tf_res, opus_int32 total_bits,
  95. opus_int32 balance, ec_ctx *ec, int M, int codedBands, opus_uint32 *seed,
  96. int complexity, int arch, int disable_inv);
  97. void anti_collapse(const CELTMode *m, celt_norm *X_,
  98. unsigned char *collapse_masks, int LM, int C, int size, int start,
  99. int end, const opus_val16 *logE, const opus_val16 *prev1logE,
  100. const opus_val16 *prev2logE, const int *pulses, opus_uint32 seed,
  101. int arch);
  102. opus_uint32 celt_lcg_rand(opus_uint32 seed);
  103. int hysteresis_decision(opus_val16 val, const opus_val16 *thresholds, const opus_val16 *hysteresis, int N, int prev);
  104. #endif /* BANDS_H */