summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/codecs/libgme/emu2413.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/apps/codecs/libgme/emu2413.c b/apps/codecs/libgme/emu2413.c
index def6d60b7f..48f32d8e57 100644
--- a/apps/codecs/libgme/emu2413.c
+++ b/apps/codecs/libgme/emu2413.c
@@ -93,8 +93,9 @@ static unsigned char default_inst[OPLL_TONE_NUM][(16 + 3) * 16] = {
93#define DP_BASE_BITS (DP_BITS - PG_BITS) 93#define DP_BASE_BITS (DP_BITS - PG_BITS)
94 94
95/* Dynamic range (Accuracy of sin table) */ 95/* Dynamic range (Accuracy of sin table) */
96#define DB_PREC 48
96#define DB_BITS 8 97#define DB_BITS 8
97#define DB_STEP (48.0/(1<<DB_BITS)) 98#define DB_STEP ((double)DB_PREC/(1<<DB_BITS))
98#define DB_MUTE (1<<DB_BITS) 99#define DB_MUTE (1<<DB_BITS)
99 100
100/* Dynamic range of envelope */ 101/* Dynamic range of envelope */
@@ -116,8 +117,8 @@ static unsigned char default_inst[OPLL_TONE_NUM][(16 + 3) * 16] = {
116#define TL2EG(d) ((d)*(e_int32)(TL_STEP/EG_STEP)) 117#define TL2EG(d) ((d)*(e_int32)(TL_STEP/EG_STEP))
117#define SL2EG(d) ((d)*(e_int32)(SL_STEP/EG_STEP)) 118#define SL2EG(d) ((d)*(e_int32)(SL_STEP/EG_STEP))
118 119
119#define DB_POS(x) (e_uint32)((x)/DB_STEP) 120#define DB_POS(x) (x*DB_MUTE/DB_PREC)
120#define DB_NEG(x) (e_uint32)(DB_MUTE+DB_MUTE+(x)/DB_STEP) 121#define DB_NEG(x) (DB_MUTE+DB_MUTE+x*DB_MUTE/DB_PREC)
121 122
122/* Bits for liner value */ 123/* Bits for liner value */
123#define DB2LIN_AMP_BITS 8 124#define DB2LIN_AMP_BITS 8
@@ -162,7 +163,7 @@ static unsigned char default_inst[OPLL_TONE_NUM][(16 + 3) * 16] = {
162#define EXPAND_BITS_X(x,s,d) (((x)<<((d)-(s)))|((1<<((d)-(s)))-1)) 163#define EXPAND_BITS_X(x,s,d) (((x)<<((d)-(s)))|((1<<((d)-(s)))-1))
163 164
164/* Adjust envelope speed which depends on sampling rate. */ 165/* Adjust envelope speed which depends on sampling rate. */
165#define RATE_ADJUST(x) (rate==49716?(e_uint32)x:(e_uint32)((double)(x)*clk/72/rate + 0.5)) /* added 0.5 to round the value*/ 166#define RATE_ADJUST(x) (rate==49716?(e_uint32)x:(e_uint32)(((long long)(x)*clk/rate+36)/72))
166 167
167#define MOD(o,x) (&(o)->slot[(x)<<1]) 168#define MOD(o,x) (&(o)->slot[(x)<<1])
168#define CAR(o,x) (&(o)->slot[((x)<<1)|1]) 169#define CAR(o,x) (&(o)->slot[((x)<<1)|1])
@@ -1167,7 +1168,7 @@ OPLL_set_quality (OPLL * opll, e_uint32 q)
1167#endif 1168#endif
1168 1169
1169/* Update AM, PM unit */ 1170/* Update AM, PM unit */
1170static void 1171INLINE static void
1171update_ampm (OPLL * opll) 1172update_ampm (OPLL * opll)
1172{ 1173{
1173 opll->pm_phase = (opll->pm_phase + pm_dphase) & (PM_DP_WIDTH - 1); 1174 opll->pm_phase = (opll->pm_phase + pm_dphase) & (PM_DP_WIDTH - 1);
@@ -1191,7 +1192,7 @@ calc_phase (OPLL_SLOT * slot, e_int32 lfo)
1191} 1192}
1192 1193
1193/* Update Noise unit */ 1194/* Update Noise unit */
1194static void 1195INLINE static void
1195update_noise (OPLL * opll) 1196update_noise (OPLL * opll)
1196{ 1197{
1197 if(opll->noise_seed&1) opll->noise_seed ^= 0x8003020; 1198 if(opll->noise_seed&1) opll->noise_seed ^= 0x8003020;
@@ -1199,7 +1200,7 @@ update_noise (OPLL * opll)
1199} 1200}
1200 1201
1201/* EG */ 1202/* EG */
1202static void 1203INLINE static void
1203calc_envelope (OPLL_SLOT * slot, e_int32 lfo) 1204calc_envelope (OPLL_SLOT * slot, e_int32 lfo)
1204{ 1205{
1205#define S2E(x) (SL2EG((e_int32)(x/SL_STEP))<<(EG_DP_BITS-EG_BITS)) 1206#define S2E(x) (SL2EG((e_int32)(x/SL_STEP))<<(EG_DP_BITS-EG_BITS))
@@ -1360,9 +1361,9 @@ calc_slot_snare (OPLL_SLOT * slot, e_uint32 noise)
1360 return 0; 1361 return 0;
1361 1362
1362 if(BIT(slot->pgout,7)) 1363 if(BIT(slot->pgout,7))
1363 return DB2LIN_TABLE[(noise?DB_POS(0.0):DB_POS(15.0))+slot->egout]; 1364 return DB2LIN_TABLE[(noise?DB_POS(0):DB_POS(15))+slot->egout];
1364 else 1365 else
1365 return DB2LIN_TABLE[(noise?DB_NEG(0.0):DB_NEG(15.0))+slot->egout]; 1366 return DB2LIN_TABLE[(noise?DB_NEG(0):DB_NEG(15))+slot->egout];
1366} 1367}
1367 1368
1368/* 1369/*
@@ -1381,9 +1382,9 @@ calc_slot_cym (OPLL_SLOT * slot, e_uint32 pgout_hh)
1381 /* different from fmopl.c */ 1382 /* different from fmopl.c */
1382 (BIT(slot->pgout,PG_BITS-7)&!BIT(slot->pgout,PG_BITS-5)) 1383 (BIT(slot->pgout,PG_BITS-7)&!BIT(slot->pgout,PG_BITS-5))
1383 ) 1384 )
1384 dbout = DB_NEG(3.0); 1385 dbout = DB_NEG(3);
1385 else 1386 else
1386 dbout = DB_POS(3.0); 1387 dbout = DB_POS(3);
1387 1388
1388 return DB2LIN_TABLE[dbout + slot->egout]; 1389 return DB2LIN_TABLE[dbout + slot->egout];
1389} 1390}
@@ -1406,16 +1407,16 @@ calc_slot_hat (OPLL_SLOT *slot, e_int32 pgout_cym, e_uint32 noise)
1406 ) 1407 )
1407 { 1408 {
1408 if(noise) 1409 if(noise)
1409 dbout = DB_NEG(12.0); 1410 dbout = DB_NEG(12);
1410 else 1411 else
1411 dbout = DB_NEG(24.0); 1412 dbout = DB_NEG(24);
1412 } 1413 }
1413 else 1414 else
1414 { 1415 {
1415 if(noise) 1416 if(noise)
1416 dbout = DB_POS(12.0); 1417 dbout = DB_POS(12);
1417 else 1418 else
1418 dbout = DB_POS(24.0); 1419 dbout = DB_POS(24);
1419 } 1420 }
1420 1421
1421 return DB2LIN_TABLE[dbout + slot->egout]; 1422 return DB2LIN_TABLE[dbout + slot->egout];