Go to the documentation of this file.
45 sizeof(*
s->windowed_samples), alloc_fail);
48 for (ch = 0; ch <
s->channels; ch++) {
69 for (ch = 0; ch <
s->channels; ch++) {
71 memcpy(&
s->planar_samples[ch][0], &
s->planar_samples[ch][
AC3_BLOCK_SIZE *
s->num_blocks],
91 for (ch = 0; ch <
s->channels; ch++) {
96 #if CONFIG_AC3ENC_FLOAT
97 s->fdsp->vector_fmul(
s->windowed_samples, input_samples,
100 s->ac3dsp.apply_window_int16(
s->windowed_samples, input_samples,
107 s->mdct.mdct_calcw(&
s->mdct,
block->mdct_coef[ch+1],
108 s->windowed_samples);
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));
136 cpl_start =
s->start_freq[
CPL_CH] - 1;
137 num_cpl_coefs =
FFALIGN(
s->num_cpl_subbands * 12 + 1, 32);
138 cpl_start =
FFMIN(256, cpl_start + num_cpl_coefs) - num_cpl_coefs;
144 if (!
block->cpl_in_use)
146 memset(cpl_coef, 0, num_cpl_coefs *
sizeof(*cpl_coef));
147 for (ch = 1; ch <=
s->fbw_channels; ch++) {
149 if (!
block->channel_in_cpl[ch])
151 for (
i = 0;
i < num_cpl_coefs;
i++)
152 cpl_coef[
i] += ch_coef[
i];
164 int band_size =
s->cpl_band_sizes[bnd];
165 for (ch =
CPL_CH; ch <=
s->fbw_channels; ch++) {
170 for (j = 0; j < band_size; j++) {
183 if (!
block->cpl_in_use)
185 for (ch = 1; ch <=
s->fbw_channels; ch++) {
186 if (!
block->channel_in_cpl[ch])
188 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
200 memset(
block->new_cpl_coords, 0,
sizeof(
block->new_cpl_coords));
202 if (
block->cpl_in_use) {
209 for (ch = 1; ch <=
s->fbw_channels; ch++)
210 block->new_cpl_coords[ch] = 1;
212 for (ch = 1; ch <=
s->fbw_channels; ch++) {
213 if (!
block->channel_in_cpl[ch])
216 block->new_cpl_coords[ch] = 1;
219 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
220 coord_diff +=
FFABS(cpl_coords[
blk-1][ch][bnd] -
221 cpl_coords[
blk ][ch][bnd]);
223 coord_diff /=
s->num_cpl_bands;
225 block->new_cpl_coords[ch] = 1;
234 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
240 if (!
block->cpl_in_use) {
245 for (ch = 1; ch <=
s->fbw_channels; ch++) {
247 if (!
block->channel_in_cpl[ch])
250 energy_ch = energy[
blk][ch][bnd];
252 while (blk1 < s->
num_blocks && !
s->blocks[blk1].new_cpl_coords[ch]) {
253 if (
s->blocks[blk1].cpl_in_use) {
254 energy_cpl += energy[blk1][
CPL_CH][bnd];
255 energy_ch += energy[blk1][ch][bnd];
268 if (!
block->cpl_in_use)
271 #if CONFIG_AC3ENC_FLOAT
272 s->ac3dsp.float_to_fixed24(fixed_cpl_coords[
blk][1],
274 s->fbw_channels * 16);
276 s->ac3dsp.extract_exponents(
block->cpl_coord_exp[1],
277 fixed_cpl_coords[
blk][1],
278 s->fbw_channels * 16);
280 for (ch = 1; ch <=
s->fbw_channels; ch++) {
281 int bnd, min_exp, max_exp, master_exp;
283 if (!
block->new_cpl_coords[ch])
287 min_exp = max_exp =
block->cpl_coord_exp[ch][0];
288 for (bnd = 1; bnd <
s->num_cpl_bands; bnd++) {
289 int exp =
block->cpl_coord_exp[ch][bnd];
293 master_exp = ((max_exp - 15) + 2) / 3;
294 master_exp =
FFMAX(master_exp, 0);
295 while (min_exp < master_exp * 3)
297 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
298 block->cpl_coord_exp[ch][bnd] = av_clip(
block->cpl_coord_exp[ch][bnd] -
299 master_exp * 3, 0, 15);
301 block->cpl_master_exp[ch] = master_exp;
304 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
305 int cpl_exp =
block->cpl_coord_exp[ch][bnd];
306 int cpl_mant = (fixed_cpl_coords[
blk][ch][bnd] << (5 + cpl_exp + master_exp * 3)) >> 24;
312 block->cpl_coord_mant[ch][bnd] = cpl_mant;
317 if (CONFIG_EAC3_ENCODER &&
s->eac3)
336 block->new_rematrixing_strategy = !
blk;
338 block->num_rematrixing_bands = 4;
339 if (
block->cpl_in_use) {
340 block->num_rematrixing_bands -= (
s->start_freq[
CPL_CH] <= 61);
341 block->num_rematrixing_bands -= (
s->start_freq[
CPL_CH] == 37);
343 block->new_rematrixing_strategy = 1;
347 if (!
s->rematrixing_enabled) {
352 for (bnd = 0; bnd <
block->num_rematrixing_bands; bnd++) {
358 block->mdct_coef[2] + start,
end - start);
361 if (
FFMIN(sum[2], sum[3]) <
FFMIN(sum[0], sum[1]))
362 block->rematrixing_flags[bnd] = 1;
364 block->rematrixing_flags[bnd] = 0;
369 block->new_rematrixing_strategy = 1;
383 if (
s->options.allow_per_frame_metadata) {
389 if (
s->bit_alloc.sr_code == 1 ||
s->eac3)
402 s->cpl_on =
s->cpl_enabled;
int AC3_NAME() allocate_sample_buffers(AC3EncodeContext *s)
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
void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s)
Set the initial coupling strategy parameters prior to coupling analysis.
static void copy_input_samples(AC3EncodeContext *s, SampleType **samples)
uint8_t channel_in_cpl[AC3_MAX_CHANNELS]
channel in coupling (chincpl)
void ff_ac3_quantize_mantissas(AC3EncodeContext *s)
Quantize mantissas using coefficients, exponents, and bit allocation pointers.
static av_cold int end(AVCodecContext *avctx)
This structure describes decoded (raw) audio or video data.
void ff_ac3_apply_rematrixing(AC3EncodeContext *s)
Apply stereo rematrixing to coefficients based on rematrixing flags.
int AC3_NAME() encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
int ff_ac3_validate_metadata(AC3EncodeContext *s)
Validate metadata options as set by AVOption system.
void ff_eac3_set_cpl_states(AC3EncodeContext *s)
Set coupling states.
void ff_ac3_group_exponents(AC3EncodeContext *s)
Group exponents.
void ff_ac3_process_exponents(AC3EncodeContext *s)
Calculate final exponents from the supplied MDCT coefficients and exponent shift.
int initial_padding
Audio only.
#define AC3_MAX_CHANNELS
maximum number of channels, including coupling channel
static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame)
Write the frame to the output bitstream.
#define CPL_CH
coupling channel index
AC-3 encoder private context.
Data for a single audio block.
void ff_ac3_adjust_frame_size(AC3EncodeContext *s)
Adjust the frame size to make the average bit rate match the target bit rate.
static void clip_coefficients(AudioDSPContext *adsp, int32_t *coef, unsigned int len)
#define AV_NOPTS_VALUE
Undefined timestamp value.
static void apply_channel_coupling(AC3EncodeContext *s)
int ff_ac3_compute_bit_allocation(AC3EncodeContext *s)
static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl)
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...
#define i(width, name, range_min, range_max)
uint8_t rematrixing_flags[4]
rematrixing flags
static void compute_rematrixing_strategy(AC3EncodeContext *s)
int num_blocks
number of blocks per frame
static void sum_square_butterfly(AC3EncodeContext *s, int64_t sum[4], const int32_t *coef0, const int32_t *coef1, int len)
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
static void scale_coefficients(AC3EncodeContext *s)
int cpl_end_freq
coupling channel end frequency bin
int num_rematrixing_bands
number of rematrixing bands
main external API structure.
static void apply_mdct(AC3EncodeContext *s)
Filter the word “frame” indicates either a video frame or a group of audio samples
#define FF_ALLOC_OR_GOTO(ctx, p, size, label)
#define MAC_COEF(d, a, b)
#define LOCAL_ALIGNED_16(t, v,...)
This structure stores compressed data.
AVCodecContext * avctx
parent AVCodecContext
The exact code depends on how similar the blocks are and how related they are to the block
static int normalize_samples(AC3EncodeContext *s)
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
#define FF_ALLOCZ_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)
int cpl_in_use
coupling in use for this block (cplinu)
#define NEW_CPL_COORD_THRESHOLD