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