52 #define CMIXLEV_NUM_OPTIONS 3 57 #define SURMIXLEV_NUM_OPTIONS 3 62 #define EXTMIXLEV_NUM_OPTIONS 8 110 { { 0, 0, 0, 12, 16, 32, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48 },
111 { 0, 0, 0, 16, 20, 36, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56 },
112 { 0, 0, 0, 32, 40, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60 } },
114 { { 0, 0, 0, 0, 0, 0, 0, 20, 24, 32, 48, 48, 48, 48, 48, 48, 48, 48, 48 },
115 { 0, 0, 0, 0, 0, 0, 4, 24, 28, 36, 56, 56, 56, 56, 56, 56, 56, 56, 56 },
116 { 0, 0, 0, 0, 0, 0, 20, 44, 52, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60 } },
118 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 24, 32, 40, 48, 48, 48, 48, 48, 48 },
119 { 0, 0, 0, 0, 0, 0, 0, 0, 4, 20, 28, 36, 44, 56, 56, 56, 56, 56, 56 },
120 { 0, 0, 0, 0, 0, 0, 0, 0, 20, 40, 48, 60, 60, 60, 60, 60, 60, 60, 60 } },
122 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 24, 32, 48, 48, 48, 48, 48, 48 },
123 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 28, 36, 56, 56, 56, 56, 56, 56 },
124 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 48, 60, 60, 60, 60, 60, 60, 60 } },
126 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 20, 32, 40, 48, 48, 48, 48 },
127 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 24, 36, 44, 56, 56, 56, 56 },
128 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 44, 60, 60, 60, 60, 60, 60 } }
144 { { 0, 0, 0, 0, 0, 0, 0, 1, 1, 7, 8, 11, 12, -1, -1, -1, -1, -1, -1 },
145 { 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 10, 12, 13, -1, -1, -1, -1, -1, -1 },
146 { 0, 0, 0, 0, 1, 2, 2, 9, 13, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
149 { { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
150 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
151 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
154 { { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
155 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 },
156 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
159 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
160 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
161 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
164 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
165 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 },
166 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
169 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 8, 11, 12, 12, -1, -1 },
170 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 8, 11, 12, 12, -1, -1 },
171 { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } },
241 if (!blk || (block->
cpl_in_use && !got_cpl_snr)) {
289 for (i = start; i <
end; i++) {
306 int expstr,
i, grpsize;
309 grpsize = 3 << expstr;
310 for (i = 12; i < 256; i++) {
340 #define EXP_DIFF_THRESHOLD 500 360 for (ch = !s->
cpl_on; ch <= s->fbw_channels; ch++) {
393 while (blk < s->num_blocks) {
395 while (blk1 < s->num_blocks && exp_strategy[blk1] ==
EXP_REUSE)
430 switch(exp_strategy) {
432 for (i = 1, k = 1-cpl; i <= nb_groups; i++) {
434 if (exp[k+1] < exp_min)
436 exp[i-cpl] = exp_min;
441 for (i = 1, k = 1-cpl; i <= nb_groups; i++) {
443 if (exp[k+1] < exp_min)
445 if (exp[k+2] < exp_min)
447 if (exp[k+3] < exp_min)
449 exp[i-cpl] = exp_min;
456 if (!cpl && exp[0] > 15)
461 for (i = 1; i <= nb_groups; i++)
462 exp[i] =
FFMIN(exp[i], exp[i-1] + 2);
465 exp[
i] =
FFMIN(exp[i], exp[i+1] + 2);
468 exp[-1] = exp[0] & ~1;
471 switch (exp_strategy) {
473 for (i = nb_groups, k = (nb_groups * 2)-cpl; i > 0; i--) {
480 for (i = nb_groups, k = (nb_groups * 4)-cpl; i > 0; i--) {
481 exp[
k] = exp[k-1] = exp[k-2] = exp[k-3] = exp[i-cpl];
497 int blk, blk1, ch, cpl;
499 int nb_coefs, num_reuse_blocks;
501 for (ch = !s->
cpl_on; ch <= s->channels; ch++) {
507 while (blk < s->num_blocks) {
520 while (blk1 < s->num_blocks && exp_strategy[blk1] ==
EXP_REUSE) {
524 num_reuse_blocks = blk1 - blk - 1;
548 int nb_groups, bit_count;
553 for (ch = !block->
cpl_in_use; ch <= s->channels; ch++) {
562 bit_count += 4 + (nb_groups * 7);
580 int group_size, nb_groups;
582 int delta0, delta1, delta2;
587 for (ch = !block->
cpl_in_use; ch <= s->channels; ch++) {
592 group_size = exp_strategy + (exp_strategy ==
EXP_D45);
601 for (i = 1; i <= nb_groups; i++) {
606 delta0 = exp1 - exp0 + 2;
612 delta1 = exp1 - exp0 + 2;
618 delta2 = exp1 - exp0 + 2;
621 block->
grouped_exp[ch][
i] = ((delta0 * 5 + delta1) * 5) + delta2;
653 static const int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
727 frame_bits += 2 + 2 + 2 + 2 + 3;
747 frame_bits += 1 + 16;
767 for (ch = 0; ch <= s->
channels; ch++)
809 frame_bits += 1 + 1 + 2;
815 frame_bits += 3 + 1 + 1;
822 frame_bits += 5 + 2 + 1;
838 frame_bits += 5 * s->
cpl_on;
896 if (!s->
eac3 || blk > 0)
945 for (ch = !block->
cpl_in_use; ch <= s->channels; ch++) {
978 for (ch = 0; ch <= s->
channels; ch++) {
999 memset(mant_cnt[blk], 0,
sizeof(mant_cnt[blk]));
1000 mant_cnt[
blk][1] = mant_cnt[
blk][2] = 2;
1001 mant_cnt[
blk][4] = 1;
1038 int ch, max_end_freq;
1044 for (ch = !s->
cpl_enabled; ch <= s->channels; ch++)
1066 snr_offset = (snr_offset - 240) << 2;
1072 for (ch = !block->
cpl_in_use; ch <= s->channels; ch++) {
1097 int snr_offset, snr_incr;
1112 while (snr_offset >= 0 &&
1120 for (snr_incr = 64; snr_incr > 0; snr_incr >>= 2) {
1121 while (snr_offset + snr_incr <= 1023 &&
1122 bit_alloc(s, snr_offset + snr_incr) <= bits_left) {
1123 snr_offset += snr_incr;
1131 for (ch = !s->
cpl_on; ch <= s->channels; ch++)
1166 int v = (((levels *
c) >> (24 - e)) + levels) >> 1;
1184 c = (((c << e) >> (24 - qbits)) + 1) >> 1;
1185 m = (1 << (qbits-1));
1206 int16_t *qmant,
int start_freq,
1211 for (i = start_freq; i < end_freq; i++) {
1212 int c = fixed_coef[
i];
1300 int blk, ch, ch0=0, got_cpl;
1307 for (ch = 1; ch <= s->
channels; ch++) {
1385 int ch,
i, baie, bnd, got_cpl, ch0;
1414 int start_sub, end_sub;
1431 for (bnd = start_sub+1; bnd < end_sub; bnd++)
1456 if (!s->
eac3 || blk > 0)
1467 for (ch = !block->
cpl_in_use; ch <= s->fbw_channels; ch++)
1480 for (ch = !block->
cpl_in_use; ch <= s->channels; ch++) {
1482 int cpl = (ch ==
CPL_CH);
1492 for (i = 1; i <= nb_groups; i++)
1518 for (ch = !block->
cpl_in_use; ch <= s->channels; ch++) {
1544 for (ch = 1; ch <= s->
channels; ch++) {
1552 for (i = s->
start_freq[ch]; i < block->end_freq[ch]; i++) {
1557 case 1:
if (q != 128)
put_bits (&s->
pb, 5, q);
break;
1558 case 2:
if (q != 128)
put_bits (&s->
pb, 7, q);
break;
1560 case 4:
if (q != 128)
put_bits (&s->
pb, 7, q);
break;
1573 #define CRC16_POLY ((1 << 0) | (1 << 2) | (1 << 15) | (1 << 16)) 1613 int frame_size_58, pad_bytes, crc1, crc2_partial, crc2, crc_inv;
1639 crc2_partial =
av_crc(crc_ctx, 0, frame + frame_size_58,
1644 if (crc2 == 0x770B) {
1682 case 6:
av_strlcpy(strbuf,
"AC-3 (alt syntax)", 32);
break;
1683 case 8:
av_strlcpy(strbuf,
"AC-3 (standard)", 32);
break;
1684 case 9:
av_strlcpy(strbuf,
"AC-3 (dnet half-rate)", 32);
break;
1685 case 10:
av_strlcpy(strbuf,
"AC-3 (dnet quater-rate)", 32);
break;
1686 case 16:
av_strlcpy(strbuf,
"E-AC-3 (enhanced)", 32);
break;
1687 default:
snprintf(strbuf, 32,
"ERROR");
1692 av_dlog(avctx,
"channel_layout: %s\n", strbuf);
1699 av_dlog(avctx,
"per_frame_metadata: %s\n",
1705 av_dlog(avctx,
"center_mixlev: {not written}\n");
1710 av_dlog(avctx,
"surround_mixlev: {not written}\n");
1719 av_dlog(avctx,
"room_type: %s\n", strbuf);
1721 av_dlog(avctx,
"mixing_level: {not written}\n");
1722 av_dlog(avctx,
"room_type: {not written}\n");
1733 av_dlog(avctx,
"dsur_mode: %s\n", strbuf);
1735 av_dlog(avctx,
"dsur_mode: {not written}\n");
1747 av_dlog(avctx,
"dmix_mode: %s\n", strbuf);
1748 av_dlog(avctx,
"ltrt_cmixlev: %0.3f (%d)\n",
1750 av_dlog(avctx,
"ltrt_surmixlev: %0.3f (%d)\n",
1752 av_dlog(avctx,
"loro_cmixlev: %0.3f (%d)\n",
1754 av_dlog(avctx,
"loro_surmixlev: %0.3f (%d)\n",
1757 av_dlog(avctx,
"extended bitstream info 1: {not written}\n");
1766 av_dlog(avctx,
"dsurex_mode: %s\n", strbuf);
1773 av_dlog(avctx,
"dheadphone_mode: %s\n", strbuf);
1780 av_dlog(avctx,
"ad_conv_type: %s\n", strbuf);
1782 av_dlog(avctx,
"extended bitstream info 2: {not written}\n");
1789 #define FLT_OPTION_THRESHOLD 0.01 1795 for (i = 0; i < v_list_size; i++) {
1800 if (i == v_list_size)
1808 float *opt_param,
const float *
list,
1809 int list_size,
int default_value,
int min_value,
1813 if (mixlev < min_value) {
1814 mixlev = default_value;
1815 if (*opt_param >= 0.0) {
1817 "default value: %0.3f\n", opt_name, list[mixlev]);
1820 *opt_param = list[mixlev];
1821 *ctx_param = mixlev;
1941 "specified number of channels\n");
1978 "room_type is set\n");
1983 "80dB and 111dB\n");
1994 static int warn_once = 1;
1997 "not compatible with reduced samplerates. writing of " 1998 "extended bitstream information will be disabled.\n");
2021 for (ch = 0; ch < s->
channels; ch++)
2060 uint64_t *channel_layout)
2066 if (*channel_layout > 0x7FF)
2068 ch_layout = *channel_layout;
2079 switch (ch_layout) {
2096 *channel_layout = ch_layout;
2112 "encoder will guess the layout, but it " 2113 "might be incorrect.\n");
2125 max_sr = s->
eac3 ? 2 : 8;
2126 for (i = 0; i <= max_sr; i++) {
2142 case 1: avctx->
bit_rate = 96000;
break;
2143 case 2: avctx->
bit_rate = 192000;
break;
2144 case 3: avctx->
bit_rate = 320000;
break;
2145 case 4: avctx->
bit_rate = 384000;
break;
2146 case 5: avctx->
bit_rate = 448000;
break;
2152 int max_br, min_br, wpf, min_br_dist, min_br_code;
2153 int num_blks_code, num_blocks, frame_samples;
2159 for (num_blks_code = 3; num_blks_code >= 0; num_blks_code--) {
2160 num_blocks = ((
int[]){ 1, 2, 3, 6 })[num_blks_code];
2162 max_br = 2048 * s->
sample_rate / frame_samples * 16;
2163 min_br = ((s->
sample_rate + (frame_samples-1)) / frame_samples) * 16;
2169 "for this sample rate\n", min_br, max_br);
2183 min_br_dist = INT_MAX;
2184 for (i = 0; i < 19; i++) {
2186 if (br_dist < min_br_dist) {
2187 min_br_dist = br_dist;
2198 int best_br = 0, best_code = 0, best_diff = INT_MAX;
2199 for (i = 0; i < 19; i++) {
2202 if (diff < best_diff) {
2249 int blk, ch, cpl_start;
2280 if (cpl_start < 0) {
2289 int i, cpl_start_band, cpl_end_band;
2293 cpl_start_band = av_clip(cpl_start, 0,
FFMIN(cpl_end_band-1, 15));
2298 *cpl_band_sizes = 12;
2299 for (i = cpl_start_band + 1; i < cpl_end_band; i++) {
2301 *cpl_band_sizes += 12;
2305 *cpl_band_sizes = 12;
2322 int channel_blocks = channels * s->
num_blocks;
2375 for (ch = 0; ch < channels; ch++) {
2400 for (ch = 0; ch < channels; ch++)
2408 for (ch = 0; ch < channels; ch++)
2422 int ret, frame_size_58;
static void count_mantissa_bits_init(uint16_t mant_cnt[AC3_MAX_BLOCKS][16])
Initialize mantissa counts.
uint8_t new_rematrixing_strategy
send new rematrixing flags in this block
uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]
exponent strategies
const uint8_t ff_ac3_bap_tab[64]
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
#define AC3_MAX_CODED_FRAME_SIZE
void(* mdct_end)(struct AC3EncodeContext *s)
static av_cold int set_channel_info(AC3EncodeContext *s, int channels, uint64_t *channel_layout)
static void ac3_output_frame_header(AC3EncodeContext *s)
int db_per_bit_code
dB/bit code (dbpbcod)
static const uint8_t exp_strategy_reuse_tab[4][6]
Table used to select exponent strategy based on exponent reuse block interval.
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
int slow_decay_code
slow decay code (sdcycod)
Encoding Options used by AVOption.
const uint8_t ff_ac3_slow_decay_tab[4]
void(* update_bap_counts)(uint16_t mant_cnt[16], uint8_t *bap, int len)
Update bap counts using the supplied array of bap.
int ff_ac3_fixed_allocate_sample_buffers(AC3EncodeContext *s)
float loro_surround_mix_level
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void compute_exp_strategy(AC3EncodeContext *s)
static int asym_quant(int c, int e, int qbits)
Asymmetric quantization on 2^qbits levels.
int dolby_surround_ex_mode
static uint8_t exponent_group_tab[2][3][256]
LUT for number of exponent groups.
#define AV_CH_LAYOUT_SURROUND
uint8_t ** cpl_coord_exp
coupling coord exponents (cplcoexp)
int bandwidth_code
bandwidth code (0 to 60) (chbwcod)
const uint16_t ff_ac3_frame_size_tab[38][3]
Possible frame sizes.
uint8_t * grouped_exp_buffer
static av_cold int allocate_buffers(AC3EncodeContext *s)
#define AV_LOG_WARNING
Something somehow does not look correct.
av_cold void ff_ac3_common_init(void)
Initialize some tables.
#define LEVEL_PLUS_1POINT5DB
int16_t ** psd
psd per frequency bin
int frame_size_code
frame size code (frmsizecod)
int frame_bits
all frame bits except exponents and mantissas
static void bit_alloc_init(AC3EncodeContext *s)
void ff_ac3_process_exponents(AC3EncodeContext *s)
Calculate final exponents from the supplied MDCT coefficients and exponent shift. ...
const uint16_t ff_ac3_sample_rate_tab[3]
#define AV_CH_LAYOUT_4POINT0
uint8_t ** cpl_coord_mant
coupling coord mantissas (cplcomant)
uint16_t ** qmant
quantized mantissas
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
int start_freq[AC3_MAX_CHANNELS]
start frequency bin (strtmant)
#define AV_CH_LAYOUT_STEREO
const uint16_t ff_ac3_slow_gain_tab[4]
PutBitContext pb
bitstream writer context
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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 list
static const float cmixlev_options[CMIXLEV_NUM_OPTIONS]
int(* mdct_init)(struct AC3EncodeContext *s)
int num_cpl_channels
number of channels in coupling
AC3BitAllocParameters bit_alloc
bit allocation parameters
#define AV_CH_LAYOUT_5POINT0
static int count_exponent_bits(AC3EncodeContext *s)
static void extract_exponents(AC3EncodeContext *s)
int ff_ac3_float_allocate_sample_buffers(AC3EncodeContext *s)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
int ff_ac3_validate_metadata(AC3EncodeContext *s)
Validate metadata options as set by AVOption system.
float ltrt_surround_mix_level
int new_cpl_leak
send new coupling leak info
int rematrixing_enabled
stereo rematrixing enabled
void ff_eac3_get_frame_exp_strategy(AC3EncodeContext *s)
Determine frame exponent strategy use and indices.
void(* extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs)
int channel_mode
channel mode (acmod)
int num_cpl_subbands
number of coupling subbands (ncplsubnd)
enum AVSampleFormat sample_fmt
audio sample format
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
static void count_frame_bits(AC3EncodeContext *s)
static const float extmixlev_options[EXTMIXLEV_NUM_OPTIONS]
uint8_t rematrixing_flags[4]
rematrixing flags
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
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 void set_bandwidth(AC3EncodeContext *s)
const uint8_t ff_ac3_enc_channel_map[8][2][6]
Table to remap channels from SMPTE order to AC-3 order.
av_cold int ff_ac3_encode_close(AVCodecContext *avctx)
Finalize encoding and free any memory allocated by the encoder.
#define AV_CH_LOW_FREQUENCY
int slow_gain_code
slow gain code (sgaincod)
uint8_t cpl_master_exp[AC3_MAX_CHANNELS]
coupling coord master exponents (mstrcplco)
#define CRC16_POLY
CRC-16 Polynomial.
void(* bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end, int snr_offset, int floor, const uint8_t *bap_tab, uint8_t *bap)
Calculate bit allocation pointers.
uint8_t ** exp
original exponents
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
int num_rematrixing_bands
number of rematrixing bands
static av_cold int validate_options(AC3EncodeContext *s)
AC3DSPContext ac3dsp
AC-3 optimized functions.
int loro_center_mix_level
Lo/Ro center mix level code.
int num_cpl_bands
number of coupling bands (ncplbnd)
static int bit_alloc(AC3EncodeContext *s, int snr_offset)
Run the bit allocation with a given SNR offset.
void ff_ac3_fixed_mdct_end(AC3EncodeContext *s)
static void dprint_options(AC3EncodeContext *s)
int lfe_channel
channel index of the LFE channel
int ref_bap_set
indicates if ref_bap pointers have been set
#define EXP_DIFF_THRESHOLD
Exponent Difference Threshold.
static av_cold void exponent_init(AC3EncodeContext *s)
static void quantize_mantissas_blk_ch(AC3Mant *s, int32_t *fixed_coef, uint8_t *exp, uint8_t *bap, int16_t *qmant, int start_freq, int end_freq)
Quantize a set of mantissas for a single channel in a single block.
int new_snr_offsets
send new SNR offsets
void(* output_frame_header)(struct AC3EncodeContext *s)
int loro_surround_mix_level
Lo/Ro surround mix level code.
CoefType ** mdct_coef
MDCT coefficients.
int16_t * qmant4_ptr
mantissa pointers for bap=1,2,4
#define AV_CH_LAYOUT_5POINT1
uint8_t channel_in_cpl[AC3_MAX_CHANNELS]
channel in coupling (chincpl)
#define AC3ENC_OPT_SMALL_ROOM
int num_blks_code
number of blocks code (numblkscod)
const uint64_t ff_ac3_channel_layouts[19]
List of supported channel layouts.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
static int sym_quant(int c, int e, int levels)
Symmetric quantization on 'levels' levels.
const uint8_t ff_ac3_fast_decay_tab[4]
AC3EncOptions options
encoding options
int16_t ** band_psd
psd per critical band
float ltrt_center_mix_level
static void encode_exponents_blk_ch(uint8_t *exp, int nb_exps, int exp_strategy, int cpl)
Update the exponents so that they are the ones the decoder will decode.
int channels
total number of channels (nchans)
#define AC3_MAX_CHANNELS
maximum number of channels, including coupling channel
int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, int start, int end, int fast_gain, int is_lfe, int dba_mode, int dba_nsegs, uint8_t *dba_offsets, uint8_t *dba_lengths, uint8_t *dba_values, int16_t *mask)
Calculate the masking curve.
int cpl_on
coupling turned on for this frame
simple assert() macros that are a bit more flexible than ISO C assert().
#define AV_CH_LAYOUT_QUAD
#define CONFIG_AC3_ENCODER
void av_log(void *avcl, int level, const char *fmt,...)
int fixed_point
indicates if fixed-point encoder is being used
int ltrt_surround_mix_level
Lt/Rt surround mix level code.
int new_cpl_strategy
send new coupling strategy
int surround_mix_level
surround mix level code
static void put_bits(J2kEncoderContext *s, int val, int n)
put n times val bit
int cpl_in_use
coupling in use for this block (cplinu)
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
int cpl_enabled
coupling enabled for all frames
static void output_frame_end(AC3EncodeContext *s)
#define EXTMIXLEV_NUM_OPTIONS
uint64_t channel_layout
Audio channel layout.
#define LEVEL_MINUS_4POINT5DB
static int put_bits_count(PutBitContext *s)
static void output_audio_block(AC3EncodeContext *s, int blk)
const uint16_t ff_ac3_bitrate_tab[19]
static int count_mantissa_bits(AC3EncodeContext *s)
Data for a single audio block.
common internal API header
int floor_code
floor code (floorcod)
int ff_ac3_compute_bit_allocation(AC3EncodeContext *s)
#define AC3ENC_OPT_DOWNMIX_LORO
int bitstream_mode
bitstream mode (bsmod)
#define AC3ENC_OPT_ADCONV_STANDARD
int has_surround
indicates if there are one or more surround channels
int bit_rate
the average bitrate
audio channel layout utility functions
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
int eac3
indicates if this is E-AC-3 vs. AC-3
static const uint8_t ac3_bandwidth_tab[5][3][19]
LUT to select the bandwidth code based on the bit rate, sample rate, and number of full-bandwidth cha...
float loro_center_mix_level
av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact)
int mant4_cnt
mantissa counts for bap=1,2,4
int ff_ac3_float_mdct_init(AC3EncodeContext *s)
Initialize MDCT tables.
const uint16_t ff_ac3_fast_gain_tab[8]
void ff_eac3_exponent_init(void)
Initialize E-AC-3 exponent tables.
void ff_ac3_adjust_frame_size(AC3EncodeContext *s)
Adjust the frame size to make the average bit rate match the target bit rate.
#define diff(a, as, b, bs)
int exponent_bits
number of bits used for exponents
#define AV_CH_LAYOUT_5POINT1_BACK
int coarse_snr_offset
coarse SNR offsets (csnroffst)
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
int16_t ** mask
masking curve
SampleType ** planar_samples
int fast_decay_code
fast decay code (fdcycod)
int frame_size
Number of samples per channel in an audio frame.
#define AC3ENC_OPT_MODE_OFF
#define AC3ENC_OPT_ADCONV_HDCD
#define CPL_CH
coupling channel index
const uint8_t ff_eac3_default_cpl_band_struct[18]
Table E2.16 Default Coupling Banding Structure.
uint8_t * ref_bap[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]
bit allocation pointers (bap)
void ff_eac3_output_frame_header(AC3EncodeContext *s)
Write the E-AC-3 frame header to the output bitstream.
int audio_production_info
int sample_rate
samples per second
static const int8_t ac3_coupling_start_tab[6][3][19]
LUT to select the coupling start band based on the bit rate, sample rate, and number of full-bandwidt...
main external API structure.
int fast_gain_code[AC3_MAX_CHANNELS]
fast gain codes (signal-to-mask ratio) (fgaincod)
int sample_rate
sampling frequency, in Hz
CoefType * mdct_coef_buffer
int has_center
indicates if there is a center channel
int bit_rate
target bit rate, in bits-per-second
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static unsigned int mul_poly(unsigned int a, unsigned int b, unsigned int poly)
int(* allocate_sample_buffers)(struct AC3EncodeContext *s)
const uint8_t * channel_map
channel map used to reorder channels
int frame_bits_fixed
number of non-coefficient bits for fixed parameters
int end_freq[AC3_MAX_CHANNELS]
end frequency bin (endmant)
#define FLT_OPTION_THRESHOLD
int(* compute_mantissa_size)(uint16_t mant_cnt[6][16])
Calculate the number of bits needed to encode a set of mantissas.
static int validate_float_option(float v, const float *v_list, int v_list_size)
synthesis window for stochastic i
uint8_t * cpl_coord_exp_buffer
int ltrt_center_mix_level
Lt/Rt center mix level code.
#define AV_CH_LAYOUT_5POINT0_BACK
int center_mix_level
center mix level code
AC-3 encoder private context.
void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame)
Write the frame to the output bitstream.
static void count_frame_bits_fixed(AC3EncodeContext *s)
AC3Block blocks[AC3_MAX_BLOCKS]
per-block info
const int16_t ff_ac3_floor_tab[8]
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
SampleType * windowed_samples
int preferred_stereo_downmix
void ff_ac3_quantize_mantissas(AC3EncodeContext *s)
Quantize mantissas using coefficients, exponents, and bit allocation pointers.
void(* ac3_exponent_min)(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
Set each encoded exponent in a block to the minimum of itself and the exponents in the same frequency...
int num_blocks
number of blocks per frame
static void encode_exponents(AC3EncodeContext *s)
#define CMIXLEV_NUM_OPTIONS
static void reset_block_bap(AC3EncodeContext *s)
int frame_size
current frame size in bytes
#define SURMIXLEV_NUM_OPTIONS
#define CONFIG_AC3_FIXED_ENCODER
uint8_t ** grouped_exp
grouped exponents
int cpl_end_freq
coupling channel end frequency bin
#define AC3ENC_OPT_LARGE_ROOM
uint8_t cpl_band_sizes[AC3_MAX_CPL_BANDS]
number of coeffs in each coupling band
#define AC3ENC_OPT_MODE_ON
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static void validate_mix_level(void *log_ctx, const char *opt_name, float *opt_param, const float *list, int list_size, int default_value, int min_value, int *ctx_param)
#define FF_ALLOC_OR_GOTO(ctx, p, size, label)
static const float surmixlev_options[SURMIXLEV_NUM_OPTIONS]
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
int64_t bits_written
bit count (used to avg. bitrate)
int bitstream_id
bitstream id (bsid)
int16_t * band_psd_buffer
AVCodecContext * avctx
parent AVCodecContext
uint8_t exp_ref_block[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]
reference blocks for EXP_REUSE
int cutoff
Audio cutoff bandwidth (0 means "automatic")
int allow_per_frame_metadata
void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, int16_t *band_psd)
Calculate the log power-spectral density of the input signal.
static void count_mantissa_bits_update_ch(AC3EncodeContext *s, int ch, uint16_t mant_cnt[AC3_MAX_BLOCKS][16], int start, int end)
Update mantissa bit counts for all blocks in 1 channel in a given bandwidth range.
#define AC3ENC_OPT_DOWNMIX_LTRT
int channels
number of audio channels
#define AC3ENC_OPT_NOT_INDICATED
static int cbr_bit_allocation(AC3EncodeContext *s)
int frame_size_min
minimum frame size in case rounding is necessary
void ff_ac3_float_mdct_end(AC3EncodeContext *s)
Finalize MDCT and free allocated memory.
AC-3 encoder & E-AC-3 encoder common header.
static unsigned int pow_poly(unsigned int a, unsigned int n, unsigned int poly)
#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...
int64_t samples_written
sample count (used to avg. bitrate)
uint8_t * cpl_coord_mant_buffer
int use_frame_exp_strategy
indicates use of frame exp strategy
#define FFSWAP(type, a, b)
static void bit_alloc_masking(AC3EncodeContext *s)
int ff_ac3_fixed_mdct_init(AC3EncodeContext *s)
void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
Initialize a float DSP context.
void ff_ac3_group_exponents(AC3EncodeContext *s)
Group exponents.
const uint16_t ff_ac3_db_per_bit_tab[4]
#define CONFIG_EAC3_ENCODER
#define AV_CH_LAYOUT_MONO
void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s)
Set the initial coupling strategy parameters prior to coupling analysis.
int cutoff
user-specified cutoff frequency, in Hz
int lfe_on
indicates if there is an LFE channel (lfeon)
int fine_snr_offset[AC3_MAX_CHANNELS]
fine SNR offsets (fsnroffst)
Common code between the AC-3 encoder and decoder.
int32_t * fixed_coef_buffer
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)
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.
int32_t ** fixed_coef
fixed-point MDCT coefficients
av_cold int ff_ac3_encode_init(AVCodecContext *avctx)
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.