Reverted to "old" YM3812 (FMOPL) emulator code.

Until specific information regarding the benefits
of migrating to the new emulator can be made
available, the "old" code will remain in effect
for the benefit of slower hardware platforms such
as some WinCE-based devices.

svn-id: r8903
This commit is contained in:
Jamieson Christian 2003-07-11 07:14:21 +00:00
parent 39b37df37a
commit 8b8b964aad
7 changed files with 996 additions and 2279 deletions

View File

@ -577,6 +577,7 @@ private:
bool _isOpen;
bool _game_SmallHeader;
FM_OPL *_opl;
byte *_adlib_reg_cache;
SoundMixer *_mixer;
@ -848,8 +849,12 @@ int MidiDriver_ADLIB::open() {
_adlib_reg_cache = (byte *)calloc(256, 1);
// We need to emulate one YM3812 chip
if (0 != YM3812Init(1, 3579545, g_system->property(OSystem::PROP_GET_SAMPLE_RATE, 0)))
error("Error initialising YM3812 sound chip emulation");
// if (0 != YM3812Init(1, 3579545, g_system->property(OSystem::PROP_GET_SAMPLE_RATE, 0)))
// error("Error initialising YM3812 sound chip emulation");
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);
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);
adlib_write(8, 0x40);
@ -876,7 +881,7 @@ void MidiDriver_ADLIB::close() {
_mixer->setupPremix (0, 0);
// Turn off the OPL emulation
YM3812Shutdown();
// YM3812Shutdown();
free(_adlib_reg_cache);
@ -986,8 +991,9 @@ void MidiDriver_ADLIB::adlib_write(byte port, byte value) {
return;
_adlib_reg_cache[port] = value;
YM3812Write(0, 0, port);
YM3812Write(0, 1, value);
// YM3812Write(0, 0, port);
// YM3812Write(0, 1, value);
OPLWriteReg (_opl, port, value);
}
void MidiDriver_ADLIB::generate_samples(int16 *data, int len) {
@ -997,7 +1003,8 @@ void MidiDriver_ADLIB::generate_samples(int16 *data, int len) {
step = len;
if (step > _next_tick)
step = _next_tick;
YM3812UpdateOne(0, data, step);
// YM3812UpdateOne(0, data, step);
YM3812UpdateOne (_opl, data, step);
_next_tick -= step;
if (!_next_tick) {

View File

@ -22,8 +22,9 @@
#include "adlibchannel.h"
#include "sound/fmopl.h"
SkyAdlibChannel::SkyAdlibChannel(uint8 *pMusicData, uint16 startOfData)
SkyAdlibChannel::SkyAdlibChannel(FM_OPL *opl, uint8 *pMusicData, uint16 startOfData)
{
_opl = opl;
_musicData = pMusicData;
_channelData.startOfData = startOfData;
_channelData.eventDataPtr = startOfData;
@ -78,8 +79,9 @@ void SkyAdlibChannel::updateVolume(uint16 pVolume) {
void SkyAdlibChannel::setRegister(uint8 regNum, uint8 value) {
if (_adlibRegMirror[regNum] != value) {
YM3812Write(0, 0, regNum);
YM3812Write(0, 1, value);
// YM3812Write(0, 0, regNum);
// YM3812Write(0, 1, value);
OPLWriteReg (_opl, regNum, value);
_adlibRegMirror[regNum] = value;
}
}

View File

@ -26,6 +26,7 @@
#include "common/engine.h"
#include "sky/sky.h"
#include "sky/music/musicbase.h"
#include "sound/fmopl.h"
typedef struct {
uint8 ad_Op1, ad_Op2;
@ -60,12 +61,13 @@ typedef struct {
class SkyAdlibChannel : public SkyChannelBase {
public:
SkyAdlibChannel(uint8 *pMusicData, uint16 startOfData);
SkyAdlibChannel (FM_OPL *opl, uint8 *pMusicData, uint16 startOfData);
virtual void stopNote(void);
virtual uint8 process(uint16 aktTime);
virtual void updateVolume(uint16 pVolume);
virtual bool isActive(void);
private:
FM_OPL *_opl;
uint8 *_musicData;
uint16 _musicVolume;
AdlibChannelType _channelData;

View File

@ -33,15 +33,20 @@ SkyAdlibMusic::SkyAdlibMusic(SoundMixer *pMixer, SkyDisk *pSkyDisk, OSystem *sys
_driverFileBase = 60202;
_mixer = pMixer;
_sampleRate = g_system->property(OSystem::PROP_GET_SAMPLE_RATE, 0);
if (0 != YM3812Init(1, 3579545, _sampleRate))
error("Error initialising YM3812 sound chip emulation");
// if (0 != YM3812Init(1, 3579545, _sampleRate))
// error("Error initialising YM3812 sound chip emulation");
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);
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));
_mixer->setupPremix(this, passMixerFunc);
}
SkyAdlibMusic::~SkyAdlibMusic(void) {
_mixer->setupPremix(NULL, NULL);
YM3812Shutdown();
// YM3812Shutdown();
}
void SkyAdlibMusic::setVolume(uint8 volume) {
@ -70,7 +75,7 @@ void SkyAdlibMusic::premixerCall(int16 *buf, uint len) {
render = (len > _nextMusicPoll) ? (_nextMusicPoll) : (len);
len -= render;
_nextMusicPoll -= render;
YM3812UpdateOne(0, buf, render);
YM3812UpdateOne (_opl, buf, render);
buf += render;
if (_nextMusicPoll == 0) {
pollMusic();
@ -98,7 +103,7 @@ void SkyAdlibMusic::setupChannels(uint8 *channelData) {
channelData++;
for (uint8 cnt = 0; cnt < _numberOfChannels; cnt++) {
uint16 chDataStart = ((channelData[(cnt << 1) | 1] << 8) | channelData[cnt << 1]) + _musicDataLoc;
_channels[cnt] = new SkyAdlibChannel(_musicData, chDataStart);
_channels[cnt] = new SkyAdlibChannel(_opl, _musicData, chDataStart);
_channels[cnt]->updateVolume(_musicVolume | 128);
}
}
@ -107,8 +112,9 @@ void SkyAdlibMusic::startDriver(void) {
uint16 cnt = 0;
while (_initSequence[cnt] || _initSequence[cnt+1]) {
YM3812Write(0, 0, _initSequence[cnt]);
YM3812Write(0, 1, _initSequence[cnt+1]);
// YM3812Write(0, 0, _initSequence[cnt]);
// YM3812Write(0, 1, _initSequence[cnt+1]);
OPLWriteReg (_opl, _initSequence[cnt], _initSequence[cnt+1]);
cnt += 2;
}
_allowedCommands = 0xD;

View File

@ -28,6 +28,7 @@
#include "common/engine.h"
#include "adlibchannel.h"
#include "musicbase.h"
#include "sound/fmopl.h"
class SkyAdlibMusic : public SkyMusicBase {
public:
@ -35,6 +36,7 @@ public:
~SkyAdlibMusic(void);
virtual void setVolume(uint8 volume);
private:
FM_OPL *_opl;
SoundMixer *_mixer;
uint8 *_initSequence;
uint32 _sampleRate, _nextMusicPoll;

File diff suppressed because it is too large Load Diff

View File

@ -18,125 +18,135 @@
*
* $Header$
*
* LGPL licensed version of MAMEs fmopl (V0.60a modified) by
* Tatsuyuki Satoh and Jarek Burczynski. Included from LGPL'ed AdPlug.
* LGPL licensed version of MAMEs fmopl (V0.37a modified) by
* Tatsuyuki Satoh. Included from LGPL'ed AdPlug.
*/
#ifndef __FMOPL_H_
#define __FMOPL_H_
#define HAS_YM3812 1
/* --- select emulation chips --- */
#ifdef _MSC_VER
// FIXME: how to fix it for VC6 ?
#define BUILD_YM3812 1
#else
#define BUILD_YM3812 defined(HAS_YM3812) && HAS_YM3812
#endif
#define BUILD_YM3526 defined(HAS_YM3526) && HAS_YM3526
#define BUILD_Y8950 defined(HAS_Y8950) && HAS_Y8950
/* select output bits size of output : 8 or 16 */
#define OPL_SAMPLE_BITS 16
/* compiler dependence */
#ifndef OSD_CPU_H
#define OSD_CPU_H
typedef unsigned char UINT8; /* unsigned 8bit */
typedef unsigned short UINT16; /* unsigned 16bit */
typedef unsigned int UINT32; /* unsigned 32bit */
typedef signed char INT8; /* signed 8bit */
typedef signed short INT16; /* signed 16bit */
typedef signed int INT32; /* signed 32bit */
#endif
#if (OPL_SAMPLE_BITS==16)
typedef INT16 OPLSAMPLE;
#endif
#if (OPL_SAMPLE_BITS==8)
typedef INT8 OPLSAMPLE;
#endif
#include "scummsys.h"
typedef void (*OPL_TIMERHANDLER)(int channel,double interval_Sec);
typedef void (*OPL_IRQHANDLER)(int param,int irq);
typedef void (*OPL_UPDATEHANDLER)(int param,int min_interval_us);
typedef void (*OPL_PORTHANDLER_W)(int param,unsigned char data);
typedef unsigned char (*OPL_PORTHANDLER_R)(int param);
#define OPL_TYPE_WAVESEL 0x01 /* waveform select */
#if BUILD_YM3812
/* Saving is necessary for member of the 'R' mark for suspend/resume */
/* ---------- OPL one of slot ---------- */
typedef struct fm_opl_slot {
int TL; /* total level :TL << 8 */
int TLL; /* adjusted now TL */
uint8 KSR; /* key scale rate :(shift down bit) */
int *AR; /* attack rate :&AR_TABLE[AR<<2] */
int *DR; /* decay rate :&DR_TABLE[DR<<2] */
int SL; /* sustain level :SL_TABLE[SL] */
int *RR; /* release rate :&DR_TABLE[RR<<2] */
uint8 ksl; /* keyscale level :(shift down bits) */
uint8 ksr; /* key scale rate :kcode>>KSR */
uint mul; /* multiple :ML_TABLE[ML] */
uint Cnt; /* frequency count */
uint Incr; /* frequency step */
/* envelope generator state */
uint8 eg_typ;/* envelope type flag */
uint8 evm; /* envelope phase */
int evc; /* envelope counter */
int eve; /* envelope counter end point */
int evs; /* envelope counter step */
int evsa; /* envelope step for AR :AR[ksr] */
int evsd; /* envelope step for DR :DR[ksr] */
int evsr; /* envelope step for RR :RR[ksr] */
int YM3812Init(int num, int clock, int rate);
void YM3812Shutdown(void);
void YM3812ResetChip(int which);
int YM3812Write(int which, int a, int v);
unsigned char YM3812Read(int which, int a);
int YM3812TimerOver(int which, int c);
void YM3812UpdateOne(int which, INT16 *buffer, int length);
void YM3812SetTimerHandler(int which, OPL_TIMERHANDLER TimerHandler, int channelOffset);
void YM3812SetIRQHandler(int which, OPL_IRQHANDLER IRQHandler, int param);
void YM3812SetUpdateHandler(int which, OPL_UPDATEHANDLER UpdateHandler, int param);
#endif
#if BUILD_YM3526
/*
** Initialize YM3526 emulator(s).
**
** 'num' is the number of virtual YM3526's to allocate
** 'clock' is the chip clock in Hz
** 'rate' is sampling rate
*/
int YM3526Init(int num, int clock, int rate);
/* shutdown the YM3526 emulators*/
void YM3526Shutdown(void);
void YM3526ResetChip(int which);
int YM3526Write(int which, int a, int v);
unsigned char YM3526Read(int which, int a);
int YM3526TimerOver(int which, int c);
/*
** Generate samples for one of the YM3526's
**
** 'which' is the virtual YM3526 number
** '*buffer' is the output buffer pointer
** 'length' is the number of samples that should be generated
*/
void YM3526UpdateOne(int which, INT16 *buffer, int length);
void YM3526SetTimerHandler(int which, OPL_TIMERHANDLER TimerHandler, int channelOffset);
void YM3526SetIRQHandler(int which, OPL_IRQHANDLER IRQHandler, int param);
void YM3526SetUpdateHandler(int which, OPL_UPDATEHANDLER UpdateHandler, int param);
#endif
#if BUILD_Y8950
#include "ymdeltat.h"
/* Y8950 port handlers */
void Y8950SetPortHandler(int which, OPL_PORTHANDLER_W PortHandler_w, OPL_PORTHANDLER_R PortHandler_r, int param);
void Y8950SetKeyboardHandler(int which, OPL_PORTHANDLER_W KeyboardHandler_w, OPL_PORTHANDLER_R KeyboardHandler_r, int param);
void Y8950SetDeltaTMemory(int which, void * deltat_rom, int deltat_rom_size );
int Y8950Init (int num, int clock, int rate);
void Y8950Shutdown (void);
void Y8950ResetChip (int which);
int Y8950Write (int which, int a, int v);
unsigned char Y8950Read (int which, int a);
int Y8950TimerOver (int which, int c);
void Y8950UpdateOne (int which, INT16 *buffer, int length);
void Y8950SetTimerHandler (int which, OPL_TIMERHANDLER TimerHandler, int channelOffset);
void Y8950SetIRQHandler (int which, OPL_IRQHANDLER IRQHandler, int param);
void Y8950SetUpdateHandler (int which, OPL_UPDATEHANDLER UpdateHandler, int param);
#endif
/* LFO */
uint8 ams; /* ams flag */
uint8 vib; /* vibrate flag */
/* wave selector */
int **wavetable;
} OPL_SLOT;
/* ---------- OPL one of channel ---------- */
typedef struct fm_opl_channel {
OPL_SLOT SLOT[2];
uint8 CON; /* connection type */
uint8 FB; /* feed back :(shift down bit)*/
int *connect1; /* slot1 output pointer */
int *connect2; /* slot2 output pointer */
int op1_out[2]; /* slot1 output for selfeedback */
/* phase generator state */
uint block_fnum; /* block+fnum */
uint8 kcode; /* key code : KeyScaleCode */
uint fc; /* Freq. Increment base */
uint ksl_base; /* KeyScaleLevel Base step */
uint8 keyon; /* key on/off flag */
} OPL_CH;
/* OPL state */
typedef struct fm_opl_f {
uint8 type; /* chip type */
int clock; /* master clock (Hz) */
int rate; /* sampling rate (Hz) */
double freqbase; /* frequency base */
double TimerBase; /* Timer base time (==sampling time) */
uint8 address; /* address register */
uint8 status; /* status flag */
uint8 statusmask; /* status mask */
uint mode; /* Reg.08 : CSM , notesel,etc. */
/* Timer */
int T[2]; /* timer counter */
uint8 st[2]; /* timer enable */
/* FM channel slots */
OPL_CH *P_CH; /* pointer of CH */
int max_ch; /* maximum channel */
/* Rythm sention */
uint8 rythm; /* Rythm mode , key flag */
/* time tables */
int AR_TABLE[75]; /* atttack rate tables */
int DR_TABLE[75]; /* decay rate tables */
uint FN_TABLE[1024];/* fnumber -> increment counter */
/* LFO */
int *ams_table;
int *vib_table;
int amsCnt;
int amsIncr;
int vibCnt;
int vibIncr;
/* wave selector enable flag */
uint8 wavesel;
/* external event callback handler */
OPL_TIMERHANDLER TimerHandler; /* TIMER handler */
int TimerParam; /* TIMER parameter */
OPL_IRQHANDLER IRQHandler; /* IRQ handler */
int IRQParam; /* IRQ parameter */
OPL_UPDATEHANDLER UpdateHandler; /* stream update handler */
int UpdateParam; /* stream update parameter */
} FM_OPL;
/* ---------- Generic interface section ---------- */
#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);
void OPLSetIRQHandler(FM_OPL *OPL, OPL_IRQHANDLER IRQHandler, int param);
void OPLSetUpdateHandler(FM_OPL *OPL, OPL_UPDATEHANDLER UpdateHandler, int param);
void OPLResetChip(FM_OPL *OPL);
int OPLWrite(FM_OPL *OPL, int a, int v);
unsigned char OPLRead(FM_OPL *OPL, int a);
int OPLTimerOver(FM_OPL *OPL, int c);
void OPLWriteReg(FM_OPL *OPL, int r, int v);
void YM3812UpdateOne(FM_OPL *OPL, int16 *buffer, int length);
#endif