From cc518c5f32daa7b40bc84fd1e98addefbb4f9d76 Mon Sep 17 00:00:00 2001 From: Thom Johansen Date: Thu, 9 Jun 2005 14:13:09 +0000 Subject: Full precision synth_full and dct32. Replaced all multiplications with proper 64 bit EMAC multiplications, which yields improved sound. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6638 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/libmad/Makefile | 3 ++- apps/codecs/libmad/fixed.h | 23 ++++++++++++++++++++ apps/codecs/libmad/global.h | 6 +++++ apps/codecs/libmad/synth.c | 53 +++++++++++++++++++++++++++++---------------- 4 files changed, 65 insertions(+), 20 deletions(-) (limited to 'apps/codecs') diff --git a/apps/codecs/libmad/Makefile b/apps/codecs/libmad/Makefile index e3ba245513..a6f310195c 100644 --- a/apps/codecs/libmad/Makefile +++ b/apps/codecs/libmad/Makefile @@ -14,7 +14,8 @@ ifdef APPEXTRA INCLUDES += -I$(APPSDIR)/$(APPEXTRA) endif -MADOPTS = -DFPM_DEFAULT -DNDEBUG -O2 +# NOTE: FPM_ define has been moved to global.h +MADOPTS = -DNDEBUG -O2 CFLAGS = $(GCCOPTS) $(MADOPTS)\ $(INCLUDES) $(TARGET) $(EXTRA_DEFINES) -DMEM=${MEMORYSIZE} diff --git a/apps/codecs/libmad/fixed.h b/apps/codecs/libmad/fixed.h index baa7dc59c8..7ccf1cb4ed 100644 --- a/apps/codecs/libmad/fixed.h +++ b/apps/codecs/libmad/fixed.h @@ -420,6 +420,29 @@ mad_fixed_t mad_f_mul_inline(mad_fixed_t x, mad_fixed_t y) # define MAD_F_SCALEBITS MAD_F_FRACBITS +# elif defined(FPM_COLDFIRE_EMAC) + +/* mad_f_mul using the Coldfire MCF5249 EMAC unit. Loses 3 bits of accuracy. + Note that we don't define any of the libmad accumulator macros, as + any functions that use these should have the relevant sections rewritten + in assembler to utilise the EMAC accumulators properly. + Assumes the default +/- 3.28 fixed point format + */ +#define mad_f_mul(x, y) \ +({ \ + mad_fixed64hi_t hi; \ + asm volatile("mac.l %[a], %[b], %%acc0\n\t" \ + "movclr.l %%acc0, %[hi]\n\t" \ + "asl.l #3, %[hi]" \ + : [hi] "=d" (hi) \ + : [a] "r" ((x)), [b] "r" ((y))); \ + hi; \ +}) +/* Define dummy mad_f_scale64 to prevent libmad from defining MAD_F_SCALEBITS + below. Having MAD_F_SCALEBITS defined screws up the PRESHIFT macro in synth.h + */ +#define mad_f_scale64(hi, lo) (lo) + /* --- Default ------------------------------------------------------------- */ # elif defined(FPM_DEFAULT) diff --git a/apps/codecs/libmad/global.h b/apps/codecs/libmad/global.h index 8669bf9044..bba9f062bf 100644 --- a/apps/codecs/libmad/global.h +++ b/apps/codecs/libmad/global.h @@ -24,6 +24,12 @@ # ifndef LIBMAD_GLOBAL_H # define LIBMAD_GLOBAL_H +#if CONFIG_CPU==MCF5249 && !defined(SIMULATOR) +#define FPM_COLDFIRE_EMAC +#else +#define FPM_DEFAULT +#endif + /* conditional debugging */ # if defined(DEBUG) && defined(NDEBUG) diff --git a/apps/codecs/libmad/synth.c b/apps/codecs/libmad/synth.c index 166e3d9f3a..bdec4258fb 100644 --- a/apps/codecs/libmad/synth.c +++ b/apps/codecs/libmad/synth.c @@ -102,7 +102,21 @@ void mad_synth_mute(struct mad_synth *synth) /* possible DCT speed optimization */ -# if defined(OPT_SPEED) && defined(MAD_F_MLX) +/* This is a Coldfire version of the OPT_SPEED optimisation below, but in the + case of Coldfire it doesn't lose any more precision than we would ordinarily + lose, */ +# ifdef FPM_COLDFIRE_EMAC +# define OPT_DCTO +# define MUL(x, y) \ + ({ \ + mad_fixed64hi_t hi; \ + asm volatile("mac.l %[a], %[b], %%acc0\n\t" \ + "movclr.l %%acc0, %[hi]" \ + : [hi] "=r" (hi) \ + : [a] "r" ((x)), [b] "r" ((y))); \ + hi; \ + }) +# elif defined(OPT_SPEED) && defined(MAD_F_MLX) # define OPT_DCTO # define MUL(x, y) \ ({ mad_fixed64hi_t hi; \ @@ -555,8 +569,8 @@ void synth_full(struct mad_synth *, struct mad_frame const *, * DESCRIPTION: perform full frequency PCM synthesis */ -/* optimised version of synth full, requires OPT_SSO at the moment */ -# if CONFIG_CPU==MCF5249 && defined(OPT_SSO) && !defined(SIMULATOR) +/* optimised version of synth_full */ +# ifdef FPM_COLDFIRE_EMAC static void synth_full(struct mad_synth *synth, struct mad_frame const *frame, unsigned int nch, unsigned int ns) @@ -566,10 +580,9 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame, mad_fixed_t const (*sbsample)[36][32]; mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8]; mad_fixed_t const (*Dptr)[32]; - mad_fixed64hi_t hi = 0; - mad_fixed64lo_t lo; + mad_fixed64hi_t hi; - asm volatile("move.l #0, %macsr"); /* need integer mode */ + asm volatile("move.l #0x20, %macsr"); /* fractional mode */ for (ch = 0; ch < nch; ++ch) { sbsample = &frame->sbsample[ch]; @@ -613,10 +626,12 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame, "mac.l %%d5, %%a5, 16(%4), %%a5, %%acc0\n\t" "mac.l %%d6, %%a5, 8(%4), %%a5, %%acc0\n\t" "mac.l %%d7, %%a5, %%acc0\n\t" - "movclr.l %%acc0, %0" - : "=ad" (lo) : "a" (*fx), "a" (*Dptr + po), "a" (*fe), "a" (*Dptr + pe) : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5"); + "movclr.l %%acc0, %0\n\t" + : "=r" (hi) + : "a" (*fx), "a" (*Dptr + po), "a" (*fe), "a" (*Dptr + pe) + : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5"); - *pcm1++ = SHIFT(MLZ(hi, lo)); + *pcm1++ = hi << 3; /* shift result to libmad's fixed point format */ pcm2 = pcm1 + 30; @@ -646,13 +661,13 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame, "mac.l %%d2, %%a5, 56(%4), %%a5, %%acc0\n\t" "mac.l %%d1, %%a5, (%4), %%a5, %%acc0\n\t" "mac.l %%d0, %%a5, %%acc0\n\t" - "movclr.l %%acc0, %0" - : "=ad" (lo) + "movclr.l %%acc0, %0\n\t" + : "=r" (hi) : "a" (*fo), "a" (*Dptr + po), "a" (*fe), "a" (*Dptr + pe) : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5"); - *pcm1++ = SHIFT(MLZ(hi, lo)); - + *pcm1++ = hi << 3; + asm volatile( "movem.l (%1), %%d0-%%d7\n\t" "move.l 60(%2), %%a5\n\t" @@ -674,12 +689,12 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame, "mac.l %%d2, %%a5, 68(%4), %%a5, %%acc0\n\t" "mac.l %%d1, %%a5, 60(%4), %%a5, %%acc0\n\t" "mac.l %%d0, %%a5, %%acc0\n\t" - "movclr.l %%acc0, %0" - : "=ad" (lo) + "movclr.l %%acc0, %0\n\t" + : "=r" (hi) : "a" (*fe), "a" (*Dptr - pe), "a" (*fo), "a" (*Dptr - po) : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5"); - *pcm2-- = SHIFT(MLZ(hi, lo)); + *pcm2-- = hi << 3; ++fo; } @@ -696,11 +711,11 @@ void synth_full(struct mad_synth *synth, struct mad_frame const *frame, "mac.l %%d5, %%a5, 16(%2), %%a5, %%acc0\n\t" "mac.l %%d6, %%a5, 8(%2), %%a5, %%acc0\n\t" "mac.l %%d7, %%a5, %%acc0\n\t" - "movclr.l %%acc0, %0" - : "=ad" (lo) : "a" (*fo), "a" (*Dptr + po) + "movclr.l %%acc0, %0\n\t" + : "=r" (hi) : "a" (*fo), "a" (*Dptr + po) : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5"); - *pcm1 = SHIFT(-MLZ(hi, lo)); + *pcm1 = -(hi << 3); pcm1 += 16; phase = (phase + 1) % 16; -- cgit v1.2.3