FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
aacenc_quantization.h
Go to the documentation of this file.
1 /*
2  * AAC encoder intensity stereo
3  * Copyright (C) 2015 Rostislav Pehlivanov
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * AAC encoder quantizer
25  * @author Rostislav Pehlivanov ( atomnuker gmail com )
26  */
27 
28 #ifndef AVCODEC_AACENC_QUANTIZATION_H
29 #define AVCODEC_AACENC_QUANTIZATION_H
30 
31 #include "aactab.h"
32 #include "aacenc.h"
33 #include "aacenctab.h"
34 #include "aacenc_utils.h"
35 
36 /**
37  * Calculate rate distortion cost for quantizing with given codebook
38  *
39  * @return quantization distortion
40  */
42  struct AACEncContext *s,
43  PutBitContext *pb, const float *in, float *out,
44  const float *scaled, int size, int scale_idx,
45  int cb, const float lambda, const float uplim,
46  int *bits, int BT_ZERO, int BT_UNSIGNED,
47  int BT_PAIR, int BT_ESC, int BT_NOISE, int BT_STEREO,
48  const float ROUNDING)
49 {
50  const int q_idx = POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512;
51  const float Q = ff_aac_pow2sf_tab [q_idx];
52  const float Q34 = ff_aac_pow34sf_tab[q_idx];
53  const float IQ = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
54  const float CLIPPED_ESCAPE = 165140.0f*IQ;
55  int i, j;
56  float cost = 0;
57  const int dim = BT_PAIR ? 2 : 4;
58  int resbits = 0;
59  int off;
60 
61  if (BT_ZERO || BT_NOISE || BT_STEREO) {
62  for (i = 0; i < size; i++)
63  cost += in[i]*in[i];
64  if (bits)
65  *bits = 0;
66  if (out) {
67  for (i = 0; i < size; i += dim)
68  for (j = 0; j < dim; j++)
69  out[i+j] = 0.0f;
70  }
71  return cost * lambda;
72  }
73  if (!scaled) {
74  abs_pow34_v(s->scoefs, in, size);
75  scaled = s->scoefs;
76  }
77  quantize_bands(s->qcoefs, in, scaled, size, Q34, !BT_UNSIGNED, aac_cb_maxval[cb], ROUNDING);
78  if (BT_UNSIGNED) {
79  off = 0;
80  } else {
81  off = aac_cb_maxval[cb];
82  }
83  for (i = 0; i < size; i += dim) {
84  const float *vec;
85  int *quants = s->qcoefs + i;
86  int curidx = 0;
87  int curbits;
88  float quantized, rd = 0.0f;
89  for (j = 0; j < dim; j++) {
90  curidx *= aac_cb_range[cb];
91  curidx += quants[j] + off;
92  }
93  curbits = ff_aac_spectral_bits[cb-1][curidx];
94  vec = &ff_aac_codebook_vectors[cb-1][curidx*dim];
95  if (BT_UNSIGNED) {
96  for (j = 0; j < dim; j++) {
97  float t = fabsf(in[i+j]);
98  float di;
99  if (BT_ESC && vec[j] == 64.0f) { //FIXME: slow
100  if (t >= CLIPPED_ESCAPE) {
101  quantized = CLIPPED_ESCAPE;
102  curbits += 21;
103  } else {
104  int c = av_clip_uintp2(quant(t, Q, ROUNDING), 13);
105  quantized = c*cbrtf(c)*IQ;
106  curbits += av_log2(c)*2 - 4 + 1;
107  }
108  } else {
109  quantized = vec[j]*IQ;
110  }
111  di = t - quantized;
112  if (out)
113  out[i+j] = in[i+j] >= 0 ? quantized : -quantized;
114  if (vec[j] != 0.0f)
115  curbits++;
116  rd += di*di;
117  }
118  } else {
119  for (j = 0; j < dim; j++) {
120  quantized = vec[j]*IQ;
121  if (out)
122  out[i+j] = quantized;
123  rd += (in[i+j] - quantized)*(in[i+j] - quantized);
124  }
125  }
126  cost += rd * lambda + curbits;
127  resbits += curbits;
128  if (cost >= uplim)
129  return uplim;
130  if (pb) {
131  put_bits(pb, ff_aac_spectral_bits[cb-1][curidx], ff_aac_spectral_codes[cb-1][curidx]);
132  if (BT_UNSIGNED)
133  for (j = 0; j < dim; j++)
134  if (ff_aac_codebook_vectors[cb-1][curidx*dim+j] != 0.0f)
135  put_bits(pb, 1, in[i+j] < 0.0f);
136  if (BT_ESC) {
137  for (j = 0; j < 2; j++) {
138  if (ff_aac_codebook_vectors[cb-1][curidx*2+j] == 64.0f) {
139  int coef = av_clip_uintp2(quant(fabsf(in[i+j]), Q, ROUNDING), 13);
140  int len = av_log2(coef);
141 
142  put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);
143  put_sbits(pb, len, coef);
144  }
145  }
146  }
147  }
148  }
149 
150  if (bits)
151  *bits = resbits;
152  return cost;
153 }
154 
156  const float *in, float *quant, const float *scaled,
157  int size, int scale_idx, int cb,
158  const float lambda, const float uplim,
159  int *bits) {
160  av_assert0(0);
161  return 0.0f;
162 }
163 
164 #define QUANTIZE_AND_ENCODE_BAND_COST_FUNC(NAME, BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC, BT_NOISE, BT_STEREO, ROUNDING) \
165 static float quantize_and_encode_band_cost_ ## NAME( \
166  struct AACEncContext *s, \
167  PutBitContext *pb, const float *in, float *quant, \
168  const float *scaled, int size, int scale_idx, \
169  int cb, const float lambda, const float uplim, \
170  int *bits) { \
171  return quantize_and_encode_band_cost_template( \
172  s, pb, in, quant, scaled, size, scale_idx, \
173  BT_ESC ? ESC_BT : cb, lambda, uplim, bits, \
174  BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC, BT_NOISE, BT_STEREO, \
175  ROUNDING); \
176 }
177 
178 QUANTIZE_AND_ENCODE_BAND_COST_FUNC(ZERO, 1, 0, 0, 0, 0, 0, ROUND_STANDARD)
179 QUANTIZE_AND_ENCODE_BAND_COST_FUNC(SQUAD, 0, 0, 0, 0, 0, 0, ROUND_STANDARD)
180 QUANTIZE_AND_ENCODE_BAND_COST_FUNC(UQUAD, 0, 1, 0, 0, 0, 0, ROUND_STANDARD)
181 QUANTIZE_AND_ENCODE_BAND_COST_FUNC(SPAIR, 0, 0, 1, 0, 0, 0, ROUND_STANDARD)
182 QUANTIZE_AND_ENCODE_BAND_COST_FUNC(UPAIR, 0, 1, 1, 0, 0, 0, ROUND_STANDARD)
184 QUANTIZE_AND_ENCODE_BAND_COST_FUNC(ESC_RTZ, 0, 1, 1, 1, 0, 0, ROUND_TO_ZERO)
185 QUANTIZE_AND_ENCODE_BAND_COST_FUNC(NOISE, 0, 0, 0, 0, 1, 0, ROUND_STANDARD)
187 
188 static float (*const quantize_and_encode_band_cost_arr[])(
189  struct AACEncContext *s,
190  PutBitContext *pb, const float *in, float *quant,
191  const float *scaled, int size, int scale_idx,
192  int cb, const float lambda, const float uplim,
193  int *bits) = {
194  quantize_and_encode_band_cost_ZERO,
195  quantize_and_encode_band_cost_SQUAD,
196  quantize_and_encode_band_cost_SQUAD,
197  quantize_and_encode_band_cost_UQUAD,
198  quantize_and_encode_band_cost_UQUAD,
199  quantize_and_encode_band_cost_SPAIR,
200  quantize_and_encode_band_cost_SPAIR,
201  quantize_and_encode_band_cost_UPAIR,
202  quantize_and_encode_band_cost_UPAIR,
203  quantize_and_encode_band_cost_UPAIR,
204  quantize_and_encode_band_cost_UPAIR,
205  quantize_and_encode_band_cost_ESC,
206  quantize_and_encode_band_cost_NONE, /* CB 12 doesn't exist */
207  quantize_and_encode_band_cost_NOISE,
208  quantize_and_encode_band_cost_STEREO,
209  quantize_and_encode_band_cost_STEREO,
210 };
211 
213  struct AACEncContext *s,
214  PutBitContext *pb, const float *in, float *quant,
215  const float *scaled, int size, int scale_idx,
216  int cb, const float lambda, const float uplim,
217  int *bits) = {
218  quantize_and_encode_band_cost_ZERO,
219  quantize_and_encode_band_cost_SQUAD,
220  quantize_and_encode_band_cost_SQUAD,
221  quantize_and_encode_band_cost_UQUAD,
222  quantize_and_encode_band_cost_UQUAD,
223  quantize_and_encode_band_cost_SPAIR,
224  quantize_and_encode_band_cost_SPAIR,
225  quantize_and_encode_band_cost_UPAIR,
226  quantize_and_encode_band_cost_UPAIR,
227  quantize_and_encode_band_cost_UPAIR,
228  quantize_and_encode_band_cost_UPAIR,
229  quantize_and_encode_band_cost_ESC_RTZ,
230  quantize_and_encode_band_cost_NONE, /* CB 12 doesn't exist */
231  quantize_and_encode_band_cost_NOISE,
232  quantize_and_encode_band_cost_STEREO,
233  quantize_and_encode_band_cost_STEREO,
234 };
235 
236 #define quantize_and_encode_band_cost( \
237  s, pb, in, quant, scaled, size, scale_idx, cb, \
238  lambda, uplim, bits, rtz) \
239  ((rtz) ? quantize_and_encode_band_cost_rtz_arr : quantize_and_encode_band_cost_arr)[cb]( \
240  s, pb, in, quant, scaled, size, scale_idx, cb, \
241  lambda, uplim, bits)
242 
243 static inline float quantize_band_cost(struct AACEncContext *s, const float *in,
244  const float *scaled, int size, int scale_idx,
245  int cb, const float lambda, const float uplim,
246  int *bits, int rtz)
247 {
248  return quantize_and_encode_band_cost(s, NULL, in, NULL, scaled, size, scale_idx,
249  cb, lambda, uplim, bits, rtz);
250 }
251 
253  const float *in, float *out, int size, int scale_idx,
254  int cb, const float lambda, int rtz)
255 {
256  quantize_and_encode_band_cost(s, pb, in, out, NULL, size, scale_idx, cb, lambda,
257  INFINITY, NULL, rtz);
258 }
259 
260 #endif /* AVCODEC_AACENC_QUANTIZATION_H */
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)
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:192
static void abs_pow34_v(float *out, const float *in, const int size)
Definition: aacenc_utils.h:39
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:167
#define quantize_and_encode_band_cost(s, pb, in, quant, scaled, size, scale_idx, cb, lambda, uplim, bits, rtz)
float lambda
Definition: aacenc.h:101
#define ROUND_TO_ZERO
Definition: aacenc_utils.h:36
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:97
AAC encoder context.
Definition: aacenc.h:80
uint8_t bits
Definition: crc.c:295
float ff_aac_pow34sf_tab[428]
Definition: aac_tablegen.h:33
int qcoefs[96]
quantized coefficients
Definition: aacenc.h:103
ptrdiff_t size
Definition: opengl_enc.c:101
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)
#define STEREO
Definition: atrac3.c:52
const float *const ff_aac_codebook_vectors[]
Definition: aactab.c:906
#define POW_SF2_ZERO
ff_aac_pow2sf_tab index corresponding to pow(2, 0);
#define SCALE_DIV_512
scalefactor difference that corresponds to scale difference in 512 times
Definition: aac.h:148
const uint8_t *const ff_aac_spectral_bits[11]
Definition: aactab.c:410
PutBitContext pb
Definition: aacenc.h:83
#define ROUND_STANDARD
Definition: aacenc_utils.h:35
#define av_log2
Definition: intmath.h:100
#define INFINITY
Definition: math.h:27
static const uint8_t aac_cb_range[12]
Definition: aacenctab.h:110
static void quantize_bands(int *out, const float *in, const float *scaled, int size, float Q34, int is_signed, int maxval, const float rounding)
Definition: aacenc_utils.h:59
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static av_always_inline float cbrtf(float x)
Definition: libm.h:59
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, 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.
int dim
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)
AAC encoder data.
const uint8_t * quant
#define SCALE_ONE_POS
scalefactor index that corresponds to scale=1.0
Definition: aac.h:149
AAC encoder utilities.
static double c[64]
static const uint8_t aac_cb_maxval[12]
Definition: aacenctab.h:111
float ff_aac_pow2sf_tab[428]
Definition: aac_tablegen.h:32
const uint16_t *const ff_aac_spectral_codes[11]
Definition: aactab.c:405
int len
#define QUANTIZE_AND_ENCODE_BAND_COST_FUNC(NAME, BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC, BT_NOISE, BT_STEREO, ROUNDING)
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)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
#define av_always_inline
Definition: attributes.h:37
AAC data declarations.
float scoefs[1024]
scaled coefficients
Definition: aacenc.h:104
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, int rtz)