Go to the documentation of this file.
28 #ifndef AVCODEC_AACENC_QUANTIZATION_H
29 #define AVCODEC_AACENC_QUANTIZATION_H
44 const float *scaled,
int size,
int scale_idx,
45 int cb,
const float lambda,
const float uplim,
46 int *
bits,
float *energy,
int BT_ZERO,
int BT_UNSIGNED,
47 int BT_PAIR,
int BT_ESC,
int BT_NOISE,
int BT_STEREO,
54 const float CLIPPED_ESCAPE = 165140.0f*IQ;
58 const int dim = BT_PAIR ? 2 : 4;
62 if (BT_ZERO || BT_NOISE || BT_STEREO) {
71 for (j = 0; j <
dim; j++)
77 s->abs_pow34(
s->scoefs, in,
size);
88 int *quants =
s->qcoefs +
i;
91 float quantized, rd = 0.0f;
92 for (j = 0; j <
dim; j++) {
94 curidx += quants[j] + off;
99 for (j = 0; j <
dim; j++) {
102 if (BT_ESC && vec[j] == 64.0
f) {
103 if (t >= CLIPPED_ESCAPE) {
104 quantized = CLIPPED_ESCAPE;
112 quantized = vec[j]*IQ;
116 out[
i+j] = in[
i+j] >= 0 ? quantized : -quantized;
119 qenergy += quantized*quantized;
123 for (j = 0; j <
dim; j++) {
124 quantized = vec[j]*IQ;
125 qenergy += quantized*quantized;
127 out[
i+j] = quantized;
128 rd += (in[
i+j] - quantized)*(in[
i+j] - quantized);
131 cost += rd * lambda + curbits;
138 for (j = 0; j <
dim; j++)
142 for (j = 0; j < 2; j++) {
163 const float *in,
float *
quant,
const float *scaled,
164 int size,
int scale_idx,
int cb,
165 const float lambda,
const float uplim,
166 int *
bits,
float *energy) {
171 #define QUANTIZE_AND_ENCODE_BAND_COST_FUNC(NAME, BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC, BT_NOISE, BT_STEREO, ROUNDING) \
172 static float quantize_and_encode_band_cost_ ## NAME( \
173 struct AACEncContext *s, \
174 PutBitContext *pb, const float *in, float *quant, \
175 const float *scaled, int size, int scale_idx, \
176 int cb, const float lambda, const float uplim, \
177 int *bits, float *energy) { \
178 return quantize_and_encode_band_cost_template( \
179 s, pb, in, quant, scaled, size, scale_idx, \
180 BT_ESC ? ESC_BT : cb, lambda, uplim, bits, energy, \
181 BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC, BT_NOISE, BT_STEREO, \
198 const
float *scaled,
int size,
int scale_idx,
199 int cb, const
float lambda, const
float uplim,
200 int *
bits,
float *energy) = {
201 quantize_and_encode_band_cost_ZERO,
202 quantize_and_encode_band_cost_SQUAD,
203 quantize_and_encode_band_cost_SQUAD,
204 quantize_and_encode_band_cost_UQUAD,
205 quantize_and_encode_band_cost_UQUAD,
206 quantize_and_encode_band_cost_SPAIR,
207 quantize_and_encode_band_cost_SPAIR,
208 quantize_and_encode_band_cost_UPAIR,
209 quantize_and_encode_band_cost_UPAIR,
210 quantize_and_encode_band_cost_UPAIR,
211 quantize_and_encode_band_cost_UPAIR,
212 quantize_and_encode_band_cost_ESC,
214 quantize_and_encode_band_cost_NOISE,
215 quantize_and_encode_band_cost_STEREO,
216 quantize_and_encode_band_cost_STEREO,
222 const float *scaled,
int size,
int scale_idx,
223 int cb,
const float lambda,
const float uplim,
224 int *
bits,
float *energy) = {
225 quantize_and_encode_band_cost_ZERO,
226 quantize_and_encode_band_cost_SQUAD,
227 quantize_and_encode_band_cost_SQUAD,
228 quantize_and_encode_band_cost_UQUAD,
229 quantize_and_encode_band_cost_UQUAD,
230 quantize_and_encode_band_cost_SPAIR,
231 quantize_and_encode_band_cost_SPAIR,
232 quantize_and_encode_band_cost_UPAIR,
233 quantize_and_encode_band_cost_UPAIR,
234 quantize_and_encode_band_cost_UPAIR,
235 quantize_and_encode_band_cost_UPAIR,
236 quantize_and_encode_band_cost_ESC_RTZ,
238 quantize_and_encode_band_cost_NOISE,
239 quantize_and_encode_band_cost_STEREO,
240 quantize_and_encode_band_cost_STEREO,
243 #define quantize_and_encode_band_cost( \
244 s, pb, in, quant, scaled, size, scale_idx, cb, \
245 lambda, uplim, bits, energy, rtz) \
246 ((rtz) ? quantize_and_encode_band_cost_rtz_arr : quantize_and_encode_band_cost_arr)[cb]( \
247 s, pb, in, quant, scaled, size, scale_idx, cb, \
248 lambda, uplim, bits, energy)
251 const float *scaled,
int size,
int scale_idx,
252 int cb,
const float lambda,
const float uplim,
253 int *
bits,
float *energy,
int rtz)
260 const float *scaled,
int size,
int scale_idx,
261 int cb,
const float lambda,
const float uplim,
262 int *
bits,
float *energy,
int rtz)
266 cb, 0.0
f, uplim, &auxbits, energy, rtz);
274 const float *in,
float *
out,
int size,
int scale_idx,
275 int cb,
const float lambda,
int rtz)
static float(*const quantize_and_encode_band_cost_rtz_arr[])(struct AACEncContext *s, PutBitContext *pb, const float *in, float *quant, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits, float *energy)
static double cb(void *priv, double x, double y)
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static const uint8_t aac_cb_maxval[12]
#define SCALE_DIV_512
scalefactor difference that corresponds to scale difference in 512 times
#define POW_SF2_ZERO
ff_aac_pow2sf_tab index corresponding to pow(2, 0);
static int quantize_band_cost_bits(struct AACEncContext *s, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits, float *energy, int rtz)
static __device__ float fabsf(float a)
static int quant(float coef, const float Q, const float rounding)
Quantize one coefficient.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static float quantize_and_encode_band_cost_NONE(struct AACEncContext *s, PutBitContext *pb, const float *in, float *quant, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits, float *energy)
static const uint8_t aac_cb_range[12]
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
#define QUANTIZE_AND_ENCODE_BAND_COST_FUNC(NAME, BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC, BT_NOISE, BT_STEREO, ROUNDING)
const uint16_t *const ff_aac_spectral_codes[11]
#define quantize_and_encode_band_cost( s, pb, in, quant, scaled, size, scale_idx, cb, lambda, uplim, bits, energy, rtz)
#define i(width, name, range_min, range_max)
#define SCALE_ONE_POS
scalefactor index that corresponds to scale=1.0
static av_always_inline float cbrtf(float x)
const float *const ff_aac_codebook_vectors[]
const uint8_t *const ff_aac_spectral_bits[11]
static av_always_inline float quantize_and_encode_band_cost_template(struct AACEncContext *s, PutBitContext *pb, const float *in, float *out, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits, float *energy, int BT_ZERO, int BT_UNSIGNED, int BT_PAIR, int BT_ESC, int BT_NOISE, int BT_STEREO, const float ROUNDING)
Calculate rate distortion cost for quantizing with given codebook.
float ff_aac_pow2sf_tab[428]
static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb, const float *in, float *out, int size, int scale_idx, int cb, const float lambda, int rtz)
float ff_aac_pow34sf_tab[428]
static float quantize_band_cost(struct AACEncContext *s, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits, float *energy, int rtz)
static float(*const quantize_and_encode_band_cost_arr[])(struct AACEncContext *s, PutBitContext *pb, const float *in, float *quant, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits, float *energy)