[FFmpeg-devel] [PATCH] [WIP] mpegaudioenc_float: change the transforms and surrounding code to use floats
Michael Niedermayer
michaelni at gmx.at
Tue Dec 3 23:44:32 CET 2013
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
libavcodec/mpegaudio.h | 11 ++++--
libavcodec/mpegaudioenc_template.c | 66 +++++++++++++++++++++++-------------
libavcodec/mpegaudiotab.h | 2 +-
tests/ref/acodec/mp2 | 6 ++--
tests/ref/lavf/asf | 4 +--
tests/ref/lavf/avi | 4 +--
tests/ref/lavf/ffm | 4 +--
tests/ref/lavf/mkv | 8 ++---
tests/ref/lavf/mpg | 12 +++----
tests/ref/lavf/nut | 4 +--
tests/ref/lavf/ts | 4 +--
tests/ref/lavf/wtv | 4 +--
12 files changed, 78 insertions(+), 51 deletions(-)
diff --git a/libavcodec/mpegaudio.h b/libavcodec/mpegaudio.h
index 1591a17..10de3a3 100644
--- a/libavcodec/mpegaudio.h
+++ b/libavcodec/mpegaudio.h
@@ -56,20 +56,27 @@
#define FRAC_ONE (1 << FRAC_BITS)
-#define FIX(a) ((int)((a) * FRAC_ONE))
-
#if USE_FLOATS
# define INTFLOAT float
+# define SHORTFLOAT float
typedef float MPA_INT;
typedef float OUT_INT;
+# define FIX(a) (a)
+# define MUL(a,b) ((a) * (b))
#elif FRAC_BITS <= 15
# define INTFLOAT int
+# define SHORTFLOAT short
typedef int16_t MPA_INT;
typedef int16_t OUT_INT;
+# define FIX(a) ((int)((a) * FRAC_ONE))
+# define MUL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS)
#else
# define INTFLOAT int
+# define SHORTFLOAT short
typedef int32_t MPA_INT;
typedef int16_t OUT_INT;
+# define FIX(a) ((int)((a) * FRAC_ONE))
+# define MUL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS)
#endif
int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
diff --git a/libavcodec/mpegaudioenc_template.c b/libavcodec/mpegaudioenc_template.c
index b2dfe78..8fd41df 100644
--- a/libavcodec/mpegaudioenc_template.c
+++ b/libavcodec/mpegaudioenc_template.c
@@ -38,10 +38,6 @@
#include "mpegaudiodata.h"
#include "mpegaudiotab.h"
-/* currently, cannot change these constants (need to modify
- quantization stage) */
-#define MUL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS)
-
#define SAMPLES_BUF_SIZE 4096
typedef struct MpegAudioContext {
@@ -53,15 +49,15 @@ typedef struct MpegAudioContext {
int frame_size; /* frame size, in bits, without padding */
/* padding computation */
int frame_frac, frame_frac_incr, do_padding;
- short samples_buf[MPA_MAX_CHANNELS][SAMPLES_BUF_SIZE]; /* buffer for filter */
+ SHORTFLOAT samples_buf[MPA_MAX_CHANNELS][SAMPLES_BUF_SIZE]; /* buffer for filter */
int samples_offset[MPA_MAX_CHANNELS]; /* offset in samples_buf */
- int sb_samples[MPA_MAX_CHANNELS][3][12][SBLIMIT];
+ INTFLOAT sb_samples[MPA_MAX_CHANNELS][3][12][SBLIMIT];
unsigned char scale_factors[MPA_MAX_CHANNELS][SBLIMIT][3]; /* scale factors */
/* code to group 3 scale factors */
unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT];
int sblimit; /* number of used subbands */
const unsigned char *alloc_table;
- int16_t filter_bank[512];
+ SHORTFLOAT filter_bank[512];
int scale_factor_table[64];
unsigned char scale_diff_table[128];
#if USE_FLOATS
@@ -141,11 +137,15 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
s->samples_offset[i] = 0;
for(i=0;i<257;i++) {
- int v;
+ INTFLOAT v;
v = ff_mpa_enwindow[i];
+#if USE_FLOATS
+ v /= 1<<16;
+#else
#if WFRAC_BITS != 16
v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);
#endif
+#endif
s->filter_bank[i] = v;
if ((i & 63) != 0)
v = -v;
@@ -194,11 +194,12 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
}
/* 32 point floating point IDCT without 1/sqrt(2) coef zero scaling */
-static void idct32(int *out, int *tab)
+static void idct32(INTFLOAT *out, INTFLOAT *tab)
{
int i, j;
- int *t, *t1, xr;
- const int *xp = costab32;
+ INTFLOAT *t, *t1;
+ INTFLOAT xr;
+ const INTFLOAT *xp = costab32;
for(j=31;j>=3;j-=2) tab[j] += tab[j - 2];
@@ -317,11 +318,12 @@ static void idct32(int *out, int *tab)
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
{
- short *p, *q;
- int sum, offset, i, j;
- int tmp[64];
- int tmp1[32];
- int *out;
+ SHORTFLOAT *p, *q;
+ int offset, i, j;
+ INTFLOAT sum;
+ INTFLOAT tmp[64];
+ INTFLOAT tmp1[32];
+ INTFLOAT *out;
offset = s->samples_offset[ch];
out = &s->sb_samples[ch][0][0][0];
@@ -349,9 +351,15 @@ static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
p++;
q++;
}
+#if USE_FLOATS
+ tmp1[0] = tmp[16];
+ for( i=1; i<=16; i++ ) tmp1[i] = (tmp[i+16]+tmp[16-i]);
+ for( i=17; i<=31; i++ ) tmp1[i] = (tmp[i+16]-tmp[80-i]);
+#else
tmp1[0] = tmp[16] >> WSHIFT;
for( i=1; i<=16; i++ ) tmp1[i] = (tmp[i+16]+tmp[16-i]) >> WSHIFT;
for( i=17; i<=31; i++ ) tmp1[i] = (tmp[i+16]-tmp[80-i]) >> WSHIFT;
+#endif
idct32(out, tmp1);
@@ -361,7 +369,7 @@ static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
/* handle the wrap around */
if (offset < 0) {
memmove(s->samples_buf[ch] + SAMPLES_BUF_SIZE - (512 - 32),
- s->samples_buf[ch], (512 - 32) * 2);
+ s->samples_buf[ch], sizeof(**s->samples_buf) * (512 - 32));
offset = SAMPLES_BUF_SIZE - 512;
}
}
@@ -371,10 +379,11 @@ static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
static void compute_scale_factors(MpegAudioContext *s,
unsigned char scale_code[SBLIMIT],
unsigned char scale_factors[SBLIMIT][3],
- int sb_samples[3][12][SBLIMIT],
+ INTFLOAT sb_samples[3][12][SBLIMIT],
int sblimit)
{
- int *p, vmax, v, n, i, j, k, code;
+ int vmax, v, n, i, j, k, code;
+ INTFLOAT *p;
int index, d1, d2;
unsigned char *sf = &scale_factors[0][0];
@@ -382,6 +391,15 @@ static void compute_scale_factors(MpegAudioContext *s,
for(i=0;i<3;i++) {
/* find the max absolute value */
p = &sb_samples[i][0][j];
+#if USE_FLOATS
+ vmax = abs(rintf(*p));
+ for(k=1;k<12;k++) {
+ p += SBLIMIT;
+ v = abs(rintf(*p));
+ if (v > vmax)
+ vmax = v;
+ }
+#else
vmax = abs(*p);
for(k=1;k<12;k++) {
p += SBLIMIT;
@@ -389,6 +407,7 @@ static void compute_scale_factors(MpegAudioContext *s,
if (v > vmax)
vmax = v;
}
+#endif
/* compute the scale factor index using log 2 computations */
if (vmax > 1) {
n = av_log2(vmax);
@@ -674,7 +693,8 @@ static void encode_frame(MpegAudioContext *s,
for(ch=0;ch<s->nb_channels;ch++) {
b = bit_alloc[ch][i];
if (b) {
- int qindex, steps, m, sample, bits;
+ int qindex, steps, m, bits;
+ INTFLOAT sample;
/* we encode 3 sub band samples of the same sub band at a time */
qindex = s->alloc_table[j+b];
steps = ff_mpa_quant_steps[qindex];
@@ -684,7 +704,7 @@ static void encode_frame(MpegAudioContext *s,
#if USE_FLOATS
{
float a;
- a = (float)sample * s->scale_factor_inv_table[s->scale_factors[ch][i][k]];
+ a = sample * s->scale_factor_inv_table[s->scale_factors[ch][i][k]];
q[m] = (int)((a + 1.0) * steps * 0.5);
}
#else
@@ -701,10 +721,10 @@ static void encode_frame(MpegAudioContext *s,
q1 = sample >> shift;
q1 = (q1 * mult) >> P;
q[m] = ((q1 + (1 << P)) * steps) >> (P + 1);
- if (q[m] < 0)
- q[m] = 0;
}
#endif
+ if (q[m] < 0)
+ q[m] = 0;
if (q[m] >= steps)
q[m] = steps - 1;
av_assert2(q[m] >= 0 && q[m] < steps);
diff --git a/libavcodec/mpegaudiotab.h b/libavcodec/mpegaudiotab.h
index 42d42d8..e199b45 100644
--- a/libavcodec/mpegaudiotab.h
+++ b/libavcodec/mpegaudiotab.h
@@ -35,7 +35,7 @@
#define SQRT2 1.41421356237309514547
-static const int costab32[30] = {
+static const INTFLOAT costab32[30] = {
FIX(0.54119610014619701222),
FIX(1.3065629648763763537),
diff --git a/tests/ref/acodec/mp2 b/tests/ref/acodec/mp2
index 42381b4..32edf2f 100644
--- a/tests/ref/acodec/mp2
+++ b/tests/ref/acodec/mp2
@@ -1,4 +1,4 @@
-f6eb0a205350bbd7fb1028a01c7ae8aa *tests/data/fate/acodec-mp2.mp2
+17d7f85e383120588fa0f67d103fde5f *tests/data/fate/acodec-mp2.mp2
96130 tests/data/fate/acodec-mp2.mp2
-5a669ca7321adc6ab66a3eade4035909 *tests/data/fate/acodec-mp2.out.wav
-stddev: 4384.33 PSNR: 23.49 MAXDIFF:52631 bytes: 1058400/ 1057916
+f73c2d59019fe99bc78989b96b39fe93 *tests/data/fate/acodec-mp2.out.wav
+stddev: 4384.86 PSNR: 23.49 MAXDIFF:52631 bytes: 1058400/ 1057916
diff --git a/tests/ref/lavf/asf b/tests/ref/lavf/asf
index a90e547..6ad8e38 100644
--- a/tests/ref/lavf/asf
+++ b/tests/ref/lavf/asf
@@ -1,3 +1,3 @@
-6bc7dc5698c3607fad8937d14560e50c *./tests/data/lavf/lavf.asf
+36538661a6882be9ab777285cbe1e8b5 *./tests/data/lavf/lavf.asf
333581 ./tests/data/lavf/lavf.asf
-./tests/data/lavf/lavf.asf CRC=0xf6340a10
+./tests/data/lavf/lavf.asf CRC=0x216aef9f
diff --git a/tests/ref/lavf/avi b/tests/ref/lavf/avi
index 3cbb44f..210cac0 100644
--- a/tests/ref/lavf/avi
+++ b/tests/ref/lavf/avi
@@ -1,3 +1,3 @@
-8d3a3554cbe21bc232603ca26b0c4d3e *./tests/data/lavf/lavf.avi
+8fa4e0fed761bbd08a522e329356957f *./tests/data/lavf/lavf.avi
330806 ./tests/data/lavf/lavf.avi
-./tests/data/lavf/lavf.avi CRC=0xec6c3c68
+./tests/data/lavf/lavf.avi CRC=0x17a22206
diff --git a/tests/ref/lavf/ffm b/tests/ref/lavf/ffm
index 7071866..7fa016d 100644
--- a/tests/ref/lavf/ffm
+++ b/tests/ref/lavf/ffm
@@ -1,3 +1,3 @@
-6f1443b952819cff1dae875529675e88 *./tests/data/lavf/lavf.ffm
+5ee1950aaec8acab25749262dfd1de37 *./tests/data/lavf/lavf.ffm
376832 ./tests/data/lavf/lavf.ffm
-./tests/data/lavf/lavf.ffm CRC=0x000e23ae
+./tests/data/lavf/lavf.ffm CRC=0x2b35094c
diff --git a/tests/ref/lavf/mkv b/tests/ref/lavf/mkv
index 51fd2e7..8af0dab 100644
--- a/tests/ref/lavf/mkv
+++ b/tests/ref/lavf/mkv
@@ -1,6 +1,6 @@
-5e3e58192b11644477474a25bef2e022 *./tests/data/lavf/lavf.mkv
+6dbb4fe8b3296face8f70c122d4e1710 *./tests/data/lavf/lavf.mkv
472559 ./tests/data/lavf/lavf.mkv
-./tests/data/lavf/lavf.mkv CRC=0xec6c3c68
-6aac0de39634046f23a3447b08380efe *./tests/data/lavf/lavf.mkv
+./tests/data/lavf/lavf.mkv CRC=0x17a22206
+0d611a2408b2bd41a74a979c47816b91 *./tests/data/lavf/lavf.mkv
320288 ./tests/data/lavf/lavf.mkv
-./tests/data/lavf/lavf.mkv CRC=0xec6c3c68
+./tests/data/lavf/lavf.mkv CRC=0x17a22206
diff --git a/tests/ref/lavf/mpg b/tests/ref/lavf/mpg
index 9feff66..9c7588a 100644
--- a/tests/ref/lavf/mpg
+++ b/tests/ref/lavf/mpg
@@ -1,9 +1,9 @@
-0a8c879bf813b6b758806088f29842dc *./tests/data/lavf/lavf.mpg
+7c9a9a4fb33b441b6ef62a746de92211 *./tests/data/lavf/lavf.mpg
372736 ./tests/data/lavf/lavf.mpg
-./tests/data/lavf/lavf.mpg CRC=0x000e23ae
-d9446ae7b49de006a5a0f052ea9333ca *./tests/data/lavf/lavf.mpg
+./tests/data/lavf/lavf.mpg CRC=0x2b35094c
+eb87c99758bf690007f5c7b334d72b5f *./tests/data/lavf/lavf.mpg
389120 ./tests/data/lavf/lavf.mpg
-./tests/data/lavf/lavf.mpg CRC=0x60ba4ab9
-edfef790122870cf4652e8a92ca558a0 *./tests/data/lavf/lavf.mpg
+./tests/data/lavf/lavf.mpg CRC=0xa4523057
+abf2be603cb723a2290eee5bc3953075 *./tests/data/lavf/lavf.mpg
372736 ./tests/data/lavf/lavf.mpg
-./tests/data/lavf/lavf.mpg CRC=0x000e23ae
+./tests/data/lavf/lavf.mpg CRC=0x2b35094c
diff --git a/tests/ref/lavf/nut b/tests/ref/lavf/nut
index 6c42a40..6153957 100644
--- a/tests/ref/lavf/nut
+++ b/tests/ref/lavf/nut
@@ -1,3 +1,3 @@
-66386a488ee35e4592b605f63ef90a73 *./tests/data/lavf/lavf.nut
+bf8db7cba44c54cb753e93570ec1abb6 *./tests/data/lavf/lavf.nut
319902 ./tests/data/lavf/lavf.nut
-./tests/data/lavf/lavf.nut CRC=0xec6c3c68
+./tests/data/lavf/lavf.nut CRC=0x17a22206
diff --git a/tests/ref/lavf/ts b/tests/ref/lavf/ts
index 02921ed..3f7e422 100644
--- a/tests/ref/lavf/ts
+++ b/tests/ref/lavf/ts
@@ -1,3 +1,3 @@
-a876e6bde8a2e8c7eca878869433ad3b *./tests/data/lavf/lavf.ts
+35e56c0bbfecafadaac18d21358eb2e7 *./tests/data/lavf/lavf.ts
407020 ./tests/data/lavf/lavf.ts
-./tests/data/lavf/lavf.ts CRC=0x71287e25
+./tests/data/lavf/lavf.ts CRC=0x9c4f63c3
diff --git a/tests/ref/lavf/wtv b/tests/ref/lavf/wtv
index fe1b83c..d494f37 100644
--- a/tests/ref/lavf/wtv
+++ b/tests/ref/lavf/wtv
@@ -1,3 +1,3 @@
-98dd5205889313542da71351fbaf4172 *./tests/data/lavf/lavf.wtv
+cfe557e31d8139572f903953c21116e0 *./tests/data/lavf/lavf.wtv
413696 ./tests/data/lavf/lavf.wtv
-./tests/data/lavf/lavf.wtv CRC=0x71287e25
+./tests/data/lavf/lavf.wtv CRC=0x9c4f63c3
--
1.7.9.5
More information about the ffmpeg-devel
mailing list