From 2c755a1f3129ff14d44262ab7979dc7945303b6b Mon Sep 17 00:00:00 2001 From: Nicolas Bacca Date: Wed, 29 Jan 2003 21:28:37 +0000 Subject: Change AdLib emulation quality for slower devices - added PROP_GET_FMOPL_ENV_BITS and PROP_GET_FMOPL_EG_ENT svn-id: r6573 --- backends/midi/adlib.cpp | 4 ++ common/system.h | 11 +++- sound/fmopl.cpp | 137 ++++++++++++++++++++++++++++-------------------- sound/fmopl.h | 2 + 4 files changed, 97 insertions(+), 57 deletions(-) diff --git a/backends/midi/adlib.cpp b/backends/midi/adlib.cpp index 120462f6aa..4f35f0322e 100644 --- a/backends/midi/adlib.cpp +++ b/backends/midi/adlib.cpp @@ -737,6 +737,8 @@ int MidiDriver_ADLIB::open () int i; MidiChannelAdl *mc; + int env_bits = g_system->property(OSystem::PROP_GET_FMOPL_ENV_BITS, NULL); + int eg_ent = g_system->property(OSystem::PROP_GET_FMOPL_EG_ENT, NULL); for (i = 0, mc = _midi_channels; i != ARRAYSIZE(_midi_channels); i++, mc++) { mc->_channel = i; @@ -746,6 +748,8 @@ int MidiDriver_ADLIB::open () _adlib_reg_cache = (byte *)calloc(256, 1); + OPLBuildTables((env_bits ? env_bits : FMOPL_ENV_BITS_HQ), (eg_ent ? eg_ent : FMOPL_EG_ENT_HQ)); + _opl = OPLCreate(OPL_TYPE_YM3812, 3579545, g_system->property(OSystem::PROP_GET_SAMPLE_RATE, 0)); adlib_write(1, 0x20); diff --git a/common/system.h b/common/system.h index 995c2d10be..11bf5df53b 100644 --- a/common/system.h +++ b/common/system.h @@ -72,7 +72,9 @@ public: PROP_SET_GFX_MODE = 4, PROP_SHOW_DEFAULT_CURSOR = 5, PROP_GET_SAMPLE_RATE = 6, - PROP_GET_FULLSCREEN = 7 + PROP_GET_FULLSCREEN = 7, + PROP_GET_FMOPL_ENV_BITS = 8, + PROP_GET_FMOPL_EG_ENT = 9 }; union Property { const char *caption; @@ -260,4 +262,11 @@ enum { #endif }; +enum { + FMOPL_ENV_BITS_HQ = 16, + FMOPL_ENV_BITS_LQ = 8, + FMOPL_EG_ENT_HQ = 4096, + FMOPL_EG_ENT_LQ = 128 +}; + #endif diff --git a/sound/fmopl.cpp b/sound/fmopl.cpp index d635e6ad12..ed2fab72bb 100644 --- a/sound/fmopl.cpp +++ b/sound/fmopl.cpp @@ -62,16 +62,16 @@ /* output level entries (envelope,sinwave) */ /* envelope counter lower bits */ -#define ENV_BITS 16 +int ENV_BITS; /* envelope output entries */ -#define EG_ENT 4096 +int EG_ENT; + /* used dynamic memory = EG_ENT*4*4(byte)or EG_ENT*6*4(byte) */ /* used static memory = EG_ENT*4 (byte) */ - -#define EG_OFF ((2*EG_ENT)<SLOT[SLOT1]; env_out=OPL_CALC_SLOT(SLOT); - if( env_out < EG_ENT-1 ) + if( env_out < (uint)(EG_ENT-1)) { /* PG */ if(SLOT->vib) SLOT->Cnt += (SLOT->Incr*vib/VIB_RATE); @@ -455,7 +480,7 @@ inline void OPL_CALC_CH( OPL_CH *CH ) /* SLOT 2 */ SLOT = &CH->SLOT[SLOT2]; env_out=OPL_CALC_SLOT(SLOT); - if( env_out < EG_ENT-1 ) + if( env_out < (uint)(EG_ENT-1) ) { /* PG */ if(SLOT->vib) SLOT->Cnt += (SLOT->Incr*vib/VIB_RATE); @@ -537,16 +562,16 @@ inline void OPL_CALC_RH( OPL_CH *CH ) tone8 = OP_OUT(SLOT8_2,whitenoise,0 ); /* SD */ - if( env_sd < EG_ENT-1 ) + if( env_sd < (uint)(EG_ENT-1) ) outd[0] += OP_OUT(SLOT7_1,env_sd, 0)*8; /* TAM */ - if( env_tam < EG_ENT-1 ) + if( env_tam < (uint)(EG_ENT-1) ) outd[0] += OP_OUT(SLOT8_1,env_tam, 0)*2; /* TOP-CY */ - if( env_top < EG_ENT-1 ) + if( env_top < (uint)(EG_ENT-1) ) outd[0] += OP_OUT(SLOT7_2,env_top,tone8)*2; /* HH */ - if( env_hh < EG_ENT-1 ) + if( env_hh < (uint)(EG_ENT-1) ) outd[0] += OP_OUT(SLOT7_2,env_hh,tone8)*2; } @@ -1144,4 +1169,4 @@ int OPLTimerOver(FM_OPL *OPL,int c) /* reload timer */ if (OPL->TimerHandler) (OPL->TimerHandler)(OPL->TimerParam+c,(double)OPL->T[c]*OPL->TimerBase); return OPL->status>>7; -} +} \ No newline at end of file diff --git a/sound/fmopl.h b/sound/fmopl.h index 8e38342e45..64b64d3e73 100644 --- a/sound/fmopl.h +++ b/sound/fmopl.h @@ -135,6 +135,8 @@ typedef struct fm_opl_f { #define OPL_TYPE_YM3526 (0) #define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL) +void OPLBuildTables(int ENV_BITS_PARAM, int EG_ENT_PARAM); + FM_OPL *OPLCreate(int type, int clock, int rate); void OPLDestroy(FM_OPL *OPL); void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER TimerHandler,int channelOffset); -- cgit v1.2.3