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