45 sizeof(*
s->windowed_samples), alloc_fail);
48 for (ch = 0; ch <
s->channels; ch++) {
69 for (ch = 0; ch < s->
channels; ch++) {
91 for (ch = 0; ch < s->
channels; ch++) {
96 #if CONFIG_AC3ENC_FLOAT
120 #if CONFIG_AC3ENC_FLOAT
127 int cpl_start, num_cpl_coefs;
130 #if CONFIG_AC3ENC_FLOAT
131 memset(fixed_cpl_coords, 0,
AC3_MAX_BLOCKS *
sizeof(*cpl_coords));
138 cpl_start =
FFMIN(256, cpl_start + num_cpl_coefs) - num_cpl_coefs;
146 memset(cpl_coef, 0, num_cpl_coefs *
sizeof(*cpl_coef));
151 for (i = 0; i < num_cpl_coefs; i++)
152 cpl_coef[i] += ch_coef[i];
170 for (j = 0; j < band_size; j++) {
220 coord_diff +=
FFABS(cpl_coords[
blk-1][ch][bnd] -
221 cpl_coords[
blk ][ch][bnd]);
250 energy_ch = energy[
blk][
ch][bnd];
254 energy_cpl += energy[blk1][
CPL_CH][bnd];
255 energy_ch += energy[blk1][
ch][bnd];
271 #if CONFIG_AC3ENC_FLOAT
277 fixed_cpl_coords[blk][1],
281 int bnd, min_exp, max_exp, master_exp;
290 min_exp =
FFMIN(exp, min_exp);
291 max_exp =
FFMAX(exp, max_exp);
293 master_exp = ((max_exp - 15) + 2) / 3;
294 master_exp =
FFMAX(master_exp, 0);
295 while (min_exp < master_exp * 3)
299 master_exp * 3, 0, 15);
306 int cpl_mant = (fixed_cpl_coords[
blk][
ch][bnd] << (5 + cpl_exp + master_exp * 3)) >> 24;
317 if (CONFIG_EAC3_ENCODER && s->
eac3)
358 block->
mdct_coef[2] + start, end - start);
361 if (
FFMIN(sum[2], sum[3]) <
FFMIN(sum[0], sum[1]))
uint8_t new_rematrixing_strategy
send new rematrixing flags in this block
void(* float_to_fixed24)(int32_t *dst, const float *src, unsigned int len)
Convert an array of float in range [-1.0,1.0] to int32_t with range [-(1<<24),(1<<24)].
This structure describes decoded (raw) audio or video data.
int AC3_NAME() allocate_sample_buffers(AC3EncodeContext *s)
static void apply_mdct(AC3EncodeContext *s)
uint8_t ** cpl_coord_exp
coupling coord exponents (cplcoexp)
void ff_ac3_process_exponents(AC3EncodeContext *s)
Calculate final exponents from the supplied MDCT coefficients and exponent shift. ...
void ff_eac3_set_cpl_states(AC3EncodeContext *s)
Set coupling states.
uint8_t ** cpl_coord_mant
coupling coord mantissas (cplcomant)
int start_freq[AC3_MAX_CHANNELS]
start frequency bin (strtmant)
AC3BitAllocParameters bit_alloc
bit allocation parameters
Macro definitions for various function/variable attributes.
int ff_ac3_validate_metadata(AC3EncodeContext *s)
Validate metadata options as set by AVOption system.
int rematrixing_enabled
stereo rematrixing enabled
static void apply_channel_coupling(AC3EncodeContext *s)
int channel_mode
channel mode (acmod)
int num_cpl_subbands
number of coupling subbands (ncplsubnd)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
uint8_t rematrixing_flags[4]
rematrixing flags
int fbw_channels
number of full-bandwidth channels (nfchans)
uint8_t new_cpl_coords[AC3_MAX_CHANNELS]
send new coupling coordinates (cplcoe)
static av_cold int end(AVCodecContext *avctx)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t cpl_master_exp[AC3_MAX_CHANNELS]
coupling coord master exponents (mstrcplco)
int num_rematrixing_bands
number of rematrixing bands
AC3DSPContext ac3dsp
AC-3 optimized functions.
int num_cpl_bands
number of coupling bands (ncplbnd)
CoefType ** mdct_coef
MDCT coefficients.
uint8_t channel_in_cpl[AC3_MAX_CHANNELS]
channel in coupling (chincpl)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AC3EncOptions options
encoding options
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
Calculate the entry wise product of two vectors of floats and store the result in a vector of floats...
int channels
total number of channels (nchans)
int initial_padding
Audio only.
#define AC3_MAX_CHANNELS
maximum number of channels, including coupling channel
int cpl_on
coupling turned on for this frame
int fixed_point
indicates if fixed-point encoder is being used
int cpl_in_use
coupling in use for this block (cplinu)
int cpl_enabled
coupling enabled for all frames
Data for a single audio block.
common internal API header
int ff_ac3_compute_bit_allocation(AC3EncodeContext *s)
int eac3
indicates if this is E-AC-3 vs. AC-3
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
void ff_ac3_adjust_frame_size(AC3EncodeContext *s)
Adjust the frame size to make the average bit rate match the target bit rate.
FFTContext mdct
FFT context for MDCT calculation.
void(* extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs)
int AC3_NAME() encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
static void scale_coefficients(AC3EncodeContext *s)
const SampleType * mdct_window
MDCT window function array.
SampleType ** planar_samples
static void clip_coefficients(AudioDSPContext *adsp, int32_t *coef, unsigned int len)
#define CPL_CH
coupling channel index
static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl)
#define NEW_CPL_COORD_THRESHOLD
main external API structure.
const uint8_t * channel_map
channel map used to reorder channels
int end_freq[AC3_MAX_CHANNELS]
end frequency bin (endmant)
AC-3 encoder private context.
void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame)
Write the frame to the output bitstream.
void(* apply_window_int16)(int16_t *output, const int16_t *input, const int16_t *window, unsigned int len)
Apply symmetric window in 16-bit fixed-point.
AC3Block blocks[AC3_MAX_BLOCKS]
per-block info
SampleType * windowed_samples
void ff_ac3_quantize_mantissas(AC3EncodeContext *s)
Quantize mantissas using coefficients, exponents, and bit allocation pointers.
int num_blocks
number of blocks per frame
#define FF_ALLOC_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)
uint8_t coeff_shift[AC3_MAX_CHANNELS]
fixed-point coefficient shift values
int frame_size
current frame size in bytes
int cpl_end_freq
coupling channel end frequency bin
uint8_t cpl_band_sizes[AC3_MAX_CPL_BANDS]
number of coeffs in each coupling band
common internal api header.
#define FF_ALLOC_OR_GOTO(ctx, p, size, label)
AVCodecContext * avctx
parent AVCodecContext
static void compute_rematrixing_strategy(AC3EncodeContext *s)
int allow_per_frame_metadata
static void copy_input_samples(AC3EncodeContext *s, SampleType **samples)
#define MAC_COEF(d, a, b)
static int normalize_samples(AC3EncodeContext *s)
AC-3 encoder & E-AC-3 encoder common header.
#define LOCAL_ALIGNED_16(t, v,...)
void ff_ac3_apply_rematrixing(AC3EncodeContext *s)
Apply stereo rematrixing to coefficients based on rematrixing flags.
const uint8_t ff_ac3_rematrix_band_tab[5]
Table of bin locations for rematrixing bands reference: Section 7.5.2 Rematrixing : Frequency Band De...
static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
static void sum_square_butterfly(AC3EncodeContext *s, int64_t sum[4], const int32_t *coef0, const int32_t *coef1, int len)
void ff_ac3_group_exponents(AC3EncodeContext *s)
Group exponents.
uint8_t ** extended_data
pointers to the data planes/channels.
void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s)
Set the initial coupling strategy parameters prior to coupling analysis.
This structure stores compressed data.
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)
#define AV_NOPTS_VALUE
Undefined timestamp value.
void(* mdct_calcw)(struct FFTContext *s, FFTDouble *output, const FFTSample *input)
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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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_X86ASM &&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