28 #ifndef AVCODEC_AACENC_UTILS_H 29 #define AVCODEC_AACENC_UTILS_H 36 #define ROUND_STANDARD 0.4054f 37 #define ROUND_TO_ZERO 0.1054f 38 #define C_QUANT 0.4054f 40 static inline void abs_pow34_v(
float *out,
const float *in,
const int size)
43 for (i = 0; i < size; i++) {
44 float a = fabsf(in[i]);
45 out[i] = sqrtf(a * sqrtf(a));
49 static inline float pos_pow34(
float a)
51 return sqrtf(a * sqrtf(a));
59 static inline int quant(
float coef,
const float Q,
const float rounding)
62 return sqrtf(a * sqrtf(a)) + rounding;
65 static inline void quantize_bands(
int *out,
const float *in,
const float *scaled,
66 int size,
int is_signed,
int maxval,
const float Q34,
70 for (i = 0; i < size; i++) {
71 float qc = scaled[i] * Q34;
72 int tmp = (int)FFMIN(qc + rounding, (
float)maxval);
73 if (is_signed && in[i] < 0.0f) {
80 static inline float find_max_val(
int group_len,
int swb_size,
const float *scaled)
84 for (w2 = 0; w2 < group_len; w2++) {
85 for (i = 0; i < swb_size; i++) {
86 maxval = FFMAX(maxval, scaled[w2*128+i]);
92 static inline int find_min_book(
float maxval,
int sf)
96 qmaxval = maxval * Q34 + C_QUANT;
97 if (qmaxval >= (FF_ARRAY_ELEMS(aac_maxval_cb)))
100 cb = aac_maxval_cb[qmaxval];
104 static inline float find_form_factor(
int group_len,
int swb_size,
float thresh,
105 const float *scaled,
float nzslope) {
106 const float iswb_size = 1.0f / swb_size;
107 const float iswb_sizem1 = 1.0f / (swb_size - 1);
108 const float ethresh = thresh;
109 float form = 0.0f, weight = 0.0f;
111 for (w2 = 0; w2 < group_len; w2++) {
112 float e = 0.0f, e2 = 0.0f, var = 0.0f, maxval = 0.0f;
114 for (i = 0; i < swb_size; i++) {
115 float s = fabsf(scaled[w2*128+i]);
116 maxval = FFMAX(maxval, s);
127 nzl += (s / ethresh) * (s / ethresh);
129 nzl += ff_fast_powf(s / ethresh, nzslope);
137 for (i = 0; i < swb_size; i++) {
138 float d = fabsf(scaled[w2*128+i]) - e;
141 var = sqrtf(var * iswb_sizem1);
144 frm = e / FFMIN(e+4*var,maxval);
145 form += e2 * sqrtf(frm) / FFMAX(0.5f,nzl);
150 return form / weight;
157 static inline uint8_t coef2minsf(
float coef)
163 static inline uint8_t coef2maxsf(
float coef)
171 static inline int quant_array_idx(
const float val,
const float *arr,
const int num)
174 float quant_min_err = INFINITY;
175 for (i = 0; i < num; i++) {
176 float error = (val - arr[i])*(val - arr[i]);
177 if (error < quant_min_err) {
178 quant_min_err = error;
188 static av_always_inline
float bval2bmax(
float b)
190 return 0.001f + 0.0035f * (b*b*b) / (15.5f*15.5f*15.5f);
201 unsigned char prevband = 0;
204 for (g = 0; g < 128; g++)
208 for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
209 for (g = 0; g < sce->ics.
num_swb; g++) {
211 prevband = nextband[prevband] = w*16+g;
214 nextband[prevband] = prevband;
221 static inline void ff_nextband_remove(uint8_t *nextband,
int prevband,
int band)
223 nextband[prevband] = nextband[band];
233 const uint8_t *nextband,
int prev_sf,
int band)
247 const uint8_t *nextband,
int prev_sf,
int new_sf,
int band)
262 static av_always_inline
int lcg_random(
unsigned previous_val)
264 union {
unsigned u;
int s; } v = { previous_val * 1664525u + 1013904223 };
268 #define ERROR_IF(cond, ...) \ 270 av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \ 271 return AVERROR(EINVAL); \ 274 #define WARN_IF(cond, ...) \ 276 av_log(avctx, AV_LOG_WARNING, __VA_ARGS__); \ Band types following are encoded differently from others.
Definition: aac.h:86
#define SCALE_MAX_DIFF
maximum scalefactor difference allowed by standard
Definition: aac.h:151
int num_swb
number of scalefactor window bands
Definition: aac.h:183
#define SCALE_DIV_512
scalefactor difference that corresponds to scale difference in 512 times
Definition: aac.h:148
uint8_t zeroes[128]
band is not coded (used by encoder)
Definition: aac.h:257
int sf_idx[128]
scalefactor indices (used by encoder)
Definition: aac.h:256
#define SCALE_ONE_POS
scalefactor index that corresponds to scale=1.0
Definition: aac.h:149
internal math functions header
Single Channel Element - used for both SCE and LFE elements.
Definition: aac.h:248
enum BandType band_type[128]
band types
Definition: aac.h:252
#define POW_SF2_ZERO
ff_aac_pow2sf_tab index corresponding to pow(2, 0);
Definition: aac.h:154