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