diff options
author | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-09-10 10:45:44 +0000 |
---|---|---|
committer | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-09-10 10:45:44 +0000 |
commit | 4096cb1830f4957da74e413d2488105e551fb507 (patch) | |
tree | f2720d043831e12f5676c690a49839efca471679 /apps/codecs | |
parent | e8dc7a6d0702c6724c4b3b9a4cf8efb7c6f712c9 (diff) | |
download | rockbox-4096cb1830f4957da74e413d2488105e551fb507.tar.gz rockbox-4096cb1830f4957da74e413d2488105e551fb507.zip |
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
Diffstat (limited to 'apps/codecs')
-rw-r--r-- | apps/codecs/libgme/emu2413.c | 72 | ||||
-rw-r--r-- | apps/codecs/libgme/emutables.h | 42 |
2 files changed, 87 insertions, 27 deletions
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]; | |||
182 | static e_uint16 *waveform[2] = { fullsintable, halfsintable }; | 182 | static e_uint16 *waveform[2] = { fullsintable, halfsintable }; |
183 | 183 | ||
184 | /* LFO Table */ | 184 | /* LFO Table */ |
185 | static e_int32 pmtable[PM_PG_WIDTH]; | 185 | #ifdef EMU2413_CALCUL_TABLES |
186 | static e_int32 amtable[AM_PG_WIDTH]; | 186 | static e_int32 pmtable[PM_PG_WIDTH]; |
187 | static e_int32 amtable[AM_PG_WIDTH]; | ||
188 | #define PMTABLE(x) pmtable[x] | ||
189 | #define AMTABLE(x) amtable[x] | ||
190 | #else | ||
191 | #define PMTABLE(x) (e_int32)pm_coeff[x] | ||
192 | #if (PM_PG_WIDTH != 256) | ||
193 | #error PM_PG_WIDTH must be set to 256 if EMU2413_CALCUL_TABLES is not defined | ||
194 | #endif | ||
195 | #define AMTABLE(x) (e_int32)am_coeff[x] | ||
196 | #if (AM_PG_WIDTH != 256) | ||
197 | #error AM_PG_WIDTH must be set to 256 if EMU2413_CALCUL_TABLES is not defined | ||
198 | #endif | ||
199 | #endif | ||
187 | 200 | ||
188 | /* Phase delta for LFO */ | 201 | /* Phase delta for LFO */ |
189 | static e_uint32 pm_dphase; | 202 | static e_uint32 pm_dphase; |
@@ -193,7 +206,15 @@ static e_uint32 am_dphase; | |||
193 | static e_int16 DB2LIN_TABLE[(DB_MUTE + DB_MUTE) * 2]; | 206 | static e_int16 DB2LIN_TABLE[(DB_MUTE + DB_MUTE) * 2]; |
194 | 207 | ||
195 | /* Liner to Log curve conversion table (for Attack rate). */ | 208 | /* Liner to Log curve conversion table (for Attack rate). */ |
196 | static e_uint16 AR_ADJUST_TABLE[1 << EG_BITS]; | 209 | #ifdef EMU2413_CALCUL_TABLES |
210 | static e_uint16 ar_adjust_table[1 << EG_BITS]; | ||
211 | #define AR_ADJUST_TABLE(x) ar_adjust_table[x] | ||
212 | #else | ||
213 | #define AR_ADJUST_TABLE(x) ar_adjust_coeff[x] | ||
214 | #if (EG_BITS != 7) | ||
215 | #error EG_BITS must be set to 7 if EMU2413_CALCUL_TABLES is not defined | ||
216 | #endif | ||
217 | #endif | ||
197 | 218 | ||
198 | /* Empty voice data */ | 219 | /* Empty voice data */ |
199 | static OPLL_PATCH null_patch = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | 220 | 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]; | |||
225 | Create tables | 246 | Create tables |
226 | 247 | ||
227 | ****************************************************/ | 248 | ****************************************************/ |
249 | #ifdef EMU2413_CALCUL_TABLES | ||
228 | INLINE static e_int32 | 250 | INLINE static e_int32 |
229 | Min (e_int32 i, e_int32 j) | 251 | Min (e_int32 i, e_int32 j) |
230 | { | 252 | { |
@@ -240,15 +262,11 @@ makeAdjustTable (void) | |||
240 | { | 262 | { |
241 | e_int32 i; | 263 | e_int32 i; |
242 | 264 | ||
243 | AR_ADJUST_TABLE[0] = (1 << EG_BITS) - 1; | 265 | ar_adjust_table[0] = (1 << EG_BITS) - 1; |
244 | for (i = 1; i < (1<<EG_BITS); i++) | 266 | for (i = 1; i < (1<<EG_BITS); i++) |
245 | #ifdef EMU2413_CALCUL_TABLES | 267 | ar_adjust_table[i] = (e_uint16) ((double) (1<<EG_BITS)-1 - ((1<<EG_BITS)-1)*log(i)/log(127)); |
246 | AR_ADJUST_TABLE[i] = (e_uint16) ((double) (1<<EG_BITS)-1 - ((1<<EG_BITS)-1)*log(i)/log(127)); | ||
247 | #else | ||
248 | AR_ADJUST_TABLE[i] = ar_adjust_coeff[i]; | ||
249 | #endif | ||
250 | } | 268 | } |
251 | 269 | #endif | |
252 | 270 | ||
253 | /* Table for dB(0 -- (1<<DB_BITS)-1) to Liner(0 -- DB2LIN_AMP_WIDTH) */ | 271 | /* Table for dB(0 -- (1<<DB_BITS)-1) to Liner(0 -- DB2LIN_AMP_WIDTH) */ |
254 | static void | 272 | static void |
@@ -308,6 +326,7 @@ makeSinTable (void) | |||
308 | halfsintable[i] = fullsintable[0]; | 326 | halfsintable[i] = fullsintable[0]; |
309 | } | 327 | } |
310 | 328 | ||
329 | #ifdef EMU2413_CALCUL_TABLES | ||
311 | static double saw(double phase) | 330 | static double saw(double phase) |
312 | { | 331 | { |
313 | if(phase <= PI/2) | 332 | if(phase <= PI/2) |
@@ -326,11 +345,7 @@ makePmTable (void) | |||
326 | 345 | ||
327 | for (i = 0; i < PM_PG_WIDTH; i++) | 346 | for (i = 0; i < PM_PG_WIDTH; i++) |
328 | /* pmtable[i] = (e_int32) ((double) PM_AMP * pow (2, (double) PM_DEPTH * sin (2.0 * PI * i / PM_PG_WIDTH) / 1200)); */ | 347 | /* pmtable[i] = (e_int32) ((double) PM_AMP * pow (2, (double) PM_DEPTH * sin (2.0 * PI * i / PM_PG_WIDTH) / 1200)); */ |
329 | #ifdef EMU2413_CALCUL_TABLES | ||
330 | pmtable[i] = (e_int32) ((double) PM_AMP * pow (2, (double) PM_DEPTH * saw (2.0 * PI * i / PM_PG_WIDTH) / 1200)); | 348 | pmtable[i] = (e_int32) ((double) PM_AMP * pow (2, (double) PM_DEPTH * saw (2.0 * PI * i / PM_PG_WIDTH) / 1200)); |
331 | #else | ||
332 | pmtable[i] = pm_coeff[i]; | ||
333 | #endif | ||
334 | } | 349 | } |
335 | 350 | ||
336 | /* Table for Amp Modulator */ | 351 | /* Table for Amp Modulator */ |
@@ -343,6 +358,7 @@ makeAmTable (void) | |||
343 | /* amtable[i] = (e_int32) ((double) AM_DEPTH / 2 / DB_STEP * (1.0 + sin (2.0 * PI * i / PM_PG_WIDTH))); */ | 358 | /* amtable[i] = (e_int32) ((double) AM_DEPTH / 2 / DB_STEP * (1.0 + sin (2.0 * PI * i / PM_PG_WIDTH))); */ |
344 | amtable[i] = (e_int32) ((double) AM_DEPTH / 2 / DB_STEP * (1.0 + saw (2.0 * PI * i / PM_PG_WIDTH))); | 359 | amtable[i] = (e_int32) ((double) AM_DEPTH / 2 / DB_STEP * (1.0 + saw (2.0 * PI * i / PM_PG_WIDTH))); |
345 | } | 360 | } |
361 | #endif | ||
346 | 362 | ||
347 | #if !defined(ROCKBOX) | 363 | #if !defined(ROCKBOX) |
348 | /* Phase increment counter table */ | 364 | /* Phase increment counter table */ |
@@ -363,10 +379,11 @@ makeDphaseTable (void) | |||
363 | static void | 379 | static void |
364 | makeTllTable (void) | 380 | makeTllTable (void) |
365 | { | 381 | { |
366 | #define dB2(x) ((x)*2) | 382 | /* Multiplication owith 8 to have an integer result. This allows to remove floating point operation. */ |
383 | #define dB2(x) (int)((x)*2*8) | ||
367 | 384 | ||
368 | static double kltable[16] = { | 385 | static int kltable[16] = { |
369 | dB2 (0.000), dB2 (9.000), dB2 (12.000), dB2 (13.875), dB2 (15.000), dB2 (16.125), dB2 (16.875), dB2 (17.625), | 386 | dB2 ( 0.000), dB2 ( 9.000), dB2 (12.000), dB2 (13.875), dB2 (15.000), dB2 (16.125), dB2 (16.875), dB2 (17.625), |
370 | dB2 (18.000), dB2 (18.750), dB2 (19.125), dB2 (19.500), dB2 (19.875), dB2 (20.250), dB2 (20.625), dB2 (21.000) | 387 | dB2 (18.000), dB2 (18.750), dB2 (19.125), dB2 (19.500), dB2 (19.875), dB2 (20.250), dB2 (20.625), dB2 (21.000) |
371 | }; | 388 | }; |
372 | 389 | ||
@@ -384,11 +401,12 @@ makeTllTable (void) | |||
384 | } | 401 | } |
385 | else | 402 | else |
386 | { | 403 | { |
387 | tmp = (e_int32) (kltable[fnum] - dB2 (3.000) * (7 - block)); | 404 | tmp = (e_int32) ((kltable[fnum] - dB2 (3.000) * (7 - block))/8); |
388 | if (tmp <= 0) | 405 | if (tmp <= 0) |
389 | tllTable[fnum][block][TL][KL] = TL2EG (TL); | 406 | tllTable[fnum][block][TL][KL] = TL2EG (TL); |
390 | else | 407 | else |
391 | tllTable[fnum][block][TL][KL] = (e_uint32) ((tmp >> (3 - KL)) / EG_STEP) + TL2EG (TL); | 408 | /* tllTable[fnum][block][TL][KL] = (e_uint32) ((tmp >> (3 - KL)) / EG_STEP) + TL2EG (TL); */ |
409 | tllTable[fnum][block][TL][KL] = (e_uint32) ((tmp << KL) / (int)(EG_STEP*8)) + TL2EG (TL); | ||
392 | } | 410 | } |
393 | } | 411 | } |
394 | } | 412 | } |
@@ -727,7 +745,7 @@ INLINE static void | |||
727 | slotOff (OPLL_SLOT * slot) | 745 | slotOff (OPLL_SLOT * slot) |
728 | { | 746 | { |
729 | if (slot->eg_mode == ATTACK) | 747 | if (slot->eg_mode == ATTACK) |
730 | slot->eg_phase = EXPAND_BITS (AR_ADJUST_TABLE[HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS)], EG_BITS, EG_DP_BITS); | 748 | slot->eg_phase = EXPAND_BITS (AR_ADJUST_TABLE(HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS)), EG_BITS, EG_DP_BITS); |
731 | slot->eg_mode = RELEASE; | 749 | slot->eg_mode = RELEASE; |
732 | UPDATE_EG(slot); | 750 | UPDATE_EG(slot); |
733 | } | 751 | } |
@@ -993,8 +1011,8 @@ internal_refresh (void) | |||
993 | #endif | 1011 | #endif |
994 | makeDphaseARTable (); | 1012 | makeDphaseARTable (); |
995 | makeDphaseDRTable (); | 1013 | makeDphaseDRTable (); |
996 | pm_dphase = (e_uint32) RATE_ADJUST (PM_SPEED * PM_DP_WIDTH / (clk / 72)); | 1014 | pm_dphase = (e_uint32) RATE_ADJUST ((int)(PM_SPEED * PM_DP_WIDTH) / (clk / 72)); |
997 | am_dphase = (e_uint32) RATE_ADJUST (AM_SPEED * AM_DP_WIDTH / (clk / 72)); | 1015 | am_dphase = (e_uint32) RATE_ADJUST ((int)(AM_SPEED * AM_DP_WIDTH) / (clk / 72)); |
998 | } | 1016 | } |
999 | 1017 | ||
1000 | static void | 1018 | static void |
@@ -1003,10 +1021,12 @@ maketables (e_uint32 c, e_uint32 r) | |||
1003 | if (c != clk) | 1021 | if (c != clk) |
1004 | { | 1022 | { |
1005 | clk = c; | 1023 | clk = c; |
1024 | #ifdef EMU2413_CALCUL_TABLES | ||
1006 | makePmTable (); | 1025 | makePmTable (); |
1007 | makeAmTable (); | 1026 | makeAmTable (); |
1008 | makeDB2LinTable (); | ||
1009 | makeAdjustTable (); | 1027 | makeAdjustTable (); |
1028 | #endif | ||
1029 | makeDB2LinTable (); | ||
1010 | makeTllTable (); | 1030 | makeTllTable (); |
1011 | makeRksTable (); | 1031 | makeRksTable (); |
1012 | makeSinTable (); | 1032 | makeSinTable (); |
@@ -1173,8 +1193,8 @@ update_ampm (OPLL * opll) | |||
1173 | { | 1193 | { |
1174 | opll->pm_phase = (opll->pm_phase + pm_dphase) & (PM_DP_WIDTH - 1); | 1194 | opll->pm_phase = (opll->pm_phase + pm_dphase) & (PM_DP_WIDTH - 1); |
1175 | opll->am_phase = (opll->am_phase + am_dphase) & (AM_DP_WIDTH - 1); | 1195 | opll->am_phase = (opll->am_phase + am_dphase) & (AM_DP_WIDTH - 1); |
1176 | opll->lfo_am = amtable[HIGHBITS (opll->am_phase, AM_DP_BITS - AM_PG_BITS)]; | 1196 | opll->lfo_am = AMTABLE(HIGHBITS (opll->am_phase, AM_DP_BITS - AM_PG_BITS)); |
1177 | opll->lfo_pm = pmtable[HIGHBITS (opll->pm_phase, PM_DP_BITS - PM_PG_BITS)]; | 1197 | opll->lfo_pm = PMTABLE(HIGHBITS (opll->pm_phase, PM_DP_BITS - PM_PG_BITS)); |
1178 | } | 1198 | } |
1179 | 1199 | ||
1180 | /* PG */ | 1200 | /* PG */ |
@@ -1215,7 +1235,7 @@ calc_envelope (OPLL_SLOT * slot, e_int32 lfo) | |||
1215 | switch (slot->eg_mode) | 1235 | switch (slot->eg_mode) |
1216 | { | 1236 | { |
1217 | case ATTACK: | 1237 | case ATTACK: |
1218 | egout = AR_ADJUST_TABLE[HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS)]; | 1238 | egout = AR_ADJUST_TABLE(HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS)); |
1219 | slot->eg_phase += slot->eg_dphase; | 1239 | slot->eg_phase += slot->eg_dphase; |
1220 | if((EG_DP_WIDTH & slot->eg_phase)||(slot->patch->AR==15)) | 1240 | if((EG_DP_WIDTH & slot->eg_phase)||(slot->patch->AR==15)) |
1221 | { | 1241 | { |
diff --git a/apps/codecs/libgme/emutables.h b/apps/codecs/libgme/emutables.h index 173ecd22c6..e34f100bc4 100644 --- a/apps/codecs/libgme/emutables.h +++ b/apps/codecs/libgme/emutables.h | |||
@@ -28,7 +28,7 @@ static const e_uint16 sin_coeff[] = { | |||
28 | 0, 0, | 28 | 0, 0, |
29 | }; | 29 | }; |
30 | 30 | ||
31 | static const e_int32 pm_coeff[] = { | 31 | static const e_int16 pm_coeff[] = { |
32 | 256, 256, 256, 256, 256, 256, 256, | 32 | 256, 256, 256, 256, 256, 256, 256, |
33 | 256, 256, 256, 256, 256, 256, 256, | 33 | 256, 256, 256, 256, 256, 256, 256, |
34 | 256, 256, 256, 256, 256, 256, 256, | 34 | 256, 256, 256, 256, 256, 256, 256, |
@@ -68,6 +68,46 @@ static const e_int32 pm_coeff[] = { | |||
68 | 255, 255, 255, 255, | 68 | 255, 255, 255, 255, |
69 | }; | 69 | }; |
70 | 70 | ||
71 | static const e_int8 am_coeff[] = { | ||
72 | 13, 13, 13, 13, 13, 14, 14, | ||
73 | 14, 14, 14, 15, 15, 15, 15, | ||
74 | 15, 16, 16, 16, 16, 16, 17, | ||
75 | 17, 17, 17, 17, 18, 18, 18, | ||
76 | 18, 18, 19, 19, 19, 19, 19, | ||
77 | 20, 20, 20, 20, 20, 21, 21, | ||
78 | 21, 21, 21, 22, 22, 22, 22, | ||
79 | 22, 23, 23, 23, 23, 23, 24, | ||
80 | 24, 24, 24, 24, 25, 25, 25, | ||
81 | 25, 26, 25, 25, 25, 25, 24, | ||
82 | 24, 24, 24, 24, 23, 23, 23, | ||
83 | 23, 23, 22, 22, 22, 22, 22, | ||
84 | 21, 21, 21, 21, 21, 20, 20, | ||
85 | 20, 20, 20, 19, 19, 19, 19, | ||
86 | 19, 18, 18, 18, 18, 18, 17, | ||
87 | 17, 17, 17, 17, 16, 16, 16, | ||
88 | 16, 16, 15, 15, 15, 15, 15, | ||
89 | 14, 14, 14, 14, 14, 13, 13, | ||
90 | 13, 13, 13, 12, 12, 12, 12, | ||
91 | 11, 11, 11, 11, 11, 10, 10, | ||
92 | 10, 10, 10, 9, 9, 9, 9, | ||
93 | 9, 8, 8, 8, 8, 8, 7, | ||
94 | 7, 7, 7, 7, 6, 6, 6, | ||
95 | 6, 6, 5, 5, 5, 5, 5, | ||
96 | 4, 4, 4, 4, 4, 3, 3, | ||
97 | 3, 3, 3, 2, 2, 2, 2, | ||
98 | 2, 1, 1, 1, 1, 1, 0, | ||
99 | 0, 0, 0, 0, 0, 0, 0, | ||
100 | 0, 1, 1, 1, 1, 1, 2, | ||
101 | 2, 2, 2, 2, 3, 3, 3, | ||
102 | 3, 3, 4, 4, 4, 4, 4, | ||
103 | 5, 5, 5, 5, 5, 6, 6, | ||
104 | 6, 6, 6, 7, 7, 7, 7, | ||
105 | 7, 8, 8, 8, 8, 8, 9, | ||
106 | 9, 9, 9, 9, 10, 10, 10, | ||
107 | 10, 10, 11, 11, 11, 11, 11, | ||
108 | 12, 12, 12, 12, | ||
109 | }; | ||
110 | |||
71 | static const e_int16 db2lin_coeff[] = { | 111 | static const e_int16 db2lin_coeff[] = { |
72 | 255, 249, 244, 239, 233, 228, 224, | 112 | 255, 249, 244, 239, 233, 228, 224, |
73 | 219, 214, 209, 205, 201, 196, 192, | 113 | 219, 214, 209, 205, 201, 196, 192, |