29#include "config_components.h"
42#define RENAME(element) element ## _float
44#define RENAME(element) element ## _fixed
48#define PHASE_BAND_ENERGY_DENOMINATOR (1 << 14)
49#define PHASE_DIFF_ENERGY_FACTOR (1 << 4)
60 for (
int ch = 0; ch <
s->channels; ch++) {
68 SampleType *windowed_samples =
s->RENAME(windowed_samples);
70 s->fdsp->vector_fmul(windowed_samples, input_samples0,
76 s->tx_fn(
s->tx,
block->mdct_coef[ch+1],
77 windowed_samples,
sizeof(*windowed_samples));
78 input_samples0 = input_samples1;
83 memcpy(
s->planar_samples[ch], input_samples0,
102 int cpl_start, num_cpl_coefs;
104 s->phase_flags_in_use = 0;
107 memset(fixed_cpl_coords, 0,
AC3_MAX_BLOCKS *
sizeof(*cpl_coords));
112 cpl_start =
s->start_freq[
CPL_CH] - 1;
113 num_cpl_coefs =
FFALIGN(
s->num_cpl_subbands * 12 + 1, 32);
114 cpl_start =
FFMIN(256, cpl_start + num_cpl_coefs) - num_cpl_coefs;
124 memset(phase_flags, 1,
s->num_cpl_bands);
132 if (!
block->cpl_in_use)
139 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
143 s->cpl_band_sizes[bnd]);
145 energy[
blk][1][bnd] = sum[bnd][0];
146 energy[
blk][2][bnd] = sum[bnd][1];
147 block_energy[0] += sum[bnd][0];
148 block_energy[1] += sum[bnd][1];
149 i +=
s->cpl_band_sizes[bnd];
151 max_energy =
FFMAX(block_energy[0], block_energy[1]);
152 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
154 int significant = band_energy >
157 phase_flags[bnd] &= significant &&
161 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
162 int phase = phase_flags[bnd] && cpl_blocks;
164 s->phase_flags[bnd] = phase;
165 s->phase_flags_in_use |= phase;
173 if (!
block->cpl_in_use)
175 memset(cpl_coef, 0, num_cpl_coefs *
sizeof(*cpl_coef));
176 for (ch = 1; ch <=
s->fbw_channels; ch++) {
178 if (!
block->channel_in_cpl[ch])
180 for (
i = 0;
i < num_cpl_coefs;
i++)
181 cpl_coef[
i] += ch_coef[
i];
189 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
190 if (
s->phase_flags[bnd]) {
191 for (j = 0; j <
s->cpl_band_sizes[bnd]; j++)
194 i +=
s->cpl_band_sizes[bnd];
207 int band_size =
s->cpl_band_sizes[bnd];
211 for (ch =
CPL_CH; ch <= last_ch; ch++) {
216 for (j = 0; j < band_size; j++) {
229 if (!
block->cpl_in_use)
231 for (ch = 1; ch <=
s->fbw_channels; ch++) {
232 if (!
block->channel_in_cpl[ch])
234 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
246 memset(
block->new_cpl_coords, 0,
sizeof(
block->new_cpl_coords));
248 if (
block->cpl_in_use) {
255 for (ch = 1; ch <=
s->fbw_channels; ch++)
256 block->new_cpl_coords[ch] = 1;
258 for (ch = 1; ch <=
s->fbw_channels; ch++) {
259 if (!
block->channel_in_cpl[ch])
262 block->new_cpl_coords[ch] = 1;
265 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
266 coord_diff +=
FFABS(cpl_coords[
blk-1][ch][bnd] -
267 cpl_coords[
blk ][ch][bnd]);
269 coord_diff /=
s->num_cpl_bands;
271 block->new_cpl_coords[ch] = 1;
282 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
288 if (!
block->cpl_in_use) {
293 for (ch = 1; ch <=
s->fbw_channels; ch++) {
295 if (!
block->channel_in_cpl[ch])
298 energy_ch = energy[
blk][ch][bnd];
300 while (blk1 < s->num_blocks && !
s->blocks[blk1].new_cpl_coords[ch]) {
301 if (
s->blocks[blk1].cpl_in_use) {
302 energy_cpl += energy[blk1][
CPL_CH][bnd];
303 energy_ch += energy[blk1][ch][bnd];
316 if (!
block->cpl_in_use)
320 s->ac3dsp.float_to_fixed24(fixed_cpl_coords[
blk][1],
322 s->fbw_channels * 16);
324 s->ac3dsp.extract_exponents(
block->cpl_coord_exp[1],
325 fixed_cpl_coords[
blk][1],
326 s->fbw_channels * 16);
328 for (ch = 1; ch <=
s->fbw_channels; ch++) {
329 int bnd, min_exp, max_exp, master_exp;
331 if (!
block->new_cpl_coords[ch])
335 min_exp = max_exp =
block->cpl_coord_exp[ch][0];
336 for (bnd = 1; bnd <
s->num_cpl_bands; bnd++) {
337 int exp =
block->cpl_coord_exp[ch][bnd];
341 master_exp = ((max_exp - 15) + 2) / 3;
342 master_exp =
FFMAX(master_exp, 0);
343 while (min_exp < master_exp * 3)
345 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
347 master_exp * 3, 0, 15);
349 block->cpl_master_exp[ch] = master_exp;
352 for (bnd = 0; bnd <
s->num_cpl_bands; bnd++) {
353 int cpl_exp =
block->cpl_coord_exp[ch][bnd];
354 int cpl_mant = (fixed_cpl_coords[
blk][ch][bnd] << (5 + cpl_exp + master_exp * 3)) >> 24;
360 block->cpl_coord_mant[ch][bnd] = cpl_mant;
384 block->new_rematrixing_strategy = !
blk;
386 block->num_rematrixing_bands = 4;
387 if (
block->cpl_in_use) {
388 block->num_rematrixing_bands -= (
s->start_freq[
CPL_CH] <= 61);
389 block->num_rematrixing_bands -= (
s->start_freq[
CPL_CH] == 37);
391 block->new_rematrixing_strategy = 1;
395 if (!
s->rematrixing_enabled) {
400 for (bnd = 0; bnd <
block->num_rematrixing_bands; bnd++) {
406 block->mdct_coef[2] + start, end - start);
409 if (
FFMIN(sum[2], sum[3]) <
FFMIN(sum[0], sum[1]))
410 block->rematrixing_flags[bnd] = 1;
412 block->rematrixing_flags[bnd] = 0;
417 block->new_rematrixing_strategy = 1;
431 frame->nb_samples,
s->channels,
432 s->avctx->sample_fmt);
435 s->avctx->frame_size - end,
436 s->channels,
s->avctx->sample_fmt);
443 if (!
frame ||
frame->nb_samples <
s->avctx->frame_size) {
445 samples =
s->input_samples;
447 samples =
frame->extended_data;
451 s->cpl_on =
s->cpl_enabled;
#define CPL_CH
coupling channel index
#define AC3_MAX_CHANNELS
maximum number of channels, including coupling channel
#define AC3_MAX_CPL_BANDS
void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s)
Set the initial coupling strategy parameters prior to coupling analysis.
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 encode_frame(AC3EncodeContext *s, const AVFrame *frame)
static void apply_channel_coupling(AC3EncodeContext *s)
#define PHASE_DIFF_ENERGY_FACTOR
static void apply_mdct(AC3EncodeContext *s, uint8_t *const *samples)
#define PHASE_BAND_ENERGY_DENOMINATOR
static void copy_input_samples(AC3EncodeContext *s, const AVFrame *frame)
static void compute_rematrixing_strategy(AC3EncodeContext *s)
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 int nb_coefs(int length, int level, uint64_t sn)
static float mdct_window[MDCT_SIZE]
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define i(width, name, range_min, range_max)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
void ff_eac3_set_cpl_states(AC3EncodeContext *s)
Set coupling states.
int av_samples_set_silence(uint8_t *const *audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
int av_samples_copy(uint8_t *const *dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Copy samples from src to dst.
Macro definitions for various function/variable attributes.
#define LOCAL_ALIGNED_32(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.
This structure describes decoded (raw) audio or video data.