29
29
#define CONFIG_FFT_FLOAT 0
30
30
#undef CONFIG_AC3ENC_FLOAT
31
31
#include "ac3enc.h"
33
34
#define AC3ENC_TYPE AC3ENC_TYPE_AC3_FIXED
34
35
#include "ac3enc_opts_template.c"
35
static AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_item_name,
36
ac3fixed_options, LIBAVUTIL_VERSION_INT };
36
static const AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_item_name,
37
ac3fixed_options, LIBAVUTIL_VERSION_INT };
38
39
#include "ac3enc_template.c"
42
43
* Finalize MDCT and free allocated memory.
45
* @param s AC-3 encoder private context
44
av_cold void AC3_NAME(mdct_end)(AC3MDCTContext *mdct)
47
av_cold void AC3_NAME(mdct_end)(AC3EncodeContext *s)
46
ff_mdct_end(&mdct->fft);
49
ff_mdct_end(&s->mdct);
51
54
* Initialize MDCT tables.
52
* @param nbits log2(MDCT size)
56
* @param s AC-3 encoder private context
57
* @return 0 on success, negative error code on failure
54
av_cold int AC3_NAME(mdct_init)(AVCodecContext *avctx, AC3MDCTContext *mdct,
59
av_cold int AC3_NAME(mdct_init)(AC3EncodeContext *s)
57
int ret = ff_mdct_init(&mdct->fft, nbits, 0, -1.0);
58
mdct->window = ff_ac3_window;
61
int ret = ff_mdct_init(&s->mdct, 9, 0, -1.0);
62
s->mdct_window = ff_ac3_window;
64
68
* Apply KBD window to input samples prior to MDCT.
66
void AC3_NAME(apply_window)(DSPContext *dsp, int16_t *output,
67
const int16_t *input, const int16_t *window,
70
static void apply_window(DSPContext *dsp, int16_t *output, const int16_t *input,
71
const int16_t *window, unsigned int len)
70
73
dsp->apply_window_int16(output, input, window, len);
75
* Calculate the log2() of the maximum absolute value in an array.
76
* @param tab input array
77
* @param n number of values in the array
78
* @return log2(max(abs(tab[])))
80
static int log2_tab(AC3EncodeContext *s, int16_t *src, int len)
82
int v = s->ac3dsp.ac3_max_msb_abs_int16(src, len);
88
78
* Normalize the input samples to use the maximum available precision.
89
79
* This assumes signed 16-bit input samples.
91
* @return exponent shift
93
int AC3_NAME(normalize_samples)(AC3EncodeContext *s)
81
static int normalize_samples(AC3EncodeContext *s)
95
int v = 14 - log2_tab(s, s->windowed_samples, AC3_WINDOW_SIZE);
83
int v = s->ac3dsp.ac3_max_msb_abs_int16(s->windowed_samples, AC3_WINDOW_SIZE);
97
86
s->ac3dsp.ac3_lshift_int16(s->windowed_samples, AC3_WINDOW_SIZE, v);
98
87
/* +6 to right-shift from 31-bit to 25-bit */
104
93
* Scale MDCT coefficients to 25-bit signed fixed-point.
106
void AC3_NAME(scale_coefficients)(AC3EncodeContext *s)
95
static void scale_coefficients(AC3EncodeContext *s)
110
for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
99
for (blk = 0; blk < s->num_blocks; blk++) {
111
100
AC3Block *block = &s->blocks[blk];
112
101
for (ch = 1; ch <= s->channels; ch++) {
113
102
s->ac3dsp.ac3_rshift_int32(block->mdct_coef[ch], AC3_MAX_COEFS,
110
* Clip MDCT coefficients to allowable range.
112
static void clip_coefficients(DSPContext *dsp, int32_t *coef, unsigned int len)
114
dsp->vector_clip_int32(coef, coef, COEF_MIN, COEF_MAX, len);
119
* Calculate a single coupling coordinate.
121
static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl)
123
if (energy_cpl <= COEF_MAX) {
126
uint64_t coord = energy_ch / (energy_cpl >> 24);
127
uint32_t coord32 = FFMIN(coord, 1073741824);
128
coord32 = ff_sqrt(coord32) << 9;
129
return FFMIN(coord32, COEF_MAX);
120
134
static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx)
122
136
AC3EncodeContext *s = avctx->priv_data;
128
142
AVCodec ff_ac3_fixed_encoder = {
132
sizeof(AC3EncodeContext),
133
ac3_fixed_encode_init,
144
.type = AVMEDIA_TYPE_AUDIO,
146
.priv_data_size = sizeof(AC3EncodeContext),
147
.init = ac3_fixed_encode_init,
148
.encode = ff_ac3_fixed_encode_frame,
149
.close = ff_ac3_encode_close,
137
150
.sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
138
151
.long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
139
152
.priv_class = &ac3enc_class,