Browse code

Change the AC-3 encoder to use floating-point. Fixed-point AC-3 encoder renamed to ac3_fixed. Regression test acodec-ac3 renamed to acodec-ac3_fixed. Regression test lavf-rm changed to use ac3_fixed encoder.

Originally committed as revision 26209 to svn://svn.ffmpeg.org/ffmpeg/trunk

Justin Ruggles authored on 2011/01/04 20:53:44
Showing 13 changed files
... ...
@@ -70,6 +70,7 @@ version <next>:
70 70
 - Windows Televison (WTV) demuxer
71 71
 - FFmpeg metadata format muxer and demuxer
72 72
 - SubRip (srt) subtitle decoder
73
+- floating-point AC-3 encoder added
73 74
 
74 75
 
75 76
 version 0.6:
... ...
@@ -1193,6 +1193,7 @@ aac_decoder_select="mdct rdft"
1193 1193
 aac_encoder_select="mdct"
1194 1194
 aac_latm_decoder_select="aac_decoder aac_latm_parser"
1195 1195
 ac3_decoder_select="mdct ac3_parser"
1196
+ac3_encoder_select="mdct"
1196 1197
 alac_encoder_select="lpc"
1197 1198
 amrnb_decoder_select="lsp"
1198 1199
 amrwb_decoder_select="lsp"
... ...
@@ -1453,7 +1454,6 @@ set_ne_test_deps(){
1453 1453
 }
1454 1454
 
1455 1455
 test_deps _encoder _decoder                                             \
1456
-    ac3                                                                 \
1457 1456
     adpcm_g726=g726                                                     \
1458 1457
     adpcm_ima_qt                                                        \
1459 1458
     adpcm_ima_wav                                                       \
... ...
@@ -1525,6 +1525,7 @@ test_deps _muxer _demuxer                                               \
1525 1525
     wav                                                                 \
1526 1526
     yuv4mpegpipe=yuv4mpeg                                               \
1527 1527
 
1528
+ac3_fixed_test_deps="ac3_fixed_encoder ac3_decoder rm_muxer rm_demuxer"
1528 1529
 mpg_test_deps="mpeg1system_muxer mpegps_demuxer"
1529 1530
 
1530 1531
 set_ne_test_deps pixdesc
... ...
@@ -54,7 +54,8 @@ OBJS-$(CONFIG_AAC_ENCODER)             += aacenc.o aaccoder.o    \
54 54
                                           mpeg4audio.o
55 55
 OBJS-$(CONFIG_AASC_DECODER)            += aasc.o msrledec.o
56 56
 OBJS-$(CONFIG_AC3_DECODER)             += ac3dec.o ac3dec_data.o ac3.o
57
-OBJS-$(CONFIG_AC3_ENCODER)             += ac3enc_fixed.o ac3tab.o ac3.o
57
+OBJS-$(CONFIG_AC3_ENCODER)             += ac3enc_float.o ac3tab.o ac3.o
58
+OBJS-$(CONFIG_AC3_FIXED_ENCODER)       += ac3enc_fixed.o ac3tab.o ac3.o
58 59
 OBJS-$(CONFIG_ALAC_DECODER)            += alac.o
59 60
 OBJS-$(CONFIG_ALAC_ENCODER)            += alacenc.o
60 61
 OBJS-$(CONFIG_ALS_DECODER)             += alsdec.o bgmc.o mpeg4audio.o
... ...
@@ -37,6 +37,11 @@
37 37
 #include "audioconvert.h"
38 38
 
39 39
 
40
+#ifndef CONFIG_AC3ENC_FLOAT
41
+#define CONFIG_AC3ENC_FLOAT 0
42
+#endif
43
+
44
+
40 45
 /** Maximum number of exponent groups. +1 for separate DC exponent. */
41 46
 #define AC3_MAX_EXP_GROUPS 85
42 47
 
... ...
@@ -44,7 +49,11 @@
44 44
 #define SCALE_FLOAT(a, bits) lrintf((a) * (float)(1 << (bits)))
45 45
 
46 46
 
47
+#if CONFIG_AC3ENC_FLOAT
48
+#include "ac3enc_float.h"
49
+#else
47 50
 #include "ac3enc_fixed.h"
51
+#endif
48 52
 
49 53
 
50 54
 /**
... ...
@@ -130,7 +139,7 @@ typedef struct AC3EncodeContext {
130 130
 } AC3EncodeContext;
131 131
 
132 132
 
133
-/* prototypes for functions in ac3enc_fixed.c */
133
+/* prototypes for functions in ac3enc_fixed.c and ac3_float.c */
134 134
 
135 135
 static av_cold void mdct_end(AC3MDCTContext *mdct);
136 136
 
... ...
@@ -26,6 +26,7 @@
26 26
  * fixed-point AC-3 encoder.
27 27
  */
28 28
 
29
+#undef CONFIG_AC3ENC_FLOAT
29 30
 #include "ac3enc.c"
30 31
 
31 32
 
... ...
@@ -413,8 +414,8 @@ int main(void)
413 413
 #endif /* TEST */
414 414
 
415 415
 
416
-AVCodec ac3_encoder = {
417
-    "ac3",
416
+AVCodec ac3_fixed_encoder = {
417
+    "ac3_fixed",
418 418
     AVMEDIA_TYPE_AUDIO,
419 419
     CODEC_ID_AC3,
420 420
     sizeof(AC3EncodeContext),
421 421
new file mode 100644
... ...
@@ -0,0 +1,117 @@
0
+/*
1
+ * The simplest AC-3 encoder
2
+ * Copyright (c) 2000 Fabrice Bellard
3
+ * Copyright (c) 2006-2010 Justin Ruggles <justin.ruggles@gmail.com>
4
+ * Copyright (c) 2006-2010 Prakash Punnoor <prakash@punnoor.de>
5
+ *
6
+ * This file is part of FFmpeg.
7
+ *
8
+ * FFmpeg is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * FFmpeg is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with FFmpeg; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ */
22
+
23
+/**
24
+ * @file
25
+ * floating-point AC-3 encoder.
26
+ */
27
+
28
+#define CONFIG_AC3ENC_FLOAT 1
29
+#include "ac3enc.c"
30
+
31
+
32
+/**
33
+ * Finalize MDCT and free allocated memory.
34
+ */
35
+static av_cold void mdct_end(AC3MDCTContext *mdct)
36
+{
37
+    ff_mdct_end(&mdct->fft);
38
+    av_freep(&mdct->window);
39
+}
40
+
41
+
42
+/**
43
+ * Initialize MDCT tables.
44
+ * @param nbits log2(MDCT size)
45
+ */
46
+static av_cold int mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct,
47
+                             int nbits)
48
+{
49
+    float *window;
50
+    int n, n2;
51
+
52
+    n  = 1 << nbits;
53
+    n2 = n >> 1;
54
+
55
+    window = av_malloc(n2 * sizeof(*window));
56
+    if (!window) {
57
+        av_log(avctx, AV_LOG_ERROR, "Cannot allocate memory.\n");
58
+        return AVERROR(ENOMEM);
59
+    }
60
+    ff_kbd_window_init(window, 5.0, n2);
61
+    mdct->window = window;
62
+
63
+    return ff_mdct_init(&mdct->fft, nbits, 0, -2.0 / n);
64
+}
65
+
66
+
67
+/**
68
+ * Calculate a 512-point MDCT
69
+ * @param out 256 output frequency coefficients
70
+ * @param in  512 windowed input audio samples
71
+ */
72
+static void mdct512(AC3MDCTContext *mdct, float *out, float *in)
73
+{
74
+    ff_mdct_calc(&mdct->fft, out, in);
75
+}
76
+
77
+
78
+/**
79
+ * Apply KBD window to input samples prior to MDCT.
80
+ */
81
+static void apply_window(float *output, const float *input,
82
+                         const float *window, int n)
83
+{
84
+    int i;
85
+    int n2 = n >> 1;
86
+
87
+    for (i = 0; i < n2; i++) {
88
+        output[i]     = input[i]     * window[i];
89
+        output[n-i-1] = input[n-i-1] * window[i];
90
+    }
91
+}
92
+
93
+
94
+/**
95
+ * Normalize the input samples to use the maximum available precision.
96
+ */
97
+static int normalize_samples(AC3EncodeContext *s)
98
+{
99
+    /* Normalization is not needed for floating-point samples, so just return 0 */
100
+    return 0;
101
+}
102
+
103
+
104
+AVCodec ac3_encoder = {
105
+    "ac3",
106
+    AVMEDIA_TYPE_AUDIO,
107
+    CODEC_ID_AC3,
108
+    sizeof(AC3EncodeContext),
109
+    ac3_encode_init,
110
+    ac3_encode_frame,
111
+    ac3_encode_close,
112
+    NULL,
113
+    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE},
114
+    .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
115
+    .channel_layouts = ac3_channel_layouts,
116
+};
0 117
new file mode 100644
... ...
@@ -0,0 +1,46 @@
0
+/*
1
+ * The simplest AC-3 encoder
2
+ * Copyright (c) 2000 Fabrice Bellard
3
+ * Copyright (c) 2006-2010 Justin Ruggles <justin.ruggles@gmail.com>
4
+ * Copyright (c) 2006-2010 Prakash Punnoor <prakash@punnoor.de>
5
+ *
6
+ * This file is part of FFmpeg.
7
+ *
8
+ * FFmpeg is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * FFmpeg is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with FFmpeg; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ */
22
+
23
+/**
24
+ * @file
25
+ * floating-point AC-3 encoder header.
26
+ */
27
+
28
+#ifndef AVCODEC_AC3ENC_FLOAT_H
29
+#define AVCODEC_AC3ENC_FLOAT_H
30
+
31
+#include "fft.h"
32
+
33
+
34
+typedef float SampleType;
35
+typedef float CoefType;
36
+
37
+#define SCALE_COEF(a) SCALE_FLOAT((a), 24)
38
+
39
+
40
+typedef struct AC3MDCTContext {
41
+    const float *window;    ///< MDCT window function
42
+    FFTContext fft;         ///< FFT context for MDCT calculation
43
+} AC3MDCTContext;
44
+
45
+#endif /* AVCODEC_AC3ENC_FLOAT_H */
... ...
@@ -222,6 +222,7 @@ void avcodec_register_all(void)
222 222
     REGISTER_ENCDEC  (AAC, aac);
223 223
     REGISTER_DECODER (AAC_LATM, aac_latm);
224 224
     REGISTER_ENCDEC  (AC3, ac3);
225
+    REGISTER_ENCODER (AC3_FIXED, ac3_fixed);
225 226
     REGISTER_ENCDEC  (ALAC, alac);
226 227
     REGISTER_DECODER (ALS, als);
227 228
     REGISTER_DECODER (AMRNB, amrnb);
... ...
@@ -32,7 +32,7 @@
32 32
 #include "libavutil/cpu.h"
33 33
 
34 34
 #define LIBAVCODEC_VERSION_MAJOR 52
35
-#define LIBAVCODEC_VERSION_MINOR 101
35
+#define LIBAVCODEC_VERSION_MINOR 102
36 36
 #define LIBAVCODEC_VERSION_MICRO  0
37 37
 
38 38
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
... ...
@@ -269,8 +269,8 @@ do_audio_decoding
269 269
 $tiny_psnr $pcm_dst $pcm_ref 2 1924 >> $logfile
270 270
 fi
271 271
 
272
-if [ -n "$do_ac3" ] ; then
273
-do_audio_encoding ac3.rm "" -vn
272
+if [ -n "$do_ac3_fixed" ] ; then
273
+do_audio_encoding ac3.rm "" "-vn -acodec ac3_fixed"
274 274
 # binaries configured with --disable-sse decode ac3 differently
275 275
 #do_audio_decoding
276 276
 #$tiny_psnr $pcm_dst $pcm_ref 2 1024 >> $logfile
... ...
@@ -57,7 +57,7 @@ fi
57 57
 
58 58
 if [ -n "$do_rm" ] ; then
59 59
 file=${outfile}lavf.rm
60
-do_ffmpeg $file -t 1 -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src -f s16le -i $pcm_src
60
+do_ffmpeg $file -t 1 -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src -f s16le -i $pcm_src -acodec ac3_fixed
61 61
 # broken
62 62
 #do_ffmpeg_crc $file -i $target_path/$file
63 63
 fi
64 64
deleted file mode 100644
... ...
@@ -1,2 +0,0 @@
1
-b315176b519a63a35cb91566e768f62b *./tests/data/acodec/ac3.rm
2
-98751 ./tests/data/acodec/ac3.rm
3 1
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+b315176b519a63a35cb91566e768f62b *./tests/data/acodec/ac3.rm
1
+98751 ./tests/data/acodec/ac3.rm