From 4096cb1830f4957da74e413d2488105e551fb507 Mon Sep 17 00:00:00 2001 From: Andree Buschmann Date: Sat, 10 Sep 2011 10:45:44 +0000 Subject: Further work on libgme's emu2413. Fully remove floating point, introduce another precalculated table, directly use predefined tables instead of copying them. Reduces memory and codesize by several KB. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30494 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/libgme/emu2413.c | 72 ++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 26 deletions(-) (limited to 'apps/codecs/libgme/emu2413.c') diff --git a/apps/codecs/libgme/emu2413.c b/apps/codecs/libgme/emu2413.c index 44782c3dc1..a4637ce15b 100644 --- a/apps/codecs/libgme/emu2413.c +++ b/apps/codecs/libgme/emu2413.c @@ -182,8 +182,21 @@ static e_uint16 halfsintable[PG_WIDTH]; static e_uint16 *waveform[2] = { fullsintable, halfsintable }; /* LFO Table */ -static e_int32 pmtable[PM_PG_WIDTH]; -static e_int32 amtable[AM_PG_WIDTH]; +#ifdef EMU2413_CALCUL_TABLES + static e_int32 pmtable[PM_PG_WIDTH]; + static e_int32 amtable[AM_PG_WIDTH]; + #define PMTABLE(x) pmtable[x] + #define AMTABLE(x) amtable[x] +#else + #define PMTABLE(x) (e_int32)pm_coeff[x] + #if (PM_PG_WIDTH != 256) + #error PM_PG_WIDTH must be set to 256 if EMU2413_CALCUL_TABLES is not defined + #endif + #define AMTABLE(x) (e_int32)am_coeff[x] + #if (AM_PG_WIDTH != 256) + #error AM_PG_WIDTH must be set to 256 if EMU2413_CALCUL_TABLES is not defined + #endif +#endif /* Phase delta for LFO */ static e_uint32 pm_dphase; @@ -193,7 +206,15 @@ static e_uint32 am_dphase; static e_int16 DB2LIN_TABLE[(DB_MUTE + DB_MUTE) * 2]; /* Liner to Log curve conversion table (for Attack rate). */ -static e_uint16 AR_ADJUST_TABLE[1 << EG_BITS]; +#ifdef EMU2413_CALCUL_TABLES + static e_uint16 ar_adjust_table[1 << EG_BITS]; + #define AR_ADJUST_TABLE(x) ar_adjust_table[x] +#else + #define AR_ADJUST_TABLE(x) ar_adjust_coeff[x] + #if (EG_BITS != 7) + #error EG_BITS must be set to 7 if EMU2413_CALCUL_TABLES is not defined + #endif +#endif /* Empty voice data */ static OPLL_PATCH null_patch = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -225,6 +246,7 @@ static e_uint32 dphaseTable[512][8][16]; Create tables ****************************************************/ +#ifdef EMU2413_CALCUL_TABLES INLINE static e_int32 Min (e_int32 i, e_int32 j) { @@ -240,15 +262,11 @@ makeAdjustTable (void) { e_int32 i; - AR_ADJUST_TABLE[0] = (1 << EG_BITS) - 1; + ar_adjust_table[0] = (1 << EG_BITS) - 1; for (i = 1; i < (1<> (3 - KL)) / EG_STEP) + TL2EG (TL); + /* tllTable[fnum][block][TL][KL] = (e_uint32) ((tmp >> (3 - KL)) / EG_STEP) + TL2EG (TL); */ + tllTable[fnum][block][TL][KL] = (e_uint32) ((tmp << KL) / (int)(EG_STEP*8)) + TL2EG (TL); } } } @@ -727,7 +745,7 @@ INLINE static void slotOff (OPLL_SLOT * slot) { if (slot->eg_mode == ATTACK) - slot->eg_phase = EXPAND_BITS (AR_ADJUST_TABLE[HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS)], EG_BITS, EG_DP_BITS); + slot->eg_phase = EXPAND_BITS (AR_ADJUST_TABLE(HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS)), EG_BITS, EG_DP_BITS); slot->eg_mode = RELEASE; UPDATE_EG(slot); } @@ -993,8 +1011,8 @@ internal_refresh (void) #endif makeDphaseARTable (); makeDphaseDRTable (); - pm_dphase = (e_uint32) RATE_ADJUST (PM_SPEED * PM_DP_WIDTH / (clk / 72)); - am_dphase = (e_uint32) RATE_ADJUST (AM_SPEED * AM_DP_WIDTH / (clk / 72)); + pm_dphase = (e_uint32) RATE_ADJUST ((int)(PM_SPEED * PM_DP_WIDTH) / (clk / 72)); + am_dphase = (e_uint32) RATE_ADJUST ((int)(AM_SPEED * AM_DP_WIDTH) / (clk / 72)); } static void @@ -1003,10 +1021,12 @@ maketables (e_uint32 c, e_uint32 r) if (c != clk) { clk = c; +#ifdef EMU2413_CALCUL_TABLES makePmTable (); makeAmTable (); - makeDB2LinTable (); makeAdjustTable (); +#endif + makeDB2LinTable (); makeTllTable (); makeRksTable (); makeSinTable (); @@ -1173,8 +1193,8 @@ update_ampm (OPLL * opll) { opll->pm_phase = (opll->pm_phase + pm_dphase) & (PM_DP_WIDTH - 1); opll->am_phase = (opll->am_phase + am_dphase) & (AM_DP_WIDTH - 1); - opll->lfo_am = amtable[HIGHBITS (opll->am_phase, AM_DP_BITS - AM_PG_BITS)]; - opll->lfo_pm = pmtable[HIGHBITS (opll->pm_phase, PM_DP_BITS - PM_PG_BITS)]; + opll->lfo_am = AMTABLE(HIGHBITS (opll->am_phase, AM_DP_BITS - AM_PG_BITS)); + opll->lfo_pm = PMTABLE(HIGHBITS (opll->pm_phase, PM_DP_BITS - PM_PG_BITS)); } /* PG */ @@ -1215,7 +1235,7 @@ calc_envelope (OPLL_SLOT * slot, e_int32 lfo) switch (slot->eg_mode) { case ATTACK: - egout = AR_ADJUST_TABLE[HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS)]; + egout = AR_ADJUST_TABLE(HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS)); slot->eg_phase += slot->eg_dphase; if((EG_DP_WIDTH & slot->eg_phase)||(slot->patch->AR==15)) { -- cgit v1.2.3