63 #define EAC3_SR_CODE_REDUCED 3
74 num_copy_sections = 0;
83 for (i = 0; i < bandsize; i += copysize) {
100 for (i = 0; i < num_copy_sections; i++) {
104 bin += copy_sizes[i];
112 for (i = 0; i < bandsize; i++) {
114 accum += coeff *
coeff;
116 rms_energy[bnd] = sqrtf(accum / bandsize);
127 coeffs[0] *= atten_tab[0];
128 coeffs[1] *= atten_tab[1];
129 coeffs[2] *= atten_tab[2];
130 coeffs[3] *= atten_tab[1];
131 coeffs[4] *= atten_tab[0];
142 float nscale = s->
spx_noise_blend[
ch][bnd] * rms_energy[bnd] * (1.0f / INT32_MIN);
146 nscale *= 1.0 / (1<<23);
147 sscale *= 1.0 / (1<<23);
160 #define COEFF_0 10273905LL
163 #define COEFF_1 11863283LL
166 #define COEFF_2 3070444LL
175 int even0, even1, even2, odd0, odd1, odd2;
177 odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
179 even2 = ( pre_mant[2] *
COEFF_0) >> 23;
180 tmp = ( pre_mant[4] *
COEFF_1) >> 23;
181 odd0 = ((pre_mant[1] + pre_mant[5]) *
COEFF_2) >> 23;
183 even0 = pre_mant[0] + (tmp >> 1);
184 even1 = pre_mant[0] -
tmp;
191 odd0 = tmp + pre_mant[1] + pre_mant[3];
192 odd2 = tmp + pre_mant[5] - pre_mant[3];
194 pre_mant[0] = even0 + odd0;
195 pre_mant[1] = even1 + odd1;
196 pre_mant[2] = even2 + odd2;
197 pre_mant[3] = even2 - odd2;
198 pre_mant[4] = even1 - odd1;
199 pre_mant[5] = even0 - odd0;
205 int end_bap, gaq_mode;
210 end_bap = (gaq_mode < 2) ? 12 : 17;
217 for (bin = s->
start_freq[ch]; bin < s->end_freq[ch]; bin++) {
218 if (s->
bap[ch][bin] > 7 && s->
bap[ch][bin] < end_bap)
219 gaq_gain[gs++] =
get_bits1(gbc) << (gaq_mode-1);
224 for (bin = s->
start_freq[ch]; bin < s->end_freq[ch]; bin++) {
225 if (s->
bap[ch][bin] > 7 && s->
bap[ch][bin] < 17) {
228 if (group_code > 26) {
242 for (bin = s->
start_freq[ch]; bin < s->end_freq[ch]; bin++) {
243 int hebap = s->
bap[
ch][bin];
247 for (blk = 0; blk < 6; blk++) {
250 }
else if (hebap < 8) {
253 for (blk = 0; blk < 6; blk++) {
260 log_gain = gaq_gain[gs++];
264 gbits = bits - log_gain;
266 for (blk = 0; blk < 6; blk++) {
268 if (log_gain && mant == -(1 << (gbits-1))) {
271 int mbits = bits - (2 - log_gain);
273 mant = ((unsigned)mant) << (23 - (mbits - 1));
276 b = 1 << (23 - log_gain);
282 mant *= (1 << 24 - bits);
298 int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
299 int parse_transient_proc_info;
352 int64_t channel_layout = 0;
353 int channel_map =
get_bits(gbc, 16);
356 for (i = 0; i < 16; i++)
405 int mix_data_size = (
get_bits(gbc, 5) + 2) << 3;
471 for (i = 0; i < addbsil + 1; i++) {
484 ac3_exponent_strategy = 1;
489 parse_transient_proc_info =
get_bits1(gbc);
534 if (ac3_exponent_strategy) {
537 for (ch = !s->
cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
543 for (ch = !((s->
channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
545 for (blk = 0; blk < 6; blk++) {
563 if (parse_aht_info) {
569 for (ch = (num_cpl_blocks != 6); ch <= s->
channels; ch++) {
571 for (blk = 1; blk < 6; blk++) {
586 int csnroffst = (
get_bits(gbc, 6) - 15) << 4;
587 int snroffst = (csnroffst +
get_bits(gbc, 4)) << 2;
588 for (ch = 0; ch <= s->
channels; ch++)
593 if (parse_transient_proc_info) {
604 if (parse_spx_atten_data &&
get_bits1(gbc)) {
EAC3GaqMode
gain adaptive quantization mode
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
const uint8_t ff_ac3_slow_decay_tab[4]
int dither_flag[AC3_MAX_CHANNELS]
dither flags (dithflg)
const float ff_eac3_spx_atten_tab[32][3]
Table E.25: Spectral Extension Attenuation Table ff_eac3_spx_atten_tab[code][bin]=pow(2.0,(bin+1)*(code+1)/-15.0);.
int preferred_downmix
Preferred 2-channel downmix mode (dmixmod)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
const uint8_t ff_ac3_ungroup_3_in_5_bits_tab[32][3]
Table used to ungroup 3 values stored in 5 bits.
static int ff_eac3_parse_header(AC3DecodeContext *s)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
int channels
number of total channels
int exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS]
exponent strategies (expstr)
int lfe_on
lfe channel in use
const uint16_t ff_ac3_slow_gain_tab[4]
int block_switch[AC3_MAX_CHANNELS]
block switch flags (blksw)
int dba_syntax
delta bit allocation syntax enabled (dbaflde)
int dialog_normalization[2]
dialog level in dBFS (dialnorm)
int spx_src_start_freq
spx start frequency bin
static int get_sbits(GetBitContext *s, int n)
int lfe_mix_level_exists
indicates if lfemixlevcod is specified (lfemixlevcode)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
#define COEFF_0
lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23))
int first_cpl_coords[AC3_MAX_CHANNELS]
first coupling coordinates states (firstcplcos)
INTFLOAT spx_noise_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS]
spx noise blending factor (nblendfact)
int bit_allocation_syntax
bit allocation model syntax enabled (bamode)
Common code between the AC-3 and E-AC-3 decoders.
static void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
int channel_map
custom channel map (chanmap)
int substreamid
substream identification
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const uint8_t ff_ac3_fast_decay_tab[4]
int lfe_ch
index of LFE channel
uint8_t first_spx_coords[AC3_MAX_CHANNELS]
first spx coordinates states (firstspxcos)
AC3BitAllocParameters bit_alloc_params
bit allocation parameters
int dolby_surround_mode
dolby surround mode (dsurmod)
GetBitContext gbc
bitstream reader
int eac3_subsbtreamid_found
bitstream has E-AC-3 additional substream(s)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int dolby_headphone_mode
dolby headphone mode (dheadphonmod)
#define COEFF_2
lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23))
int compression_exists[2]
compression field is valid for frame (compre)
INTFLOAT transform_coeffs[AC3_MAX_CHANNELS][AC3_MAX_COEFS]
transform coefficients
#define EAC3_SR_CODE_REDUCED
int block_switch_syntax
block switch syntax enabled (blkswe)
int fast_gain_syntax
fast gain codes enabled (frmfgaincode)
uint8_t channel_uses_spx[AC3_MAX_CHANNELS]
channel uses spectral extension (chinspx)
static void idct6(int pre_mant[6])
Calculate 6-point IDCT of the pre-mantissas.
#define AC3_HEAVY_RANGE(x)
int surround_mix_level_ltrt
Surround mix level index for Lt/Rt (ltrtsurmixlev)
int dither_flag_syntax
dither flag syntax enabled (dithflage)
INTFLOAT heavy_dynamic_range[2]
heavy dynamic range compression
const int16_t ff_eac3_gaq_remap_1[12]
Table E3.6, Gk=1 No gain (Gk=1) inverse quantization, remapping scale factors ff_eac3_gaq_remap[hebap...
const int16_t ff_eac3_gaq_remap_2_4_a[9][2]
Table E3.6, Gk=2 & Gk=4, A Large mantissa inverse quantization, remapping scale factors ff_eac3_gaq_r...
#define COEFF_1
lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23))
AVCodecContext * avctx
parent context
const uint8_t ff_eac3_bits_vs_hebap[20]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int fbw_channels
number of full-bandwidth channels
int8_t spx_atten_code[AC3_MAX_CHANNELS]
spx attenuation code (spxattencod)
uint8_t bap[AC3_MAX_CHANNELS][AC3_MAX_COEFS]
bit allocation pointers
#define CPL_CH
coupling channel index
Libavcodec external API header.
const int16_t ff_eac3_gaq_remap_2_4_b[9][2]
Table E3.6, Gk=2 & Gk=4, B Large mantissa inverse quantization, negative mantissa remapping offsets f...
static void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
int num_spx_bands
number of spx bands (nspxbnds)
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
INTFLOAT spx_signal_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS]
spx signal blending factor (sblendfact)
static void skip_bits(GetBitContext *s, int n)
int bitstream_mode
bitstream mode (bsmod)
int center_mix_level_ltrt
Center mix level index for Lt/Rt (ltrtcmixlev)
int frame_type
frame type (strmtyp)
int channel_uses_aht[AC3_MAX_CHANNELS]
channel AHT in use (chahtinu)
const int16_t ff_ac3_floor_tab[8]
static int noise(AVBSFContext *ctx, AVPacket *pkt)
int cpl_in_use[AC3_MAX_BLOCKS]
coupling in use (cplinu)
const uint64_t ff_eac3_custom_channel_map_locations[16][2]
int first_cpl_leak
first coupling leak state (firstcplleak)
int surround_mix_level
Surround mix level index.
int snr_offset[AC3_MAX_CHANNELS]
signal-to-noise ratio offsets (snroffst)
common internal api header.
const uint8_t ff_eac3_frm_expstr[32][6]
Table E2.14 Frame Exponent Strategy Combinations.
int num_blocks
number of audio blocks
int target_level
target level in dBFS
int pre_mantissa[AC3_MAX_CHANNELS][AC3_MAX_COEFS][AC3_MAX_BLOCKS]
pre-IDCT mantissas
#define EAC3_MAX_CHANNELS
maximum number of channels in EAC3
uint8_t spx_band_sizes[SPX_MAX_BANDS]
number of bins in each spx band
int lfe_mix_level
LFE mix level index (lfemixlevcod)
int snr_offset_strategy
SNR offset strategy (snroffststr)
int start_freq[AC3_MAX_CHANNELS]
start frequency bin (strtmant)
int center_mix_level
Center mix level index.
static const double coeff[2][5]
int frame_size
current frame size, in bytes
const int16_t(*const [8] ff_eac3_mantissa_vq)[6]
int dolby_surround_ex_mode
dolby surround ex mode (dsurexmod)
AVLFG dith_state
for dither generation
int cpl_strategy_exists[AC3_MAX_BLOCKS]
coupling strategy exists (cplstre)
const uint16_t ff_ac3_db_per_bit_tab[4]
Common code between the AC-3 encoder and decoder.
int channel_mode
channel mode (acmod)
int spx_dst_start_freq
spx starting frequency bin for copying (copystartmant) the copy region ends at the start of the spx r...
int skip_syntax
skip field syntax enabled (skipflde)
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_SAMPL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MT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_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