* fixed-point AC-3 encoder.
*/
+#define AC3ENC_FLOAT 0
#define FFT_FLOAT 0
-#undef CONFIG_AC3ENC_FLOAT
+#define FFT_FIXED_32 1
#include "internal.h"
#include "audiodsp.h"
#include "ac3enc.h"
#include "eac3enc.h"
-
-#define AC3ENC_TYPE AC3ENC_TYPE_AC3_FIXED
-#include "ac3enc_opts_template.c"
+#include "kbdwin.h"
static const AVClass ac3enc_class = {
.class_name = "Fixed-Point AC-3 Encoder",
.item_name = av_default_item_name,
- .option = ac3_options,
+ .option = ff_ac3_enc_options,
.version = LIBAVUTIL_VERSION_INT,
};
-/*
- * Normalize the input samples to use the maximum available precision.
- * This assumes signed 16-bit input samples.
- */
-static int normalize_samples(AC3EncodeContext *s)
-{
- int v = s->ac3dsp.ac3_max_msb_abs_int16(s->windowed_samples, AC3_WINDOW_SIZE);
- v = 14 - av_log2(v);
- if (v > 0)
- s->ac3dsp.ac3_lshift_int16(s->windowed_samples, AC3_WINDOW_SIZE, v);
- /* +6 to right-shift from 31-bit to 25-bit */
- return v + 6;
-}
-
-
-/*
- * Scale MDCT coefficients to 25-bit signed fixed-point.
- */
-static void scale_coefficients(AC3EncodeContext *s)
-{
- int blk, ch;
-
- for (blk = 0; blk < s->num_blocks; blk++) {
- AC3Block *block = &s->blocks[blk];
- for (ch = 1; ch <= s->channels; ch++) {
- s->ac3dsp.ac3_rshift_int32(block->mdct_coef[ch], AC3_MAX_COEFS,
- block->coeff_shift[ch]);
- }
- }
-}
-
static void sum_square_butterfly(AC3EncodeContext *s, int64_t sum[4],
const int32_t *coef0, const int32_t *coef1,
int len)
*
* @param s AC-3 encoder private context
*/
-av_cold void ff_ac3_fixed_mdct_end(AC3EncodeContext *s)
+static av_cold void ac3_fixed_mdct_end(AC3EncodeContext *s)
{
ff_mdct_end(&s->mdct);
}
-
/**
* Initialize MDCT tables.
*
* @param s AC-3 encoder private context
* @return 0 on success, negative error code on failure
*/
-av_cold int ff_ac3_fixed_mdct_init(AC3EncodeContext *s)
+static av_cold int ac3_fixed_mdct_init(AC3EncodeContext *s)
{
- int ret = ff_mdct_init(&s->mdct, 9, 0, -1.0);
- s->mdct_window = ff_ac3_window;
- return ret;
+ float fwin[AC3_BLOCK_SIZE];
+
+ int32_t *iwin = av_malloc_array(AC3_BLOCK_SIZE, sizeof(*iwin));
+ if (!iwin)
+ return AVERROR(ENOMEM);
+
+ ff_kbd_window_init(fwin, 5.0, AC3_BLOCK_SIZE);
+ for (int i = 0; i < AC3_BLOCK_SIZE; i++)
+ iwin[i] = lrintf(fwin[i] * (1 << 22));
+
+ s->mdct_window = iwin;
+
+ s->fdsp = avpriv_alloc_fixed_dsp(s->avctx->flags & AV_CODEC_FLAG_BITEXACT);
+ if (!s->fdsp)
+ return AVERROR(ENOMEM);
+
+ return ff_mdct_init(&s->mdct, 9, 0, -1.0);
}
{
AC3EncodeContext *s = avctx->priv_data;
s->fixed_point = 1;
+ s->mdct_end = ac3_fixed_mdct_end;
+ s->mdct_init = ac3_fixed_mdct_init;
+ s->allocate_sample_buffers = allocate_sample_buffers;
return ff_ac3_encode_init(avctx);
}
-AVCodec ff_ac3_fixed_encoder = {
+const AVCodec ff_ac3_fixed_encoder = {
.name = "ac3_fixed",
.long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
.type = AVMEDIA_TYPE_AUDIO,
.init = ac3_fixed_encode_init,
.encode2 = ff_ac3_fixed_encode_frame,
.close = ff_ac3_encode_close,
- .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16P,
+ .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P,
AV_SAMPLE_FMT_NONE },
.priv_class = &ac3enc_class,
+ .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
+ .supported_samplerates = ff_ac3_sample_rate_tab,
.channel_layouts = ff_ac3_channel_layouts,
- .defaults = ac3_defaults,
+ .defaults = ff_ac3_enc_defaults,
};