summaryrefslogtreecommitdiff
path: root/libavcodec/ac3enc_fixed.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/ac3enc_fixed.c')
-rw-r--r--libavcodec/ac3enc_fixed.c60
1 files changed, 23 insertions, 37 deletions
diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index 7818dd8c35..eab086cdab 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -26,12 +26,14 @@
* fixed-point AC-3 encoder.
*/
-#define FFT_FLOAT 0
#define AC3ENC_FLOAT 0
+#define FFT_FLOAT 0
+#define FFT_FIXED_32 1
#include "internal.h"
#include "audiodsp.h"
#include "ac3enc.h"
#include "eac3enc.h"
+#include "kbdwin.h"
#define AC3ENC_TYPE AC3ENC_TYPE_AC3_FIXED
#include "ac3enc_opts_template.c"
@@ -43,37 +45,6 @@ static const AVClass ac3enc_class = {
.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)
@@ -120,7 +91,6 @@ static av_cold void ac3_fixed_mdct_end(AC3EncodeContext *s)
ff_mdct_end(&s->mdct);
}
-
/**
* Initialize MDCT tables.
*
@@ -129,9 +99,25 @@ static av_cold void ac3_fixed_mdct_end(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_WINDOW_SIZE, sizeof(*iwin));
+ if (!iwin)
+ return AVERROR(ENOMEM);
+
+ ff_kbd_window_init(fwin, 5.0, AC3_WINDOW_SIZE/2);
+ for (int i = 0; i < AC3_WINDOW_SIZE/2; i++) {
+ iwin[i] = lrintf(fwin[i] * (1 << 22));
+ iwin[AC3_WINDOW_SIZE-1-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);
}
@@ -155,7 +141,7 @@ AVCodec ff_ac3_fixed_encoder = {
.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,