Go to the documentation of this file.
75 for (
i = 0;
i < 4;
i++) {
76 for (j = 0; j < pce->
num_ele[
i]; j++) {
96 int channels = (!
s->needs_pce)*(
s->channels - (
s->channels == 8 ? 1 : 0));
97 const int max_size = 32;
126 ++
s->quantize_band_cost_cache_generation;
127 if (
s->quantize_band_cost_cache_generation == 0) {
128 memset(
s->quantize_band_cost_cache, 0,
sizeof(
s->quantize_band_cost_cache));
129 s->quantize_band_cost_cache_generation = 1;
133 #define WINDOW_FUNC(type) \
134 static void apply_ ##type ##_window(AVFloatDSPContext *fdsp, \
135 SingleChannelElement *sce, \
142 float *
out = sce->ret_buf;
144 fdsp->vector_fmul (
out, audio, lwindow, 1024);
145 fdsp->vector_fmul_reverse(
out + 1024, audio + 1024, pwindow, 1024);
152 float *
out = sce->ret_buf;
154 fdsp->vector_fmul(
out, audio, lwindow, 1024);
155 memcpy(
out + 1024, audio + 1024,
sizeof(
out[0]) * 448);
156 fdsp->vector_fmul_reverse(
out + 1024 + 448, audio + 1024 + 448, swindow, 128);
157 memset(
out + 1024 + 576, 0,
sizeof(
out[0]) * 448);
164 float *
out = sce->ret_buf;
166 memset(
out, 0,
sizeof(
out[0]) * 448);
167 fdsp->vector_fmul(
out + 448, audio + 448, swindow, 128);
168 memcpy(
out + 576, audio + 576,
sizeof(
out[0]) * 448);
169 fdsp->vector_fmul_reverse(
out + 1024, audio + 1024, lwindow, 1024);
176 const float *
in = audio + 448;
177 float *
out = sce->ret_buf;
180 for (
w = 0;
w < 8;
w++) {
181 fdsp->vector_fmul (
out,
in,
w ? pwindow : swindow, 128);
184 fdsp->vector_fmul_reverse(
out,
in, swindow, 128);
191 const float *audio) = {
209 for (
i = 0;
i < 1024;
i += 128)
211 memcpy(audio, audio + 1024,
sizeof(audio[0]) * 1024);
231 for (
w = 1;
w < 8;
w++)
259 for (ch = 0; ch < chans; ch++) {
265 for (cmaxsfb = ics->
num_swb; cmaxsfb > 0 && cpe->
ch[ch].
zeroes[
w*16+cmaxsfb-1]; cmaxsfb--)
267 maxsfb =
FFMAX(maxsfb, cmaxsfb);
297 if (msc == 0 || ics0->
max_sfb == 0)
312 int start = (
w+w2) * 128;
341 int start = (
w+w2) * 128;
372 if (
s->coder->set_special_band_scalefactors)
373 s->coder->set_special_band_scalefactors(
s, sce);
386 int off_is = 0, noise_flag = 1;
395 if (noise_flag-- > 0) {
449 s->coder->quantize_and_encode_band(
s, &
s->pb,
450 &sce->
coeffs[start + w2*128],
473 float *swb_coeffs = &sce->
coeffs[start +
w*128];
490 if (!common_window) {
492 if (
s->coder->encode_main_pred)
493 s->coder->encode_main_pred(
s, sce);
494 if (
s->coder->encode_ltp_info)
495 s->coder->encode_ltp_info(
s, sce, 0);
501 if (
s->coder->encode_tns_info)
502 s->coder->encode_tns_info(
s, sce);
513 int i, namelen, padbits;
515 namelen = strlen(
name) + 2;
523 for (
i = 0;
i < namelen - 2;
i++)
535 int end = 2048 + (
frame ?
frame->nb_samples : 0);
536 const uint8_t *channel_map =
s->reorder_map;
539 for (ch = 0; ch <
s->channels; ch++) {
541 memcpy(&
s->planar_samples[ch][1024], &
s->planar_samples[ch][2048], 1024 *
sizeof(
s->planar_samples[0][0]));
545 memcpy(&
s->planar_samples[ch][2048],
546 frame->extended_data[channel_map[ch]],
547 frame->nb_samples *
sizeof(
s->planar_samples[0][0]));
549 memset(&
s->planar_samples[ch][end], 0,
550 (3072 - end) *
sizeof(
s->planar_samples[0][0]));
558 float **
samples =
s->planar_samples, *samples2, *la, *overlap;
562 int i, its, ch,
w, chans,
tag, start_ch,
ret, frame_bits;
563 int target_bits, rate_bits, too_many_bits, too_few_bits;
564 int ms_mode = 0, is_mode = 0, tns_mode = 0, pred_mode = 0;
565 int chan_el_counter[4];
573 if (!
s->afq.remaining_samples || (!
s->afq.frame_alloc && !
s->afq.frame_count))
585 for (
i = 0;
i <
s->chan_map[0];
i++) {
587 tag =
s->chan_map[
i+1];
590 for (ch = 0; ch < chans; ch++) {
592 float clip_avoidance_factor;
595 s->cur_channel = start_ch + ch;
596 overlap = &
samples[
s->cur_channel][0];
597 samples2 = overlap + 1024;
598 la = samples2 + (448+64);
612 ics->
num_swb =
s->samplerate_index >= 8 ? 1 : 3;
614 wi[ch] =
s->psy.model->window(&
s->psy, samples2, la,
s->cur_channel,
636 clip_avoidance_factor = 0.0f;
638 const float *wbuf = overlap +
w * 128;
643 for (j = 0; j < wlen; j++)
650 clip_avoidance_factor =
FFMAX(clip_avoidance_factor, wi[ch].clipping[
w]);
663 if (
s->options.ltp &&
s->coder->update_ltp) {
664 s->coder->update_ltp(
s, sce);
669 for (k = 0; k < 1024; k++) {
681 frame_bits = its = 0;
689 memset(chan_el_counter, 0,
sizeof(chan_el_counter));
690 for (
i = 0;
i <
s->chan_map[0];
i++) {
692 const float *coeffs[2];
693 tag =
s->chan_map[
i+1];
701 for (ch = 0; ch < chans; ch++) {
709 for (
w = 0;
w < 128;
w++)
713 s->psy.bitres.alloc = -1;
714 s->psy.bitres.bits =
s->last_frame_pb_count /
s->channels;
715 s->psy.model->analyze(&
s->psy, start_ch, coeffs, wi);
716 if (
s->psy.bitres.alloc > 0) {
718 target_bits +=
s->psy.bitres.alloc
720 s->psy.bitres.alloc /= chans;
723 for (ch = 0; ch < chans; ch++) {
724 s->cur_channel = start_ch + ch;
725 if (
s->options.pns &&
s->coder->mark_pns)
726 s->coder->mark_pns(
s, avctx, &cpe->
ch[ch]);
727 s->coder->search_for_quantizers(avctx,
s, &cpe->
ch[ch],
s->lambda);
730 && wi[0].window_type[0] == wi[1].window_type[0]
731 && wi[0].window_shape == wi[1].window_shape) {
735 if (wi[0].grouping[
w] != wi[1].grouping[
w]) {
741 for (ch = 0; ch < chans; ch++) {
743 s->cur_channel = start_ch + ch;
744 if (
s->options.tns &&
s->coder->search_for_tns)
745 s->coder->search_for_tns(
s, sce);
746 if (
s->options.tns &&
s->coder->apply_tns_filt)
747 s->coder->apply_tns_filt(
s, sce);
750 if (
s->options.pns &&
s->coder->search_for_pns)
751 s->coder->search_for_pns(
s, avctx, sce);
753 s->cur_channel = start_ch;
754 if (
s->options.intensity_stereo) {
755 if (
s->coder->search_for_is)
756 s->coder->search_for_is(
s, avctx, cpe);
760 if (
s->options.pred) {
761 for (ch = 0; ch < chans; ch++) {
763 s->cur_channel = start_ch + ch;
764 if (
s->options.pred &&
s->coder->search_for_pred)
765 s->coder->search_for_pred(
s, sce);
768 if (
s->coder->adjust_common_pred)
769 s->coder->adjust_common_pred(
s, cpe);
770 for (ch = 0; ch < chans; ch++) {
772 s->cur_channel = start_ch + ch;
773 if (
s->options.pred &&
s->coder->apply_main_pred)
774 s->coder->apply_main_pred(
s, sce);
776 s->cur_channel = start_ch;
778 if (
s->options.mid_side) {
779 if (
s->options.mid_side == -1 &&
s->coder->search_for_ms)
780 s->coder->search_for_ms(
s, cpe);
786 if (
s->options.ltp) {
787 for (ch = 0; ch < chans; ch++) {
789 s->cur_channel = start_ch + ch;
790 if (
s->coder->search_for_ltp)
794 s->cur_channel = start_ch;
795 if (
s->coder->adjust_common_ltp)
796 s->coder->adjust_common_ltp(
s, cpe);
802 if (
s->coder->encode_main_pred)
803 s->coder->encode_main_pred(
s, &cpe->
ch[0]);
804 if (
s->coder->encode_ltp_info)
805 s->coder->encode_ltp_info(
s, &cpe->
ch[0], 1);
810 for (ch = 0; ch < chans; ch++) {
811 s->cur_channel = start_ch + ch;
828 rate_bits =
FFMIN(rate_bits, 6144 *
s->channels - 3);
829 too_many_bits =
FFMAX(target_bits, rate_bits);
830 too_many_bits =
FFMIN(too_many_bits, 6144 *
s->channels - 3);
831 too_few_bits =
FFMIN(
FFMAX(rate_bits - rate_bits/4, target_bits), too_many_bits);
834 too_few_bits = too_few_bits - too_few_bits/8;
835 too_many_bits = too_many_bits + too_many_bits/2;
838 || (its < 5 && (frame_bits < too_few_bits || frame_bits > too_many_bits))
839 || frame_bits >= 6144 *
s->channels - 3 )
841 float ratio = ((float)rate_bits) / frame_bits;
843 if (frame_bits >= too_few_bits && frame_bits <= too_many_bits) {
850 ratio = sqrtf(sqrtf(ratio));
854 ratio = sqrtf(ratio);
856 s->lambda =
av_clipf(
s->lambda * ratio, FLT_EPSILON, 65536.f);
859 if (ratio > 0.9
f && ratio < 1.1
f) {
862 if (is_mode || ms_mode || tns_mode || pred_mode) {
863 for (
i = 0;
i <
s->chan_map[0];
i++) {
867 for (ch = 0; ch < chans; ch++)
878 if (
s->options.ltp &&
s->coder->ltp_insert_new_frame)
879 s->coder->ltp_insert_new_frame(
s);
886 s->lambda_sum +=
s->lambda;
942 for(ch = 0; ch <
s->channels; ch++)
943 s->planar_samples[ch] =
s->buffer.samples + 3 * 1024 * ch;
957 s->last_frame_pb_count = 0;
968 s->needs_pce =
s->options.pce;
980 av_log(avctx,
AV_LOG_INFO,
"Using a PCE to encode channel layout \"%s\"\n", buf);
982 s->reorder_map =
s->pce.reorder_map;
983 s->chan_map =
s->pce.config_map;
990 for (
i = 1;
i <=
s->chan_map[0];
i++) {
998 for (
i = 0;
i < 16;
i++)
1001 s->samplerate_index =
i;
1005 "Unsupported sample rate %d\n", avctx->
sample_rate);
1009 "Too many bits %f > %d per frame requested, clamping to max\n",
1011 6144 *
s->channels);
1024 "Main prediction unavailable in the \"mpeg2_aac_low\" profile\n");
1026 "LTP prediction unavailable in the \"mpeg2_aac_low\" profile\n");
1028 "PNS unavailable in the \"mpeg2_aac_low\" profile, turning off\n");
1033 "Main prediction unavailable in the \"aac_ltp\" profile\n");
1035 s->options.pred = 1;
1037 "LTP prediction unavailable in the \"aac_main\" profile\n");
1038 }
else if (
s->options.ltp) {
1041 "Chainging profile to \"aac_ltp\"\n");
1043 "Main prediction unavailable in the \"aac_ltp\" profile\n");
1044 }
else if (
s->options.pred) {
1047 "Chainging profile to \"aac_main\"\n");
1049 "LTP prediction unavailable in the \"aac_main\" profile\n");
1057 "The ANMR coder is considered experimental, add -strict -2 to enable!\n");
1058 s->options.intensity_stereo = 0;
1062 "The LPT profile requires experimental compliance, add -strict -2 to enable!\n");
1065 if (
s->channels > 3)
1066 s->options.mid_side = 0;
1081 for (
i = 0;
i <
s->chan_map[0];
i++)
1084 s->chan_map[0], grouping)) < 0)
1088 s->random_state = 0x1f2e3d4c;
1105 #define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
1107 {
"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_ALLOCZ_TYPED_ARRAY(p, nelem)
int frame_size
Number of samples per channel in an audio frame.
@ AV_SAMPLE_FMT_FLTP
float, planar
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
const uint8_t ff_tns_max_bands_128[]
static const AVClass aacenc_class
static av_cold int init(AVCodecContext *avctx)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
uint64_t channel_layout
Audio channel layout.
static void put_bitstream_info(AACEncContext *s, const char *name)
Write some auxiliary information about the created AAC file.
float ff_aac_kbd_short_128[128]
static void align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int64_t *duration)
Remove frame(s) from the queue.
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
int sample_rate
samples per second
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
static void abs_pow34_v(float *out, const float *in, const int size)
static enum AVSampleFormat sample_fmts[]
static void copy_input_samples(AACEncContext *s, const AVFrame *frame)
static av_cold int aac_encode_init(AVCodecContext *avctx)
static const int aacenc_profiles[]
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
#define FF_PROFILE_AAC_MAIN
uint8_t zeroes[128]
band is not coded (used by encoder)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
This structure describes decoded (raw) audio or video data.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define WARN_IF(cond,...)
const AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB]
#define FF_PROFILE_AAC_LTP
static void encode_band_info(AACEncContext *s, SingleChannelElement *sce)
Encode scalefactor band coding type.
int window_shape
window shape (sine/KBD/whatever)
static const uint8_t aac_chan_configs[AAC_MAX_CHANNELS][6]
default channel configurations
int8_t used[MAX_LTP_LONG_SFB]
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
INTFLOAT pcoeffs[1024]
coefficients for IMDCT, pristine
const uint16_t *const ff_swb_offset_128[]
static void encode_spectral_coeffs(AACEncContext *s, SingleChannelElement *sce)
Encode spectral coefficients processed by psychoacoustic model.
const uint8_t ff_tns_max_bands_1024[]
int num_swb
number of scalefactor window bands
#define WINDOW_FUNC(type)
static void avoid_clipping(AACEncContext *s, SingleChannelElement *sce)
Downscale spectral coefficients for near-clipping windows to avoid artifacts.
INTFLOAT ret_buf[2048]
PCM output buffer.
#define FF_PROFILE_MPEG2_AAC_LOW
static void apply_mid_side_stereo(ChannelElement *cpe)
int ms_mode
Signals mid/side stereo flags coding mode (used by encoder)
int initial_padding
Audio only.
static const AVCodecDefault defaults[]
int flags
AV_CODEC_FLAG_*.
static void put_pce(PutBitContext *pb, AVCodecContext *avctx)
av_cold void ff_psy_end(FFPsyContext *ctx)
Cleanup model context at the end.
static __device__ float fabsf(float a)
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
uint8_t prediction_used[41]
int num_ele[4]
front, side, back, lfe
IndividualChannelStream ics
windowing related information
static void adjust_frame_information(ChannelElement *cpe, int chans)
Produce integer coefficients from scalefactors provided by the model.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
float clip_avoidance_factor
set if any window is near clipping to the necessary atennuation factor to avoid it
@ NOISE_BT
Spectral data are scaled white noise not coded in the bitstream.
INTFLOAT coeffs[1024]
coefficients for IMDCT, maybe processed
int global_quality
Global quality for codecs which cannot change it per frame.
const uint8_t * swb_sizes
table of scalefactor band sizes for a particular window
@ INTENSITY_BT2
Scalefactor data are intensity stereo positions (out of phase).
#define FF_PROFILE_UNKNOWN
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static const int64_t aac_normal_chan_layouts[7]
static av_cold int alloc_buffers(AVCodecContext *avctx, AACEncContext *s)
const int ff_aac_swb_size_128_len
void ff_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
Individual Channel Stream.
#define SCALE_DIFF_ZERO
codebook index corresponding to zero scalefactor indices difference
#define NOISE_PRE
preamble for NOISE_BT, put in bitstream with the first noise band
const uint16_t * swb_offset
table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular wind...
void ff_aac_tableinit(void)
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.
@ INTENSITY_BT
Scalefactor data are intensity stereo positions (in phase).
int window_type[3]
window type (short/long/transitional, etc.) - current, previous and next
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
static const AACPCEInfo aac_pce_configs[]
List of PCE (Program Configuration Element) for the channel layouts listed in channel_layout....
static __device__ float fabs(float a)
uint8_t is_mask[128]
Set if intensity stereo is used (used by encoder)
static const int sizes[][2]
const int ff_aac_swb_size_1024_len
static void encode_pulses(AACEncContext *s, Pulse *pulse)
Encode pulse data.
float is_ener[128]
Intensity stereo pos (used by encoder)
const uint8_t ff_aac_num_swb_128[]
int64_t bit_rate
the average bitrate
const char * av_default_item_name(void *ptr)
Return the context name.
int grouping[8]
window grouping (for e.g. AAC)
int sf_idx[128]
scalefactor indices (used by encoder)
static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
const uint8_t ff_aac_scalefactor_bits[121]
float clipping[8]
maximum absolute normalized intensity in the given window for clip avoidance
const OptionDef options[]
AAC_FLOAT lcoeffs[1024]
MDCT of LTP coefficients (used by encoder)
SingleChannelElement ch[2]
const uint16_t *const ff_swb_offset_1024[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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)
void ff_aac_float_common_init(void)
#define FF_PROFILE_AAC_LOW
static void encode_scale_factors(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce)
Encode scalefactors.
static void apply_window_and_mdct(AACEncContext *s, SingleChannelElement *sce, float *audio)
void ff_aac_coder_init_mips(AACEncContext *c)
int common_window
Set if channels share a common 'IndividualChannelStream' in bitstream.
static void apply_intensity_stereo(ChannelElement *cpe)
int index[4][8]
front, side, back, lfe
uint8_t ms_mask[128]
Set if mid/side stereo is used for each scalefactor window band.
av_cold void ff_lpc_end(LPCContext *s)
Uninitialize LPCContext.
#define AV_LOG_INFO
Standard information.
int channels
number of audio channels
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 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)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Single Channel Element - used for both SCE and LFE elements.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static int put_bits_count(PutBitContext *s)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
static const AVOption aacenc_options[]
channel element - generic struct for SCE/CPE/CCE/LFE
static void(*const apply_window[4])(AVFloatDSPContext *fdsp, SingleChannelElement *sce, const float *audio)
int pairing[3][8]
front, side, back
AVSampleFormat
Audio sample formats.
#define NOISE_PRE_BITS
length of preamble
av_cold struct FFPsyPreprocessContext * ff_psy_preprocess_init(AVCodecContext *avctx)
psychoacoustic model audio preprocessing initialization
float ff_aac_kbd_long_1024[1024]
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.
void ff_aac_dsp_init_x86(AACEncContext *s)
const uint8_t ff_aac_num_swb_1024[]
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
static void encode_ms_info(PutBitContext *pb, ChannelElement *cpe)
Encode MS data.
@ RESERVED_BT
Band types following are encoded differently from others.
void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int channels)
Preprocess several channel in audio frame in order to compress it better.
#define CLIP_AVOIDANCE_FACTOR
main external API structure.
static int encode_individual_channel(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, int common_window)
Encode one channel of audio data.
#define NOISE_OFFSET
subtracted from global gain, used as offset for the preamble
#define ERROR_IF(cond,...)
const uint8_t *const ff_aac_swb_size_1024[]
enum WindowSequence window_sequence[2]
@ AOT_SBR
Y Spectral Band Replication.
static int put_audio_specific_config(AVCodecContext *avctx)
Make AAC audio config object.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Filter the word “frame” indicates either a video frame or a group of audio samples
uint8_t is_mode
Set if any bands have been encoded using intensity stereo (used by encoder)
static void put_ics_info(AACEncContext *s, IndividualChannelStream *info)
Encode ics_info element.
const uint8_t *const ff_aac_swb_size_128[]
static const AVCodecDefault aac_encode_defaults[]
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
const int avpriv_mpeg4audio_sample_rates[16]
static av_cold int aac_encode_end(AVCodecContext *avctx)
int frame_number
Frame counter, set by libavcodec.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static av_always_inline int diff(const uint32_t a, const uint32_t b)
#define FF_AAC_PROFILE_OPTS
This structure stores compressed data.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
uint8_t window_clipping[8]
set if a certain window is near clipping
static const int mpeg4audio_sample_rates[16]
uint8_t max_sfb
number of scalefactor bands per group
INTFLOAT ltp_state[3072]
time signal for LTP
static av_cold int dsp_init(AVCodecContext *avctx, AACEncContext *s)
av_cold void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx)
Cleanup audio preprocessing module.
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
enum BandType band_type[128]
band types
uint8_t use_kb_window[2]
If set, use Kaiser-Bessel window, otherwise use a sine window.
@ FF_LPC_TYPE_LEVINSON
Levinson-Durbin recursion.
int num_windows
number of windows in a frame
av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order, enum FFLPCType lpc_type)
Initialize LPCContext.
const uint32_t ff_aac_scalefactor_code[121]
void ff_quantize_band_cost_cache_init(struct AACEncContext *s)