45 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
46 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10,
47 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
48 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 15
53 3, 3, 3, 3, 3, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 9
69 return sqrtf(a * sqrtf(a)) + 0.4054;
73 int size,
float Q34,
int is_signed,
int maxval)
77 for (i = 0; i <
size; i++) {
79 out[
i] = (int)
FFMIN(qc + 0.4054, (
double)maxval);
80 if (is_signed && in[i] < 0.0
f) {
88 #ifndef USE_REALLY_FULL_SEARCH 90 for (i = 0; i <
size; i++) {
91 float a = fabsf(in[i]);
92 out[
i] = sqrtf(a * sqrtf(a));
97 static const uint8_t aac_cb_range [12] = {0, 3, 3, 3, 3, 9, 9, 8, 8, 13, 13, 17};
98 static const uint8_t aac_cb_maxval[12] = {0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12, 16};
108 const float *scaled,
int size,
int scale_idx,
109 int cb,
const float lambda,
const float uplim,
110 int *
bits,
int BT_ZERO,
int BT_UNSIGNED,
111 int BT_PAIR,
int BT_ESC)
117 const float CLIPPED_ESCAPE = 165140.0f*IQ;
120 const int dim = BT_PAIR ? 2 : 4;
127 for (i = 0; i <
size; i++)
131 return cost * lambda;
137 quantize_bands(s->qcoefs, in, scaled, size, Q34, !BT_UNSIGNED, maxval);
143 for (i = 0; i <
size; i +=
dim) {
145 int *quants = s->qcoefs +
i;
149 for (j = 0; j <
dim; j++) {
151 curidx += quants[j] +
off;
156 for (j = 0; j <
dim; j++) {
157 float t = fabsf(in[i+j]);
159 if (BT_ESC && vec[j] == 64.0
f) {
160 if (t >= CLIPPED_ESCAPE) {
161 di = t - CLIPPED_ESCAPE;
164 int c = av_clip(
quant(t, Q), 0, 8191);
165 di = t - c*
cbrtf(c)*IQ;
166 curbits +=
av_log2(c)*2 - 4 + 1;
176 for (j = 0; j <
dim; j++) {
177 float di = in[i+j] - vec[j]*IQ;
181 cost += rd * lambda + curbits;
188 for (j = 0; j <
dim; j++)
192 for (j = 0; j < 2; j++) {
194 int coef = av_clip(
quant(fabsf(in[i+j]), Q), 0, 8191);
197 put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);
198 put_bits(pb, len, coef & ((1 << len) - 1));
210 #define QUANTIZE_AND_ENCODE_BAND_COST_FUNC(NAME, BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC) \ 211 static float quantize_and_encode_band_cost_ ## NAME( \ 212 struct AACEncContext *s, \ 213 PutBitContext *pb, const float *in, \ 214 const float *scaled, int size, int scale_idx, \ 215 int cb, const float lambda, const float uplim, \ 217 return quantize_and_encode_band_cost_template( \ 218 s, pb, in, scaled, size, scale_idx, \ 219 BT_ESC ? ESC_BT : cb, lambda, uplim, bits, \ 220 BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC); \ 233 const
float *scaled,
int size,
int scale_idx,
234 int cb, const
float lambda, const
float uplim,
236 quantize_and_encode_band_cost_ZERO,
237 quantize_and_encode_band_cost_SQUAD,
238 quantize_and_encode_band_cost_SQUAD,
239 quantize_and_encode_band_cost_UQUAD,
240 quantize_and_encode_band_cost_UQUAD,
241 quantize_and_encode_band_cost_SPAIR,
242 quantize_and_encode_band_cost_SPAIR,
243 quantize_and_encode_band_cost_UPAIR,
244 quantize_and_encode_band_cost_UPAIR,
245 quantize_and_encode_band_cost_UPAIR,
246 quantize_and_encode_band_cost_UPAIR,
247 quantize_and_encode_band_cost_ESC,
250 #define quantize_and_encode_band_cost( \ 251 s, pb, in, scaled, size, scale_idx, cb, \ 252 lambda, uplim, bits) \ 253 quantize_and_encode_band_cost_arr[cb]( \ 254 s, pb, in, scaled, size, scale_idx, cb, \ 258 const float *scaled,
int size,
int scale_idx,
259 int cb,
const float lambda,
const float uplim,
263 cb, lambda, uplim, bits);
267 const float *
in,
int size,
int scale_idx,
268 int cb,
const float lambda)
274 static float find_max_val(
int group_len,
int swb_size,
const float *scaled) {
277 for (w2 = 0; w2 < group_len; w2++) {
278 for (i = 0; i < swb_size; i++) {
279 maxval =
FFMAX(maxval, scaled[w2*128+i]);
287 float Q34 = sqrtf(Q * sqrtf(Q));
289 qmaxval = maxval * Q34 + 0.4054f;
290 if (qmaxval == 0) cb = 0;
291 else if (qmaxval == 1) cb = 1;
292 else if (qmaxval == 2) cb = 3;
293 else if (qmaxval <= 4) cb = 5;
294 else if (qmaxval <= 7) cb = 7;
295 else if (qmaxval <= 12) cb = 9;
313 int win,
int group_len,
const float lambda)
320 const int run_esc = (1 <<
run_bits) - 1;
321 int idx, ppos,
count;
322 int stackrun[120], stackcb[120], stack_len;
328 for (cb = 0; cb < 12; cb++) {
333 for (swb = 0; swb < max_sfb; swb++) {
335 if (sce->
zeroes[win*16 + swb]) {
336 for (cb = 0; cb < 12; cb++) {
342 float minrd = next_minrd;
343 int mincb = next_mincb;
346 for (cb = 0; cb < 12; cb++) {
347 float cost_stay_here, cost_get_here;
349 for (w = 0; w < group_len; w++) {
352 s->scoefs + start + w*128, size,
353 sce->
sf_idx[(win+w)*16+swb], cb,
356 cost_stay_here = path[swb][
cb].
cost + rd;
357 cost_get_here = minrd + rd + run_bits + 4;
361 if (cost_get_here < cost_stay_here) {
363 path[swb+1][
cb].
cost = cost_get_here;
364 path[swb+1][
cb].
run = 1;
367 path[swb+1][
cb].
cost = cost_stay_here;
370 if (path[swb+1][cb].
cost < next_minrd) {
371 next_minrd = path[swb+1][
cb].
cost;
382 for (cb = 1; cb < 12; cb++)
383 if (path[max_sfb][cb].
cost < path[max_sfb][idx].
cost)
388 stackrun[stack_len] = path[ppos][
cb].
run;
389 stackcb [stack_len] =
cb;
391 ppos -= path[ppos][
cb].
run;
396 for (i = stack_len - 1; i >= 0; i--) {
399 memset(sce->
zeroes + win*16 + start, !stackcb[i], count);
401 for (j = 0; j <
count; j++) {
405 while (count >= run_esc) {
414 int win,
int group_len,
const float lambda)
421 const int run_esc = (1 <<
run_bits) - 1;
422 int idx, ppos,
count;
423 int stackrun[120], stackcb[120], stack_len;
429 for (cb = 0; cb < 12; cb++) {
430 path[0][
cb].
cost = run_bits+4;
434 for (swb = 0; swb < max_sfb; swb++) {
436 if (sce->
zeroes[win*16 + swb]) {
437 float cost_stay_here = path[swb][0].
cost;
438 float cost_get_here = next_minbits + run_bits + 4;
442 if (cost_get_here < cost_stay_here) {
443 path[swb+1][0].
prev_idx = next_mincb;
444 path[swb+1][0].
cost = cost_get_here;
445 path[swb+1][0].
run = 1;
448 path[swb+1][0].
cost = cost_stay_here;
449 path[swb+1][0].
run = path[swb][0].
run + 1;
451 next_minbits = path[swb+1][0].
cost;
453 for (cb = 1; cb < 12; cb++) {
454 path[swb+1][
cb].
cost = 61450;
456 path[swb+1][
cb].
run = 0;
459 float minbits = next_minbits;
460 int mincb = next_mincb;
461 int startcb = sce->
band_type[win*16+swb];
464 for (cb = 0; cb < startcb; cb++) {
465 path[swb+1][
cb].
cost = 61450;
467 path[swb+1][
cb].
run = 0;
469 for (cb = startcb; cb < 12; cb++) {
470 float cost_stay_here, cost_get_here;
472 for (w = 0; w < group_len; w++) {
474 s->scoefs + start + w*128, size,
475 sce->
sf_idx[(win+w)*16+swb], cb,
479 cost_get_here = minbits + bits + run_bits + 4;
483 if (cost_get_here < cost_stay_here) {
485 path[swb+1][
cb].
cost = cost_get_here;
486 path[swb+1][
cb].
run = 1;
489 path[swb+1][
cb].
cost = cost_stay_here;
492 if (path[swb+1][cb].
cost < next_minbits) {
493 next_minbits = path[swb+1][
cb].
cost;
504 for (cb = 1; cb < 12; cb++)
505 if (path[max_sfb][cb].
cost < path[max_sfb][idx].
cost)
511 stackrun[stack_len] = path[ppos][
cb].
run;
512 stackcb [stack_len] =
cb;
514 ppos -= path[ppos][
cb].
run;
519 for (i = stack_len - 1; i >= 0; i--) {
522 memset(sce->
zeroes + win*16 + start, !stackcb[i], count);
524 for (j = 0; j <
count; j++) {
528 while (count >= run_esc) {
551 #define TRELLIS_STAGES 121 552 #define TRELLIS_STATES (SCALE_MAX_DIFF+1) 565 float q0f = FLT_MAX, q1f = 0.0f, qnrgf = 0.0f;
566 int q0, q1, qcnt = 0;
568 for (i = 0; i < 1024; i++) {
569 float t = fabsf(sce->coeffs[i]);
598 }
else if (q1 > q1high) {
605 paths[0][
i].
cost = 0.0f;
606 paths[0][
i].
prev = -1;
611 paths[j][
i].
prev = -2;
619 const float *coefs = sce->coeffs +
start;
623 bandaddr[idx] = w * 16 +
g;
629 sce->
zeroes[(w+w2)*16+g] = 1;
632 sce->
zeroes[(w+w2)*16+g] = 0;
635 float t = fabsf(coefs[w2*128+i]);
637 qmin =
FFMIN(qmin, t);
638 qmax =
FFMAX(qmax, t);
642 int minscale, maxscale;
649 minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1);
650 maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES);
652 for (q = minscale; q < maxscale; q++) {
660 minrd =
FFMIN(minrd, dist);
662 for (i = 0; i < q1 - q0; i++) {
664 cost = paths[idx - 1][
i].
cost + dist
666 if (cost < paths[idx][q].cost) {
668 paths[idx][q].
prev =
i;
673 for (q = 0; q < q1 - q0; q++) {
674 paths[idx][q].
cost = paths[idx - 1][q].
cost + 1;
675 paths[idx][q].
prev = q;
684 mincost = paths[idx][0].
cost;
687 if (paths[idx][i].
cost < mincost) {
688 mincost = paths[idx][
i].
cost;
693 sce->
sf_idx[bandaddr[idx]] = minq + q0;
694 minq = paths[idx][minq].
prev;
714 float dists[128] = { 0 }, uplims[128];
716 int fflag, minscaler;
723 destbits =
FFMIN(destbits, 5800);
734 sce->
zeroes[(w+w2)*16+g] = 1;
739 uplims[w*16+
g] = uplim *512;
742 minthr =
FFMIN(minthr, uplim);
748 if (sce->
zeroes[w*16+g]) {
763 const float *scaled = s->scoefs +
start;
773 minscaler = sce->
sf_idx[0];
775 qstep = its ? 1 : 32;
783 const float *coefs = sce->coeffs +
start;
784 const float *scaled = s->scoefs +
start;
789 if (sce->
zeroes[w*16+g] || sce->
sf_idx[w*16+g] >= 218) {
807 dists[w*16+
g] = dist -
bits;
816 if (tbits > destbits) {
817 for (
i = 0;
i < 128;
i++)
818 if (sce->
sf_idx[
i] < 218 - qstep)
821 for (
i = 0;
i < 128;
i++)
822 if (sce->
sf_idx[
i] > 60 - qstep)
826 if (!qstep && tbits > destbits*1.02 && sce->
sf_idx[0] < 217)
834 int prevsc = sce->
sf_idx[w*16+
g];
835 if (dists[w*16+g] > uplims[w*16+g] && sce->
sf_idx[w*16+g] > 60) {
843 if (sce->
sf_idx[w*16+g] != prevsc)
849 }
while (fflag && its < 10);
857 float uplim[128], maxq[128];
859 float distfact = ((sce->
ics.
num_windows > 1) ? 85.80 : 147.84) / lambda;
860 int last = 0, lastband = 0, curband = 0;
861 float avg_energy = 0.0;
864 for (
i = 0;
i < 1024;
i++) {
869 if (sce->coeffs[
i]) {
870 avg_energy += sce->coeffs[
i] * sce->coeffs[
i];
876 for (w = 0; w < 8; w++) {
877 const float *coeffs = sce->coeffs + w*128;
879 for (
i = 0;
i < 128;
i++) {
885 avg_energy += coeffs[
i] * coeffs[
i];
886 last =
FFMAX(last, i);
887 lastband =
FFMAX(lastband, curband);
894 if (avg_energy == 0.0
f) {
902 float *coefs = sce->coeffs +
start;
905 float maxval = -1, thr = 0.0f,
t;
911 memset(coefs + w2*128, 0,
sizeof(coefs[0])*
size);
916 float t = coefs[w2*128+
i]*coefs[w2*128+
i];
917 maxq[w*16+
g] =
FFMAX(maxq[w*16+g], fabsf(coefs[w2*128 +
i]));
926 start2 =
FFMAX(peakpos - 2, start2);
927 end2 =
FFMIN(peakpos + 3, end2);
933 thr = pow(thr / (avg_energy * (end2 - start2)), 0.3 + 0.1*(lastband - g) / lastband);
934 t = 1.0 - (1.0 * start2 / last);
935 uplim[w*16+
g] = distfact / (1.4 * thr +
t*
t*
t + 0.075);
943 const float *coefs = sce->coeffs +
start;
944 const float *scaled = s->scoefs +
start;
946 int scf, prev_scf,
step;
947 int min_scf = -1, max_scf = 256;
949 if (maxq[w*16+g] < 21.544) {
973 dist *= 1.0f / 512.0f / lambda;
975 if (quant_max >= 8191) {
976 sce->
sf_idx[w*16+
g] = prev_scf;
980 curdiff = fabsf(dist - uplim[w*16+g]);
984 step =
log2f(curdiff);
985 if (dist > uplim[w*16+g])
988 scf = av_clip_uint8(scf);
989 step = scf - prev_scf;
990 if (
FFABS(step) <= 1 || (step > 0 && scf >= max_scf) || (step < 0 && scf <= min_scf)) {
991 sce->
sf_idx[w*16+
g] = av_clip(scf, min_scf, max_scf);
1003 for (
i = 1;
i < 128;
i++) {
1009 if (minq == INT_MAX)
1013 for (
i = 126;
i >= 0;
i--) {
1033 sce->
sf_idx[(w+w2)*16+g] = 218;
1034 sce->
zeroes[(w+w2)*16+g] = 1;
1037 sce->
zeroes[(w+w2)*16+g] = 0;
1043 for (i = 0; i < 128; i++) {
1058 float M[128],
S[128];
1059 float *L34 = s->scoefs, *R34 = s->scoefs + 128, *M34 = s->scoefs + 128*2, *S34 = s->scoefs + 128*3;
1067 float dist1 = 0.0f, dist2 = 0.0f;
1074 M[
i] = (sce0->coeffs[start+w2*128+
i]
1075 + sce1->coeffs[start+w2*128+
i]) * 0.5;
1077 - sce1->coeffs[start+w2*128+
i];
1086 sce0->
sf_idx[(w+w2)*16+g],
1092 sce1->
sf_idx[(w+w2)*16+g],
1098 sce0->
sf_idx[(w+w2)*16+g],
1104 sce1->
sf_idx[(w+w2)*16+g],
1108 cpe->
ms_mask[w*16+
g] = dist2 < dist1;
static const uint8_t run_value_bits_long[64]
bits needed to code codebook run value for long windows
struct TrellisPath TrellisPath
AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB]
#define QUANTIZE_AND_ENCODE_BAND_COST_FUNC(NAME, BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC)
static av_always_inline uint8_t coef2maxsf(float coef)
Return the maximum scalefactor where the quantized coef is not zero.
static void encode_window_bands_info(AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
Encode band info for single window group bands.
#define SCALE_DIFF_ZERO
codebook index corresponding to zero scalefactor indices difference
FFPsyBand psy_bands[PSY_MAX_BANDS]
channel bands information
static const uint8_t run_value_bits_short[16]
bits needed to code codebook run value for short windows
#define SCALE_MAX_POS
scalefactor index maximum value
static int find_min_book(float maxval, int sf)
#define SCALE_MAX_DIFF
maximum scalefactor difference allowed by standard
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
int common_window
Set if channels share a common 'IndividualChannelStream' in bitstream.
#define quantize_and_encode_band_cost(s, pb, in, scaled, size, scale_idx, cb, lambda, uplim, bits)
int prev_idx
pointer to the previous path point
#define FF_ARRAY_ELEMS(a)
uint8_t ms_mask[128]
Set if mid/side stereo is used for each scalefactor window band.
static const uint8_t * run_value_bits[2]
static void search_for_quantizers_fast(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
output residual component w
static void search_for_ms(AACEncContext *s, ChannelElement *cpe, const float lambda)
SingleChannelElement ch[2]
static av_always_inline int quant(float coef, const float Q)
Quantize one coefficient.
const uint8_t ff_aac_scalefactor_bits[121]
static const uint8_t run_bits[7][16]
single band psychoacoustic information
static const uint8_t aac_cb_range[12]
static av_always_inline uint8_t coef2minsf(float coef)
Return the minimum scalefactor where the quantized coef does not clip.
static av_always_inline float quantize_and_encode_band_cost_template(struct AACEncContext *s, PutBitContext *pb, const float *in, 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)
Calculate rate distortion cost for quantizing with given codebook.
uint8_t max_sfb
number of scalefactor bands per group
static void put_bits(J2kEncoderContext *s, int val, int n)
put n times val bit
int num_swb
number of scalefactor window bands
static void quantize_bands(int *out, const float *in, const float *scaled, int size, float Q34, int is_signed, int maxval)
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)
const float *const ff_aac_codebook_vectors[]
#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
static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb, const float *in, int size, int scale_idx, int cb, const float lambda)
int bit_rate
the average bitrate
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
const uint8_t *const ff_aac_spectral_bits[11]
AAC definitions and structures.
static void abs_pow34_v(float *out, const float *in, const int size)
float ff_aac_pow34sf_tab[428]
int sample_rate
samples per second
static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
main external API structure.
IndividualChannelStream ics
static av_always_inline float cbrtf(float x)
structure used in optimal codebook search
Replacements for frequently missing libm functions.
synthesis window for stochastic i
Spectral data are coded with an escape sequence.
const uint8_t * swb_sizes
table of scalefactor band sizes for a particular window
static float(*const quantize_and_encode_band_cost_arr[])(struct AACEncContext *s, PutBitContext *pb, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits)
uint8_t zeroes[128]
band is not coded (used by encoder)
int sf_idx[128]
scalefactor indices (used by encoder)
#define SCALE_ONE_POS
scalefactor index that corresponds to scale=1.0
static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
static void search_for_quantizers_twoloop(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
two-loop quantizers search taken from ISO 13818-7 Appendix C
Single Channel Element - used for both SCE and LFE elements.
static const uint8_t aac_cb_maxval[12]
float ff_aac_pow2sf_tab[428]
static float find_max_val(int group_len, int swb_size, const float *scaled)
channel element - generic struct for SCE/CPE/CCE/LFE
const uint16_t *const ff_aac_spectral_codes[11]
int channels
number of audio channels
FFPsyChannel * ch
single channel information
enum BandType band_type[128]
band types
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;}return ac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
struct BandCodingPath BandCodingPath
structure used in optimal codebook search
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step