49 for (ch = 0; ch <
s->channels; ch++) {
51 sizeof(**
s->planar_samples))))
67 for (ch = 0; ch <
s->channels; ch++) {
69 memcpy(&
s->planar_samples[ch][0], &
s->planar_samples[ch][
AC3_BLOCK_SIZE *
s->num_blocks],
74 samples[
s->channel_map[ch]],
89 for (ch = 0; ch <
s->channels; ch++) {
94 s->fdsp->vector_fmul(
s->windowed_samples, input_samples,
100 s->mdct.mdct_calc(&
s->mdct,
block->mdct_coef[ch+1],
101 s->windowed_samples);
120 int cpl_start, num_cpl_coefs;
124 memset(fixed_cpl_coords, 0,
AC3_MAX_BLOCKS *
sizeof(*cpl_coords));
129 cpl_start =
s->start_freq[
CPL_CH] - 1;
130 num_cpl_coefs =
FFALIGN(
s->num_cpl_subbands * 12 + 1, 32);
131 cpl_start =
FFMIN(256, cpl_start + num_cpl_coefs) - num_cpl_coefs;
137 if (!
block->cpl_in_use)
139 memset(cpl_coef, 0, num_cpl_coefs *
sizeof(*cpl_coef));
140 for (ch = 1; ch <=
s->fbw_channels; ch++) {
142 if (!
block->channel_in_cpl[ch])
144 for (
i = 0;
i < num_cpl_coefs;
i++)
145 cpl_coef[
i] += ch_coef[
i];
156 while (i < s->cpl_end_freq) {
157 int band_size =
s->cpl_band_sizes[bnd];
158 for (ch =
CPL_CH; ch <=
s->fbw_channels; ch++) {
163 for (j = 0; j < band_size; j++) {
176 if (!
block->cpl_in_use)
178 for (ch = 1; ch <=
s->fbw_channels; ch++) {
179 if (!
block->channel_in_cpl[ch])
181 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
193 memset(
block->new_cpl_coords, 0,
sizeof(
block->new_cpl_coords));
195 if (
block->cpl_in_use) {
202 for (ch = 1; ch <=
s->fbw_channels; ch++)
203 block->new_cpl_coords[ch] = 1;
205 for (ch = 1; ch <=
s->fbw_channels; ch++) {
206 if (!
block->channel_in_cpl[ch])
209 block->new_cpl_coords[ch] = 1;
212 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
213 coord_diff +=
FFABS(cpl_coords[
blk-1][ch][bnd] -
214 cpl_coords[
blk ][ch][bnd]);
216 coord_diff /=
s->num_cpl_bands;
218 block->new_cpl_coords[ch] = 1;
227 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
229 while (blk < s->num_blocks) {
233 if (!
block->cpl_in_use) {
238 for (ch = 1; ch <=
s->fbw_channels; ch++) {
240 if (!
block->channel_in_cpl[ch])
243 energy_ch = energy[
blk][ch][bnd];
245 while (blk1 < s->num_blocks && !
s->blocks[blk1].new_cpl_coords[ch]) {
246 if (
s->blocks[blk1].cpl_in_use) {
247 energy_cpl += energy[blk1][
CPL_CH][bnd];
248 energy_ch += energy[blk1][ch][bnd];
261 if (!
block->cpl_in_use)
265 s->ac3dsp.float_to_fixed24(fixed_cpl_coords[
blk][1],
267 s->fbw_channels * 16);
269 s->ac3dsp.extract_exponents(
block->cpl_coord_exp[1],
270 fixed_cpl_coords[
blk][1],
271 s->fbw_channels * 16);
273 for (ch = 1; ch <=
s->fbw_channels; ch++) {
274 int bnd, min_exp, max_exp, master_exp;
276 if (!
block->new_cpl_coords[ch])
280 min_exp = max_exp =
block->cpl_coord_exp[ch][0];
281 for (bnd = 1; bnd <
s->num_cpl_bands; bnd++) {
282 int exp =
block->cpl_coord_exp[ch][bnd];
286 master_exp = ((max_exp - 15) + 2) / 3;
287 master_exp =
FFMAX(master_exp, 0);
288 while (min_exp < master_exp * 3)
290 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
292 master_exp * 3, 0, 15);
294 block->cpl_master_exp[ch] = master_exp;
297 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
298 int cpl_exp =
block->cpl_coord_exp[ch][bnd];
299 int cpl_mant = (fixed_cpl_coords[
blk][ch][bnd] << (5 + cpl_exp + master_exp * 3)) >> 24;
305 block->cpl_coord_mant[ch][bnd] = cpl_mant;
329 block->new_rematrixing_strategy = !
blk;
331 block->num_rematrixing_bands = 4;
332 if (
block->cpl_in_use) {
333 block->num_rematrixing_bands -= (
s->start_freq[
CPL_CH] <= 61);
334 block->num_rematrixing_bands -= (
s->start_freq[
CPL_CH] == 37);
336 block->new_rematrixing_strategy = 1;
340 if (!
s->rematrixing_enabled) {
345 for (bnd = 0; bnd <
block->num_rematrixing_bands; bnd++) {
351 block->mdct_coef[2] + start, end - start);
354 if (
FFMIN(sum[2], sum[3]) <
FFMIN(sum[0], sum[1]))
355 block->rematrixing_flags[bnd] = 1;
357 block->rematrixing_flags[bnd] = 0;
362 block->new_rematrixing_strategy = 1;
376 if (
s->options.allow_per_frame_metadata) {
389 s->cpl_on =
s->cpl_enabled;
#define CPL_CH
coupling channel index
#define AC3_MAX_CHANNELS
maximum number of channels, including coupling channel
int ff_ac3_validate_metadata(AC3EncodeContext *s)
Validate metadata options as set by AVOption system.
void ff_ac3_adjust_frame_size(AC3EncodeContext *s)
Adjust the frame size to make the average bit rate match the target bit rate.
void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s)
Set the initial coupling strategy parameters prior to coupling analysis.
int ff_ac3_encode_frame_common_end(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
AC-3 encoder & E-AC-3 encoder common header.
#define NEW_CPL_COORD_THRESHOLD
#define MAC_COEF(d, a, b)
static void clip_coefficients(AudioDSPContext *adsp, int32_t *coef, unsigned int len)
static void sum_square_butterfly(AC3EncodeContext *s, int64_t sum[4], const int32_t *coef0, const int32_t *coef1, int len)
static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl)
static void scale_coefficients(AC3EncodeContext *s)
static void apply_channel_coupling(AC3EncodeContext *s)
static void copy_input_samples(AC3EncodeContext *s, SampleType **samples)
static int allocate_sample_buffers(AC3EncodeContext *s)
static void compute_rematrixing_strategy(AC3EncodeContext *s)
static void apply_mdct(AC3EncodeContext *s)
int AC3_NAME() encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
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...
Macro definitions for various function/variable attributes.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define CONFIG_EAC3_ENCODER
void ff_eac3_set_cpl_states(AC3EncodeContext *s)
Set coupling states.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
common internal API header
#define FF_ALLOC_TYPED_ARRAY(p, nelem)
#define FF_ALLOCZ_TYPED_ARRAY(p, nelem)
#define LOCAL_ALIGNED_16(t, v,...)
Data for a single audio block.
uint8_t rematrixing_flags[4]
rematrixing flags
int num_rematrixing_bands
number of rematrixing bands
uint8_t channel_in_cpl[AC3_MAX_CHANNELS]
channel in coupling (chincpl)
int cpl_in_use
coupling in use for this block (cplinu)
AC-3 encoder private context.
main external API structure.
This structure describes decoded (raw) audio or video data.
uint8_t ** extended_data
pointers to the data planes/channels.
This structure stores compressed data.