ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

mame.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  * LGPL licensed version of MAMEs fmopl (V0.37a modified) by
00022  * Tatsuyuki Satoh. Included from LGPL'ed AdPlug.
00023  *
00024  */
00025 
00026 
00027 #ifndef AUDIO_SOFTSYNTH_OPL_MAME_H
00028 #define AUDIO_SOFTSYNTH_OPL_MAME_H
00029 
00030 #include "common/scummsys.h"
00031 #include "common/random.h"
00032 
00033 #include "audio/fmopl.h"
00034 
00035 namespace OPL {
00036 namespace MAME {
00037 
00038 enum {
00039     FMOPL_ENV_BITS_HQ = 16,
00040     FMOPL_ENV_BITS_MQ = 8,
00041     FMOPL_ENV_BITS_LQ = 8,
00042     FMOPL_EG_ENT_HQ = 4096,
00043     FMOPL_EG_ENT_MQ = 1024,
00044     FMOPL_EG_ENT_LQ = 128
00045 };
00046 
00047 
00048 typedef void (*OPL_TIMERHANDLER)(int channel,double interval_Sec);
00049 typedef void (*OPL_IRQHANDLER)(int param,int irq);
00050 typedef void (*OPL_UPDATEHANDLER)(int param,int min_interval_us);
00051 
00052 #define OPL_TYPE_WAVESEL   0x01  /* waveform select    */
00053 
00054 /* Saving is necessary for member of the 'R' mark for suspend/resume */
00055 /* ---------- OPL one of slot  ---------- */
00056 typedef struct fm_opl_slot {
00057     int TL;     /* total level     :TL << 8             */
00058     int TLL;    /* adjusted now TL                      */
00059     uint8 KSR;  /* key scale rate  :(shift down bit)    */
00060     int *AR;    /* attack rate     :&AR_TABLE[AR<<2]    */
00061     int *DR;    /* decay rate      :&DR_TABLE[DR<<2]    */
00062     int SL;     /* sustain level   :SL_TABLE[SL]        */
00063     int *RR;    /* release rate    :&DR_TABLE[RR<<2]    */
00064     uint8 ksl;  /* keyscale level  :(shift down bits)   */
00065     uint8 ksr;  /* key scale rate  :kcode>>KSR          */
00066     uint mul;   /* multiple        :ML_TABLE[ML]        */
00067     uint Cnt;   /* frequency count                      */
00068     uint Incr;  /* frequency step                       */
00069 
00070     /* envelope generator state */
00071     uint8 eg_typ;/* envelope type flag                  */
00072     uint8 evm;  /* envelope phase                       */
00073     int evc;    /* envelope counter                     */
00074     int eve;    /* envelope counter end point           */
00075     int evs;    /* envelope counter step                */
00076     int evsa;   /* envelope step for AR :AR[ksr]        */
00077     int evsd;   /* envelope step for DR :DR[ksr]        */
00078     int evsr;   /* envelope step for RR :RR[ksr]        */
00079 
00080     /* LFO */
00081     uint8 ams;      /* ams flag                            */
00082     uint8 vib;      /* vibrate flag                        */
00083     /* wave selector */
00084     int **wavetable;
00085 } OPL_SLOT;
00086 
00087 /* ---------- OPL one of channel  ---------- */
00088 typedef struct fm_opl_channel {
00089     OPL_SLOT SLOT[2];
00090     uint8 CON;          /* connection type                  */
00091     uint8 FB;           /* feed back       :(shift down bit)*/
00092     int *connect1;      /* slot1 output pointer             */
00093     int *connect2;      /* slot2 output pointer             */
00094     int op1_out[2];     /* slot1 output for selfeedback     */
00095 
00096     /* phase generator state */
00097     uint block_fnum;    /* block+fnum                       */
00098     uint8 kcode;        /* key code        : KeyScaleCode   */
00099     uint fc;            /* Freq. Increment base             */
00100     uint ksl_base;      /* KeyScaleLevel Base step          */
00101     uint8 keyon;        /* key on/off flag                  */
00102 } OPL_CH;
00103 
00104 /* OPL state */
00105 typedef struct fm_opl_f {
00106     uint8 type;         /* chip type                         */
00107     int clock;          /* master clock  (Hz)                */
00108     int rate;           /* sampling rate (Hz)                */
00109     double freqbase;    /* frequency base                    */
00110     double TimerBase;   /* Timer base time (==sampling time) */
00111     uint8 address;      /* address register                  */
00112     uint8 status;       /* status flag                       */
00113     uint8 statusmask;   /* status mask                       */
00114     uint mode;          /* Reg.08 : CSM , notesel,etc.       */
00115 
00116     /* Timer */
00117     int T[2];           /* timer counter                     */
00118     uint8 st[2];        /* timer enable                      */
00119 
00120     /* FM channel slots */
00121     OPL_CH *P_CH;       /* pointer of CH                     */
00122     int max_ch;         /* maximum channel                   */
00123 
00124     /* Rythm sention */
00125     uint8 rythm;        /* Rythm mode , key flag */
00126 
00127     /* time tables */
00128     int AR_TABLE[76];   /* atttack rate tables              */
00129     int DR_TABLE[76];   /* decay rate tables                */
00130     uint FN_TABLE[1024];/* fnumber -> increment counter     */
00131 
00132     /* LFO */
00133     int *ams_table;
00134     int *vib_table;
00135     int amsCnt;
00136     int amsIncr;
00137     int vibCnt;
00138     int vibIncr;
00139 
00140     /* wave selector enable flag */
00141     uint8 wavesel;
00142 
00143     /* external event callback handler */
00144     OPL_TIMERHANDLER  TimerHandler;     /* TIMER handler   */
00145     int TimerParam;                     /* TIMER parameter */
00146     OPL_IRQHANDLER    IRQHandler;       /* IRQ handler    */
00147     int IRQParam;                       /* IRQ parameter  */
00148     OPL_UPDATEHANDLER UpdateHandler;    /* stream update handler   */
00149     int UpdateParam;                    /* stream update parameter */
00150 
00151     Common::RandomSource *rnd;
00152 } FM_OPL;
00153 
00154 /* ---------- Generic interface section ---------- */
00155 #define OPL_TYPE_YM3526 (0)
00156 #define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL)
00157 
00158 void OPLBuildTables(int ENV_BITS_PARAM, int EG_ENT_PARAM);
00159 
00160 FM_OPL *OPLCreate(int type, int clock, int rate);
00161 void OPLDestroy(FM_OPL *OPL);
00162 void OPLSetTimerHandler(FM_OPL *OPL, OPL_TIMERHANDLER TimerHandler, int channelOffset);
00163 void OPLSetIRQHandler(FM_OPL *OPL, OPL_IRQHANDLER IRQHandler, int param);
00164 void OPLSetUpdateHandler(FM_OPL *OPL, OPL_UPDATEHANDLER UpdateHandler, int param);
00165 
00166 void OPLResetChip(FM_OPL *OPL);
00167 int OPLWrite(FM_OPL *OPL, int a, int v);
00168 unsigned char OPLRead(FM_OPL *OPL, int a);
00169 int OPLTimerOver(FM_OPL *OPL, int c);
00170 void OPLWriteReg(FM_OPL *OPL, int r, int v);
00171 void YM3812UpdateOne(FM_OPL *OPL, int16 *buffer, int length);
00172 
00173 // Factory method
00174 FM_OPL *makeAdLibOPL(int rate);
00175 
00176 // OPL API implementation
00177 class OPL : public ::OPL::EmulatedOPL {
00178 private:
00179     FM_OPL *_opl;
00180 public:
00181     OPL() : _opl(0) {}
00182     ~OPL();
00183 
00184     bool init();
00185     void reset();
00186 
00187     void write(int a, int v);
00188     byte read(int a);
00189 
00190     void writeReg(int r, int v);
00191 
00192     bool isStereo() const { return false; }
00193 
00194 protected:
00195     void generateSamples(int16 *buffer, int length);
00196 };
00197 
00198 } // End of namespace MAME
00199 } // End of namespace OPL
00200 
00201 #endif


Generated on Sat Apr 20 2019 05:03:11 for ResidualVM by doxygen 1.7.1
curved edge   curved edge