cannam@154: /* Copyright (c) 2007-2008 CSIRO cannam@154: Copyright (c) 2007-2009 Xiph.Org Foundation cannam@154: Copyright (c) 2008-2009 Gregory Maxwell cannam@154: Written by Jean-Marc Valin and Gregory Maxwell */ cannam@154: /* cannam@154: Redistribution and use in source and binary forms, with or without cannam@154: modification, are permitted provided that the following conditions cannam@154: are met: cannam@154: cannam@154: - Redistributions of source code must retain the above copyright cannam@154: notice, this list of conditions and the following disclaimer. cannam@154: cannam@154: - Redistributions in binary form must reproduce the above copyright cannam@154: notice, this list of conditions and the following disclaimer in the cannam@154: documentation and/or other materials provided with the distribution. cannam@154: cannam@154: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS cannam@154: ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT cannam@154: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR cannam@154: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER cannam@154: OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, cannam@154: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, cannam@154: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR cannam@154: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF cannam@154: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING cannam@154: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS cannam@154: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. cannam@154: */ cannam@154: cannam@154: #ifndef BANDS_H cannam@154: #define BANDS_H cannam@154: cannam@154: #include "arch.h" cannam@154: #include "modes.h" cannam@154: #include "entenc.h" cannam@154: #include "entdec.h" cannam@154: #include "rate.h" cannam@154: cannam@154: opus_int16 bitexact_cos(opus_int16 x); cannam@154: int bitexact_log2tan(int isin,int icos); cannam@154: cannam@154: /** Compute the amplitude (sqrt energy) in each of the bands cannam@154: * @param m Mode data cannam@154: * @param X Spectrum cannam@154: * @param bandE Square root of the energy for each band (returned) cannam@154: */ cannam@154: void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *bandE, int end, int C, int LM, int arch); cannam@154: cannam@154: /*void compute_noise_energies(const CELTMode *m, const celt_sig *X, const opus_val16 *tonality, celt_ener *bandE);*/ cannam@154: cannam@154: /** Normalise each band of X such that the energy in each band is cannam@154: equal to 1 cannam@154: * @param m Mode data cannam@154: * @param X Spectrum (returned normalised) cannam@154: * @param bandE Square root of the energy for each band cannam@154: */ cannam@154: 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); cannam@154: cannam@154: /** Denormalise each band of X to restore full amplitude cannam@154: * @param m Mode data cannam@154: * @param X Spectrum (returned de-normalised) cannam@154: * @param bandE Square root of the energy for each band cannam@154: */ cannam@154: void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X, cannam@154: celt_sig * OPUS_RESTRICT freq, const opus_val16 *bandE, int start, cannam@154: int end, int M, int downsample, int silence); cannam@154: cannam@154: #define SPREAD_NONE (0) cannam@154: #define SPREAD_LIGHT (1) cannam@154: #define SPREAD_NORMAL (2) cannam@154: #define SPREAD_AGGRESSIVE (3) cannam@154: cannam@154: int spreading_decision(const CELTMode *m, const celt_norm *X, int *average, cannam@154: int last_decision, int *hf_average, int *tapset_decision, int update_hf, cannam@154: int end, int C, int M, const int *spread_weight); cannam@154: cannam@154: #ifdef MEASURE_NORM_MSE cannam@154: void measure_norm_mse(const CELTMode *m, float *X, float *X0, float *bandE, float *bandE0, int M, int N, int C); cannam@154: #endif cannam@154: cannam@154: void haar1(celt_norm *X, int N0, int stride); cannam@154: cannam@154: /** Quantisation/encoding of the residual spectrum cannam@154: * @param encode flag that indicates whether we're encoding (1) or decoding (0) cannam@154: * @param m Mode data cannam@154: * @param start First band to process cannam@154: * @param end Last band to process + 1 cannam@154: * @param X Residual (normalised) cannam@154: * @param Y Residual (normalised) for second channel (or NULL for mono) cannam@154: * @param collapse_masks Anti-collapse tracking mask cannam@154: * @param bandE Square root of the energy for each band cannam@154: * @param pulses Bit allocation (per band) for PVQ cannam@154: * @param shortBlocks Zero for long blocks, non-zero for short blocks cannam@154: * @param spread Amount of spreading to use cannam@154: * @param dual_stereo Zero for MS stereo, non-zero for dual stereo cannam@154: * @param intensity First band to use intensity stereo cannam@154: * @param tf_res Time-frequency resolution change cannam@154: * @param total_bits Total number of bits that can be used for the frame (including the ones already spent) cannam@154: * @param balance Number of unallocated bits cannam@154: * @param en Entropy coder state cannam@154: * @param LM log2() of the number of 2.5 subframes in the frame cannam@154: * @param codedBands Last band to receive bits + 1 cannam@154: * @param seed Random generator seed cannam@154: * @param arch Run-time architecture (see opus_select_arch()) cannam@154: */ cannam@154: void quant_all_bands(int encode, const CELTMode *m, int start, int end, cannam@154: celt_norm * X, celt_norm * Y, unsigned char *collapse_masks, cannam@154: const celt_ener *bandE, int *pulses, int shortBlocks, int spread, cannam@154: int dual_stereo, int intensity, int *tf_res, opus_int32 total_bits, cannam@154: opus_int32 balance, ec_ctx *ec, int M, int codedBands, opus_uint32 *seed, cannam@154: int complexity, int arch, int disable_inv); cannam@154: cannam@154: void anti_collapse(const CELTMode *m, celt_norm *X_, cannam@154: unsigned char *collapse_masks, int LM, int C, int size, int start, cannam@154: int end, const opus_val16 *logE, const opus_val16 *prev1logE, cannam@154: const opus_val16 *prev2logE, const int *pulses, opus_uint32 seed, cannam@154: int arch); cannam@154: cannam@154: opus_uint32 celt_lcg_rand(opus_uint32 seed); cannam@154: cannam@154: int hysteresis_decision(opus_val16 val, const opus_val16 *thresholds, const opus_val16 *hysteresis, int N, int prev); cannam@154: cannam@154: #endif /* BANDS_H */