[FFmpeg-devel] [PATCH] Allow arch-specific mdct code to request interleaving of cos/sin tables
Mans Rullgard
mans
Thu Sep 17 01:46:03 CEST 2009
---
libavcodec/dsputil.h | 3 +++
libavcodec/mdct.c | 27 +++++++++++++++++++--------
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h
index 6c81e3c..c845046 100644
--- a/libavcodec/dsputil.h
+++ b/libavcodec/dsputil.h
@@ -727,6 +727,9 @@ typedef struct MDCTContext {
void (*imdct_calc)(struct MDCTContext *s, FFTSample *output, const FFTSample *input);
void (*imdct_half)(struct MDCTContext *s, FFTSample *output, const FFTSample *input);
void (*mdct_calc)(struct MDCTContext *s, FFTSample *output, const FFTSample *input);
+ int permutation;
+#define FF_MDCT_PERM_NONE 0
+#define FF_MDCT_PERM_INTERLEAVE 1
} MDCTContext;
static inline void ff_imdct_calc(MDCTContext *s, FFTSample *output, const FFTSample *input)
diff --git a/libavcodec/mdct.c b/libavcodec/mdct.c
index dad966d..6a893f9 100644
--- a/libavcodec/mdct.c
+++ b/libavcodec/mdct.c
@@ -76,39 +76,51 @@ av_cold int ff_mdct_init(MDCTContext *s, int nbits, int inverse, double scale)
{
int n, n4, i;
double alpha, theta;
+ int tstep;
memset(s, 0, sizeof(*s));
n = 1 << nbits;
s->nbits = nbits;
s->n = n;
n4 = n >> 2;
- s->tcos = av_malloc(n4 * sizeof(FFTSample));
+ s->tcos = av_malloc(n/2 * sizeof(FFTSample));
if (!s->tcos)
goto fail;
- s->tsin = av_malloc(n4 * sizeof(FFTSample));
- if (!s->tsin)
- goto fail;
s->imdct_calc = ff_imdct_calc_c;
s->imdct_half = ff_imdct_half_c;
s->mdct_calc = ff_mdct_calc_c;
+ s->permutation = FF_MDCT_PERM_NONE;
+
if (ARCH_ARM) ff_mdct_init_arm(s);
if (HAVE_MMX) ff_mdct_init_mmx(s);
+ switch (s->permutation) {
+ case FF_MDCT_PERM_NONE:
+ s->tsin = s->tcos + n4;
+ tstep = 1;
+ break;
+ case FF_MDCT_PERM_INTERLEAVE:
+ s->tsin = s->tcos + 1;
+ tstep = 2;
+ break;
+ default:
+ goto fail;
+ }
+
theta = 1.0 / 8.0 + (scale < 0 ? n4 : 0);
scale = sqrt(fabs(scale));
for(i=0;i<n4;i++) {
alpha = 2 * M_PI * (i + theta) / n;
- s->tcos[i] = -cos(alpha) * scale;
- s->tsin[i] = -sin(alpha) * scale;
+ s->tcos[i*tstep] = -cos(alpha) * scale;
+ s->tsin[i*tstep] = -sin(alpha) * scale;
}
if (ff_fft_init(&s->fft, s->nbits - 2, inverse) < 0)
goto fail;
return 0;
fail:
av_freep(&s->tcos);
- av_freep(&s->tsin);
return -1;
}
@@ -236,6 +248,5 @@ void ff_mdct_calc_c(MDCTContext *s, FFTSample *out, const FFTSample *input)
av_cold void ff_mdct_end(MDCTContext *s)
{
av_freep(&s->tcos);
- av_freep(&s->tsin);
ff_fft_end(&s->fft);
}
--
1.6.4.2
More information about the ffmpeg-devel
mailing list