77 for (i = 0; i < 4; i++) {
78 for (j = 0; j < pce->
num_ele[i]; j++) {
99 const int max_size = 32;
135 #define WINDOW_FUNC(type) \ 136 static void apply_ ##type ##_window(AVFloatDSPContext *fdsp, \ 137 SingleChannelElement *sce, \ 144 float *
out = sce->ret_buf;
146 fdsp->vector_fmul (out, audio, lwindow, 1024);
147 fdsp->vector_fmul_reverse(out + 1024, audio + 1024, pwindow, 1024);
154 float *
out = sce->ret_buf;
156 fdsp->vector_fmul(out, audio, lwindow, 1024);
157 memcpy(out + 1024, audio + 1024,
sizeof(out[0]) * 448);
158 fdsp->vector_fmul_reverse(out + 1024 + 448, audio + 1024 + 448, swindow, 128);
159 memset(out + 1024 + 576, 0,
sizeof(out[0]) * 448);
166 float *
out = sce->ret_buf;
168 memset(out, 0,
sizeof(out[0]) * 448);
169 fdsp->vector_fmul(out + 448, audio + 448, swindow, 128);
170 memcpy(out + 576, audio + 576,
sizeof(out[0]) * 448);
171 fdsp->vector_fmul_reverse(out + 1024, audio + 1024, lwindow, 1024);
178 const float *
in = audio + 448;
179 float *
out = sce->ret_buf;
182 for (w = 0; w < 8; w++) {
183 fdsp->vector_fmul (out, in, w ? pwindow : swindow, 128);
186 fdsp->vector_fmul_reverse(out, in, swindow, 128);
193 const float *audio) = {
204 const float *output = sce->
ret_buf;
211 for (i = 0; i < 1024; i += 128)
213 memcpy(audio, audio + 1024,
sizeof(audio[0]) * 1024);
233 for (w = 1; w < 8; w++)
261 for (ch = 0; ch < chans; ch++) {
267 for (cmaxsfb = ics->
num_swb; cmaxsfb > 0 && cpe->
ch[ch].
zeroes[w*16+cmaxsfb-1]; cmaxsfb--)
269 maxsfb =
FFMAX(maxsfb, cmaxsfb);
276 for (g = 0; g < ics->
max_sfb; g++) {
278 for (w2 = w; w2 < w + ics->
group_len[
w]; w2++) {
279 if (!cpe->
ch[ch].
zeroes[w2*16 + g]) {
296 for (i = 0; i < ics0->
max_sfb; i++)
299 if (msc == 0 || ics0->
max_sfb == 0)
314 int start = (w+w2) * 128;
315 for (g = 0; g < ics->
num_swb; g++) {
325 float sum = (cpe->
ch[0].
coeffs[start+i] + p*cpe->
ch[1].
coeffs[start+i])*scale;
343 int start = (w+w2) * 128;
344 for (g = 0; g < ics->
num_swb; g++) {
357 float R = L - cpe->
ch[1].
coeffs[start+i];
388 int off_is = 0, noise_flag = 1;
393 if (!sce->
zeroes[w*16 + i]) {
395 diff = sce->
sf_idx[w*16 + i] - off_pns;
396 off_pns = sce->
sf_idx[w*16 + i];
397 if (noise_flag-- > 0) {
403 diff = sce->
sf_idx[w*16 + i] - off_is;
404 off_is = sce->
sf_idx[w*16 + i];
406 diff = sce->
sf_idx[w*16 + i] - off_sf;
407 off_sf = sce->
sf_idx[w*16 + i];
446 if (sce->
zeroes[w*16 + i]) {
452 &sce->
coeffs[start + w2*128],
475 float *swb_coeffs = &sce->
coeffs[start + w*128];
492 if (!common_window) {
515 int i, namelen, padbits;
517 namelen = strlen(name) + 2;
525 for (i = 0; i < namelen - 2; i++)
541 for (ch = 0; ch < s->
channels; ch++) {
564 int i, its,
ch,
w, chans,
tag, start_ch, ret, frame_bits;
565 int target_bits, rate_bits, too_many_bits, too_few_bits;
566 int ms_mode = 0, is_mode = 0, tns_mode = 0, pred_mode = 0;
567 int chan_el_counter[4];
587 for (i = 0; i < s->
chan_map[0]; i++) {
592 for (ch = 0; ch < chans; ch++) {
594 float clip_avoidance_factor;
599 samples2 = overlap + 1024;
600 la = samples2 + (448+64);
638 clip_avoidance_factor = 0.0f;
640 const float *wbuf = overlap + w * 128;
645 for (j = 0; j < wlen; j++)
646 max =
FFMAX(max, fabsf(wbuf[j]));
652 clip_avoidance_factor =
FFMAX(clip_avoidance_factor, wi[ch].clipping[w]);
671 for (k = 0; k < 1024; k++) {
672 if (!(fabs(cpe->
ch[ch].
coeffs[k]) < 1E16)) {
683 frame_bits = its = 0;
691 memset(chan_el_counter, 0,
sizeof(chan_el_counter));
692 for (i = 0; i < s->
chan_map[0]; i++) {
703 for (ch = 0; ch < chans; ch++) {
711 for (w = 0; w < 128; w++)
725 for (ch = 0; ch < chans; ch++) {
732 && wi[0].window_type[0] == wi[1].window_type[0]
733 && wi[0].window_shape == wi[1].window_shape) {
737 if (wi[0].grouping[w] != wi[1].grouping[w]) {
743 for (ch = 0; ch < chans; ch++) {
763 for (ch = 0; ch < chans; ch++) {
772 for (ch = 0; ch < chans; ch++) {
789 for (ch = 0; ch < chans; ch++) {
812 for (ch = 0; ch < chans; ch++) {
831 too_many_bits =
FFMAX(target_bits, rate_bits);
832 too_many_bits =
FFMIN(too_many_bits, 6144 * s->
channels - 3);
833 too_few_bits =
FFMIN(
FFMAX(rate_bits - rate_bits/4, target_bits), too_many_bits);
836 too_few_bits = too_few_bits - too_few_bits/8;
837 too_many_bits = too_many_bits + too_many_bits/2;
840 || (its < 5 && (frame_bits < too_few_bits || frame_bits > too_many_bits))
841 || frame_bits >= 6144 * s->
channels - 3 )
843 float ratio = ((float)rate_bits) / frame_bits;
845 if (frame_bits >= too_few_bits && frame_bits <= too_many_bits) {
852 ratio = sqrtf(sqrtf(ratio));
853 ratio = av_clipf(ratio, 0.9f, 1.1f);
856 ratio = sqrtf(ratio);
861 if (ratio > 0.9f && ratio < 1.1f) {
864 if (is_mode || ms_mode || tns_mode || pred_mode) {
865 for (i = 0; i < s->
chan_map[0]; i++) {
869 for (ch = 0; ch < chans; ch++)
999 for (i = 1; i <= s->
chan_map[0]; i++) {
1007 for (i = 0; i < 16; i++)
1014 "Unsupported sample rate %d\n", avctx->
sample_rate);
1018 "Too many bits %f > %d per frame requested, clamping to max\n",
1033 "Main prediction unavailable in the \"mpeg2_aac_low\" profile\n");
1035 "LTP prediction unavailable in the \"mpeg2_aac_low\" profile\n");
1037 "PNS unavailable in the \"mpeg2_aac_low\" profile, turning off\n");
1042 "Main prediction unavailable in the \"aac_ltp\" profile\n");
1046 "LTP prediction unavailable in the \"aac_main\" profile\n");
1050 "Chainging profile to \"aac_ltp\"\n");
1052 "Main prediction unavailable in the \"aac_ltp\" profile\n");
1056 "Chainging profile to \"aac_main\"\n");
1058 "LTP prediction unavailable in the \"aac_main\" profile\n");
1066 "The ANMR coder is considered experimental, add -strict -2 to enable!\n");
1071 "The LPT profile requires experimental compliance, add -strict -2 to enable!\n");
1077 if ((ret =
dsp_init(avctx, s)) < 0)
1090 for (i = 0; i < s->
chan_map[0]; i++)
1119 #define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM 1121 {
"aac_coder",
"Coding algorithm", offsetof(
AACEncContext,
options.coder),
AV_OPT_TYPE_INT, {.i64 =
AAC_CODER_FAST}, 0,
AAC_CODER_NB-1,
AACENC_FLAGS,
"coder"},
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int64_t *duration)
Remove frame(s) from the queue.
void ff_quantize_band_cost_cache_init(struct AACEncContext *s)
const AACCoefficientsEncoder * coder
Band types following are encoded differently from others.
static const uint8_t aac_chan_configs[AAC_MAX_CHANNELS][6]
default channel configurations
uint8_t use_kb_window[2]
If set, use Kaiser-Bessel window, otherwise use a sine window.
This structure describes decoded (raw) audio or video data.
#define FF_ALLOCZ_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)
int grouping[8]
window grouping (for e.g. AAC)
void(* search_for_ms)(struct AACEncContext *s, ChannelElement *cpe)
enum RawDataBlockType cur_type
channel group type cur_channel belongs to
uint8_t ** bands
scalefactor band sizes for possible frame sizes
AACQuantizeBandCostCacheEntry quantize_band_cost_cache[256][128]
memoization area for quantize_band_cost
static void abs_pow34_v(float *out, const float *in, const int size)
static const AVClass aacenc_class
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
av_cold void ff_kbd_window_init(float *window, float alpha, int n)
Generate a Kaiser-Bessel Derived Window.
int64_t bit_rate
the average bitrate
#define LIBAVUTIL_VERSION_INT
#define SCALE_DIFF_ZERO
codebook index corresponding to zero scalefactor indices difference
uint8_t window_clipping[8]
set if a certain window is near clipping
static av_cold int init(AVCodecContext *avctx)
av_cold void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx)
Cleanup audio preprocessing module.
#define WARN_IF(cond,...)
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&HAVE_MMX) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
const char * av_default_item_name(void *ptr)
Return the context name.
const int ff_aac_swb_size_1024_len
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
static void put_ics_info(AACEncContext *s, IndividualChannelStream *info)
Encode ics_info element.
void(* search_for_tns)(struct AACEncContext *s, SingleChannelElement *sce)
int common_window
Set if channels share a common 'IndividualChannelStream' in bitstream.
int alloc
number of bits allocated by the psy, or -1 if no allocation was done
const uint8_t * ff_aac_swb_size_1024[]
#define FF_PROFILE_AAC_MAIN
int lambda_count
count(lambda), for Qvg reporting
av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens, const uint8_t **bands, const int *num_bands, int num_groups, const uint8_t *group_map)
Initialize psychoacoustic model.
uint8_t ms_mask[128]
Set if mid/side stereo is used for each scalefactor window band.
#define NOISE_PRE
preamble for NOISE_BT, put in bitstream with the first noise band
static void encode_spectral_coeffs(AACEncContext *s, SingleChannelElement *sce)
Encode spectral coefficients processed by psychoacoustic model.
Spectral data are scaled white noise not coded in the bitstream.
int * num_bands
number of scalefactor bands for possible frame sizes
static AVOnce aac_table_init
static int put_audio_specific_config(AVCodecContext *avctx)
Make AAC audio config object.
void(* apply_tns_filt)(struct AACEncContext *s, SingleChannelElement *sce)
const uint8_t ff_aac_num_swb_128[]
void(* search_for_quantizers)(AVCodecContext *avctx, struct AACEncContext *s, SingleChannelElement *sce, const float lambda)
INTFLOAT pcoeffs[1024]
coefficients for IMDCT, pristine
const uint16_t * swb_offset
table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular wind...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
AACEncOptions options
encoding options
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
int num_ele[4]
front, side, back, lfe
void(* search_for_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
#define WINDOW_FUNC(type)
void(* update_ltp)(struct AACEncContext *s, SingleChannelElement *sce)
LPCContext lpc
used by TNS
void ff_aac_coder_init_mips(AACEncContext *c)
SingleChannelElement ch[2]
int samplerate_index
MPEG-4 samplerate index.
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
static av_cold int end(AVCodecContext *avctx)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
const uint8_t * chan_map
channel configuration map
const uint8_t ff_aac_scalefactor_bits[121]
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
const AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB]
static const uint8_t aac_chan_maps[AAC_MAX_CHANNELS][AAC_MAX_CHANNELS]
Table to remap channels from libavcodec's default order to AAC order.
#define FF_PROFILE_AAC_LTP
static void put_pce(PutBitContext *pb, AVCodecContext *avctx)
const uint8_t * ff_aac_swb_size_128[]
Scalefactor data are intensity stereo positions (in phase).
int profile
copied from avctx
uint8_t reorder_map[16]
maps channels from lavc to aac order
static void adjust_frame_information(ChannelElement *cpe, int chans)
Produce integer coefficients from scalefactors provided by the model.
static const AVOption aacenc_options[]
const uint8_t * reorder_map
lavc to aac reorder map
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
void(* encode_ltp_info)(struct AACEncContext *s, SingleChannelElement *sce, int common_window)
static const int sizes[][2]
const uint8_t ff_aac_num_swb_1024[]
#define FF_PROFILE_MPEG2_AAC_LOW
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
float is_ener[128]
Intensity stereo pos (used by encoder)
int initial_padding
Audio only.
static const AACPCEInfo aac_pce_configs[]
List of PCE (Program Configuration Element) for the channel layouts listed in channel_layout.h.
float ff_aac_kbd_long_1024[1024]
int flags
AV_CODEC_FLAG_*.
void(* mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
static const int mpeg4audio_sample_rates[16]
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation.
int num_windows
number of windows in a frame
static void copy_input_samples(AACEncContext *s, const AVFrame *frame)
uint8_t max_sfb
number of scalefactor bands per group
static const AVCodecDefault defaults[]
void(* adjust_common_ltp)(struct AACEncContext *s, ChannelElement *cpe)
int num_swb
number of scalefactor window bands
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
void(* mark_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
int index[4][8]
front, side, back, lfe
uint64_t channel_layout
Audio channel layout.
static int put_bits_count(PutBitContext *s)
INTFLOAT ret_buf[2048]
PCM output buffer.
void(* set_special_band_scalefactors)(struct AACEncContext *s, SingleChannelElement *sce)
enum WindowSequence window_sequence[2]
INTFLOAT ltp_state[3072]
time signal for LTP
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
av_cold void ff_lpc_end(LPCContext *s)
Uninitialize LPCContext.
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
int cur_channel
current channel for coder context
int last_frame_pb_count
number of bits for the previous frame
static void apply_intensity_stereo(ChannelElement *cpe)
static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
void(* quant_bands)(int *out, const float *in, const float *scaled, int size, int is_signed, int maxval, const float Q34, const float rounding)
#define FF_PROFILE_AAC_LOW
static const AVCodecDefault aac_encode_defaults[]
#define FF_PROFILE_UNKNOWN
int channels
channel count
AAC definitions and structures.
const uint8_t ff_tns_max_bands_1024[]
static void quantize_bands(int *out, const float *in, const float *scaled, int size, int is_signed, int maxval, const float Q34, const float rounding)
FFTContext mdct128
short (128 samples) frame transform context
static void(*const apply_window[4])(AVFloatDSPContext *fdsp, SingleChannelElement *sce, const float *audio)
#define FF_ARRAY_ELEMS(a)
static av_cold int aac_encode_end(AVCodecContext *avctx)
void(* search_for_is)(struct AACEncContext *s, AVCodecContext *avctx, ChannelElement *cpe)
void ff_aac_dsp_init_x86(AACEncContext *s)
int frame_size
Number of samples per channel in an audio frame.
void(* search_for_ltp)(struct AACEncContext *s, SingleChannelElement *sce, int common_window)
#define AV_LOG_INFO
Standard information.
#define CLIP_AVOIDANCE_FACTOR
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
struct FFPsyContext::@106 bitres
typedef void(RENAME(mix_any_func_type))
int sample_rate
samples per second
float ff_aac_kbd_short_128[128]
static void encode_ms_info(PutBitContext *pb, ChannelElement *cpe)
Encode MS data.
void(* ltp_insert_new_frame)(struct AACEncContext *s)
void(* search_for_pred)(struct AACEncContext *s, SingleChannelElement *sce)
main external API structure.
int pairing[3][8]
front, side, back
int bits
number of bits used in the bitresevoir
#define NOISE_PRE_BITS
length of preamble
Levinson-Durbin recursion.
void(* apply_main_pred)(struct AACEncContext *s, SingleChannelElement *sce)
IndividualChannelStream ics
Replacements for frequently missing libm functions.
float lambda_sum
sum(lambda), for Qvg reporting
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=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;} 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_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);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_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
static void put_bitstream_info(AACEncContext *s, const char *name)
Write some auxiliary information about the created AAC file.
const int ff_aac_swb_size_128_len
void(* encode_main_pred)(struct AACEncContext *s, SingleChannelElement *sce)
void(* adjust_common_pred)(struct AACEncContext *s, ChannelElement *cpe)
int window_shape
window shape (sine/KBD/whatever)
static void encode_pulses(AACEncContext *s, Pulse *pulse)
Encode pulse data.
uint16_t quantize_band_cost_cache_generation
static av_cold void aac_encode_init_tables(void)
const uint8_t * swb_sizes
table of scalefactor band sizes for a particular window
const uint32_t ff_aac_scalefactor_code[121]
static av_cold int alloc_buffers(AVCodecContext *avctx, AACEncContext *s)
const struct FFPsyModel * model
encoder-specific model functions
av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order, enum FFLPCType lpc_type)
Initialize LPCContext.
int needs_pce
flag for non-standard layout
struct AACEncContext::@28 buffer
FFPsyWindowInfo(* window)(FFPsyContext *ctx, const float *audio, const float *la, int channel, int prev_type)
Suggest window sequence for channel.
int ms_mode
Signals mid/side stereo flags coding mode (used by encoder)
const uint8_t ff_tns_max_bands_128[]
struct FFPsyPreprocessContext * psypp
#define NOISE_OFFSET
subtracted from global gain, used as offset for the preamble
int global_quality
Global quality for codecs which cannot change it per frame.
uint8_t zeroes[128]
band is not coded (used by encoder)
int sf_idx[128]
scalefactor indices (used by encoder)
uint8_t is_mode
Set if any bands have been encoded using intensity stereo (used by encoder)
INTFLOAT coeffs[1024]
coefficients for IMDCT, maybe processed
const int avpriv_mpeg4audio_sample_rates[16]
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)
Scalefactor data are intensity stereo positions (out of phase).
Y Spectral Band Replication.
const OptionDef options[]
uint8_t prediction_used[41]
static av_cold int aac_encode_init(AVCodecContext *avctx)
common internal api header.
AACPCEInfo pce
PCE data, if needed.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Single Channel Element - used for both SCE and LFE elements.
windowing related information
av_cold struct FFPsyPreprocessContext * ff_psy_preprocess_init(AVCodecContext *avctx)
psychoacoustic model audio preprocessing initialization
const uint16_t *const ff_swb_offset_1024[]
uint8_t config_map[16]
configs the encoder's channel specific settings
void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int channels)
Preprocess several channel in audio frame in order to compress it better.
static void encode_scale_factors(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce)
Encode scalefactors.
float * planar_samples[16]
saved preprocessed input
ChannelElement * cpe
channel elements
Individual Channel Stream.
float clip_avoidance_factor
set if any window is near clipping to the necessary atennuation factor to avoid it ...
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define ERROR_IF(cond,...)
static void ff_aac_tableinit(void)
channel element - generic struct for SCE/CPE/CCE/LFE
FFTContext mdct1024
long (1024 samples) frame transform context
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static const int16_t coeffs[]
int channels
number of audio channels
AAC_FLOAT lcoeffs[1024]
MDCT of LTP coefficients (used by encoder)
static int ff_thread_once(char *control, void(*routine)(void))
static void encode_band_info(AACEncContext *s, SingleChannelElement *sce)
Encode scalefactor band coding type.
void(* analyze)(FFPsyContext *ctx, int channel, const float **coeffs, const FFPsyWindowInfo *wi)
Perform psychoacoustic analysis and set band info (threshold, energy) for a group of channels...
static void apply_mid_side_stereo(ChannelElement *cpe)
static const int64_t aac_normal_chan_layouts[7]
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
enum BandType band_type[128]
band types
void avpriv_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
static enum AVSampleFormat sample_fmts[]
int frame_number
Frame counter, set by libavcodec.
void(* encode_tns_info)(struct AACEncContext *s, SingleChannelElement *sce)
static int encode_individual_channel(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, int common_window)
Encode one channel of audio data.
int8_t used[MAX_LTP_LONG_SFB]
static void apply_window_and_mdct(AACEncContext *s, SingleChannelElement *sce, float *audio)
const uint16_t *const ff_swb_offset_128[]
uint8_t is_mask[128]
Set if intensity stereo is used (used by encoder)
static const int aacenc_profiles[]
void(* abs_pow34)(float *out, const float *in, const int size)
uint8_t ** extended_data
pointers to the data planes/channels.
av_cold void ff_psy_end(FFPsyContext *ctx)
Cleanup model context at the end.
This structure stores compressed data.
static void avoid_clipping(AACEncContext *s, SingleChannelElement *sce)
Downscale spectral coefficients for near-clipping windows to avoid artifacts.
int window_type[3]
window type (short/long/transitional, etc.) - current, previous and next
int nb_samples
number of audio samples (per channel) described by this frame
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
static av_cold int dsp_init(AVCodecContext *avctx, AACEncContext *s)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void AAC_RENAME() ff_init_ff_sine_windows(int index)
initialize the specified entry of ff_sine_windows
float clipping[8]
maximum absolute normalized intensity in the given window for clip avoidance
void(* encode_window_bands_info)(struct AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)