88 #define WINDOW_FUNC(type) \
89 static void apply_ ##type ##_window(AVFloatDSPContext *fdsp, \
90 SingleChannelElement *sce, \
97 float *
out = sce->ret_buf;
99 fdsp->vector_fmul (out, audio, lwindow, 1024);
100 fdsp->vector_fmul_reverse(out + 1024, audio + 1024, pwindow, 1024);
107 float *
out = sce->ret_buf;
109 fdsp->vector_fmul(out, audio, lwindow, 1024);
110 memcpy(out + 1024, audio + 1024,
sizeof(out[0]) * 448);
111 fdsp->vector_fmul_reverse(out + 1024 + 448, audio + 1024 + 448, swindow, 128);
112 memset(out + 1024 + 576, 0,
sizeof(out[0]) * 448);
119 float *
out = sce->ret_buf;
121 memset(out, 0,
sizeof(out[0]) * 448);
122 fdsp->vector_fmul(out + 448, audio + 448, swindow, 128);
123 memcpy(out + 576, audio + 576,
sizeof(out[0]) * 448);
124 fdsp->vector_fmul_reverse(out + 1024, audio + 1024, lwindow, 1024);
131 const float *
in = audio + 448;
132 float *
out = sce->ret_buf;
135 for (w = 0; w < 8; w++) {
136 fdsp->vector_fmul (out, in, w ? pwindow : swindow, 128);
139 fdsp->vector_fmul_reverse(out, in, swindow, 128);
146 const float *audio) = {
157 const float *output = sce->
ret_buf;
164 for (i = 0; i < 1024; i += 128)
166 memcpy(audio, audio + 1024,
sizeof(audio[0]) * 1024);
186 for (w = 1; w < 8; w++)
214 for (ch = 0; ch < chans; ch++) {
219 for (w2 = 0; w2 < ics->
group_len[w]; w2++) {
220 for (cmaxsfb = ics->
num_swb; cmaxsfb > 0 && cpe->
ch[ch].
zeroes[w*16+cmaxsfb-1]; cmaxsfb--)
222 maxsfb =
FFMAX(maxsfb, cmaxsfb);
229 for (g = 0; g < ics->
max_sfb; g++) {
231 for (w2 = w; w2 < w + ics->
group_len[w]; w2++) {
232 if (!cpe->
ch[ch].
zeroes[w2*16 + g]) {
249 for (i = 0; i < ics0->
max_sfb; i++)
252 if (msc == 0 || ics0->
max_sfb == 0)
266 for (w2 = 0; w2 < ics->
group_len[w]; w2++) {
267 int start = (w+w2) * 128;
268 for (g = 0; g < ics->
num_swb; g++) {
278 float sum = (cpe->
ch[0].
coeffs[start+i] + p*cpe->
ch[1].
coeffs[start+i])*scale;
295 for (w2 = 0; w2 < ics->
group_len[w]; w2++) {
296 int start = (w+w2) * 128;
297 for (g = 0; g < ics->
num_swb; g++) {
310 float R = L - cpe->
ch[1].
coeffs[start+i];
341 int off_is = 0, noise_flag = 1;
346 if (!sce->
zeroes[w*16 + i]) {
348 diff = sce->
sf_idx[w*16 + i] - off_pns;
349 off_pns = sce->
sf_idx[w*16 + i];
350 if (noise_flag-- > 0) {
356 diff = sce->
sf_idx[w*16 + i] - off_is;
357 off_is = sce->
sf_idx[w*16 + i];
359 diff = sce->
sf_idx[w*16 + i] - off_sf;
360 off_sf = sce->
sf_idx[w*16 + i];
399 if (sce->
zeroes[w*16 + i]) {
405 &sce->
coeffs[start + w2*128],
428 float *swb_coeffs = &sce->
coeffs[start + w*128];
445 if (!common_window) {
468 int i, namelen, padbits;
470 namelen = strlen(name) + 2;
478 for (i = 0; i < namelen - 2; i++)
494 for (ch = 0; ch < s->
channels; ch++) {
517 int i, its,
ch, w, chans,
tag, start_ch, ret, frame_bits;
518 int target_bits, rate_bits, too_many_bits, too_few_bits;
519 int ms_mode = 0, is_mode = 0, tns_mode = 0, pred_mode = 0;
520 int chan_el_counter[4];
540 for (i = 0; i < s->
chan_map[0]; i++) {
545 for (ch = 0; ch < chans; ch++) {
547 float clip_avoidance_factor;
552 samples2 = overlap + 1024;
553 la = samples2 + (448+64);
591 clip_avoidance_factor = 0.0f;
593 const float *wbuf = overlap + w * 128;
598 for (j = 0; j < wlen; j++)
599 max =
FFMAX(max, fabsf(wbuf[j]));
605 clip_avoidance_factor =
FFMAX(clip_avoidance_factor, wi[ch].clipping[w]);
624 for (k = 0; k < 1024; k++) {
625 if (!(fabs(cpe->
ch[ch].
coeffs[k]) < 1E16)) {
636 frame_bits = its = 0;
644 memset(chan_el_counter, 0,
sizeof(chan_el_counter));
645 for (i = 0; i < s->
chan_map[0]; i++) {
656 for (ch = 0; ch < chans; ch++) {
664 for (w = 0; w < 128; w++)
678 for (ch = 0; ch < chans; ch++) {
685 && wi[0].window_type[0] == wi[1].window_type[0]
686 && wi[0].window_shape == wi[1].window_shape) {
690 if (wi[0].grouping[w] != wi[1].grouping[w]) {
696 for (ch = 0; ch < chans; ch++) {
716 for (ch = 0; ch < chans; ch++) {
725 for (ch = 0; ch < chans; ch++) {
742 for (ch = 0; ch < chans; ch++) {
765 for (ch = 0; ch < chans; ch++) {
784 too_many_bits =
FFMAX(target_bits, rate_bits);
785 too_many_bits =
FFMIN(too_many_bits, 6144 * s->
channels - 3);
786 too_few_bits =
FFMIN(
FFMAX(rate_bits - rate_bits/4, target_bits), too_many_bits);
789 too_few_bits = too_few_bits - too_few_bits/8;
790 too_many_bits = too_many_bits + too_many_bits/2;
793 || (its < 5 && (frame_bits < too_few_bits || frame_bits > too_many_bits))
794 || frame_bits >= 6144 * s->
channels - 3 )
796 float ratio = ((float)rate_bits) / frame_bits;
798 if (frame_bits >= too_few_bits && frame_bits <= too_many_bits) {
805 ratio = sqrtf(sqrtf(ratio));
806 ratio = av_clipf(ratio, 0.9f, 1.1f);
809 ratio = sqrtf(ratio);
814 if (ratio > 0.9f && ratio < 1.1f) {
817 if (is_mode || ms_mode || tns_mode || pred_mode) {
818 for (i = 0; i < s->
chan_map[0]; i++) {
822 for (ch = 0; ch < chans; ch++)
931 "Unsupported number of channels: %d\n", s->
channels);
934 for (i = 1; i <= s->
chan_map[0]; i++) {
942 for (i = 0; i < 16; i++)
949 "Unsupported sample rate %d\n", avctx->
sample_rate);
953 "Too many bits %f > %d per frame requested, clamping to max\n",
968 "Main prediction unavailable in the \"mpeg2_aac_low\" profile\n");
970 "LTP prediction unavailable in the \"mpeg2_aac_low\" profile\n");
972 "PNS unavailable in the \"mpeg2_aac_low\" profile, turning off\n");
977 "Main prediction unavailable in the \"aac_ltp\" profile\n");
981 "LTP prediction unavailable in the \"aac_main\" profile\n");
985 "Chainging profile to \"aac_ltp\"\n");
987 "Main prediction unavailable in the \"aac_ltp\" profile\n");
991 "Chainging profile to \"aac_main\"\n");
993 "LTP prediction unavailable in the \"aac_main\" profile\n");
1001 "The ANMR coder is considered experimental, add -strict -2 to enable!\n");
1006 "The LPT profile requires experimental compliance, add -strict -2 to enable!\n");
1012 if ((ret =
dsp_init(avctx, s)) < 0)
1024 for (i = 0; i < s->
chan_map[0]; i++)
1053 #define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
1055 {
"aac_coder",
"Coding algorithm", offsetof(
AACEncContext,
options.coder),
AV_OPT_TYPE_INT, {.i64 =
AAC_CODER_TWOLOOP}, 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)
void(* search_for_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
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.
AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB]
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)
enum RawDataBlockType cur_type
channel group type cur_channel belongs to
uint8_t ** bands
scalefactor band sizes for possible frame sizes
void(* mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
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)
void(* encode_ltp_info)(struct AACEncContext *s, SingleChannelElement *sce, int common_window)
av_cold void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx)
Cleanup audio preprocessing module.
#define WARN_IF(cond,...)
const int ff_aac_swb_size_1024_len
AACCoefficientsEncoder * coder
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.
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
void(* search_for_tns)(struct AACEncContext *s, SingleChannelElement *sce)
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
const uint8_t ff_aac_num_swb_128[]
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...
#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.
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...
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 WINDOW_FUNC(type)
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.
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
const uint8_t * ff_aac_swb_size_128[]
Scalefactor data are intensity stereo positions (in phase).
int profile
copied from avctx
const OptionDef options[]
static void adjust_frame_information(ChannelElement *cpe, int chans)
Produce integer coefficients from scalefactors provided by the model.
float * planar_samples[8]
saved preprocessed input
static const AVOption aacenc_options[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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.
float ff_aac_kbd_long_1024[1024]
int flags
AV_CODEC_FLAG_*.
static const int mpeg4audio_sample_rates[16]
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
void(* set_special_band_scalefactors)(struct AACEncContext *s, SingleChannelElement *sce)
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(* search_for_quantizers)(AVCodecContext *avctx, struct AACEncContext *s, SingleChannelElement *sce, const float lambda)
static int put_bits_count(PutBitContext *s)
INTFLOAT ret_buf[2048]
PCM output buffer.
void(* search_for_is)(struct AACEncContext *s, AVCodecContext *avctx, ChannelElement *cpe)
void(* abs_pow34)(float *out, const float *in, const int size)
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(* apply_tns_filt)(struct AACEncContext *s, SingleChannelElement *sce)
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...
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
#define FF_PROFILE_AAC_LOW
static const AVCodecDefault aac_encode_defaults[]
#define FF_PROFILE_UNKNOWN
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)
int channels
channel count
void(* encode_main_pred)(struct AACEncContext *s, SingleChannelElement *sce)
AAC definitions and structures.
void(* search_for_ltp)(struct AACEncContext *s, SingleChannelElement *sce, int common_window)
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)
void(* search_for_pred)(struct AACEncContext *s, SingleChannelElement *sce)
#define FF_ARRAY_ELEMS(a)
void(* adjust_common_pred)(struct AACEncContext *s, ChannelElement *cpe)
static av_cold int aac_encode_end(AVCodecContext *avctx)
void ff_aac_dsp_init_x86(AACEncContext *s)
int frame_size
Number of samples per channel in an audio frame.
#define AV_LOG_INFO
Standard information.
#define CLIP_AVOIDANCE_FACTOR
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
void(* search_for_ms)(struct AACEncContext *s, ChannelElement *cpe)
static void put_audio_specific_config(AVCodecContext *avctx)
Make AAC audio config object.
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.
FFPsyWindowInfo(* window)(FFPsyContext *ctx, const float *audio, const float *la, int channel, int prev_type)
Suggest window sequence for channel.
void(* apply_main_pred)(struct AACEncContext *s, SingleChannelElement *sce)
main external API structure.
int bits
number of bits used in the bitresevoir
#define NOISE_PRE_BITS
length of preamble
Levinson-Durbin recursion.
IndividualChannelStream ics
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
void(* encode_window_bands_info)(struct AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
void(* mark_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
Replacements for frequently missing libm functions.
float lambda_sum
sum(lambda), for Qvg reporting
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
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
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
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 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
void(* encode_tns_info)(struct AACEncContext *s, SingleChannelElement *sce)
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)
struct FFPsyContext::@104 bitres
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]
struct AACEncContext::@40 buffer
Scalefactor data are intensity stereo positions (out of phase).
Y Spectral Band Replication.
uint8_t prediction_used[41]
static av_cold int aac_encode_init(AVCodecContext *avctx)
common internal api header.
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[]
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.
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.
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_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),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){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) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;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)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&1) 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);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
void(* ltp_insert_new_frame)(struct AACEncContext *s)
#define ERROR_IF(cond,...)
static void ff_aac_tableinit(void)
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
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.
static void apply_mid_side_stereo(ChannelElement *cpe)
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
enum BandType band_type[128]
band types
static enum AVSampleFormat sample_fmts[]
int frame_number
Frame counter, set by libavcodec.
static int encode_individual_channel(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, int common_window)
Encode one channel of audio data.
void(* adjust_common_ltp)(struct AACEncContext *s, ChannelElement *cpe)
static const AVCodecDefault defaults[]
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[]
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)
void(* update_ltp)(struct AACEncContext *s, SingleChannelElement *sce)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)
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