fmopl.h

Go to the documentation of this file.
00001 /* ScummVM - Scumm Interpreter
00002  * Copyright (C) 1999/2000 Tatsuyuki Satoh
00003  * Copyright (C) 2001/2002 The ScummVM project
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  *
00019  * $Header: /cvsroot/exult/exult/audio/midi_drivers/fmopl.h,v 1.1 2002/08/06 18:10:31 colourles Exp $
00020  *
00021  * LGPL licensed version of MAMEs fmopl (V0.37a modified) by
00022  * Tatsuyuki Satoh. Included from LGPL'ed AdPlug.
00023  */
00024 
00025 #ifndef FMOPL_H
00026 #define FMOPL_H
00027 
00028 #ifdef USE_FMOPL_MIDI
00029 
00030 #include "common_types.h"
00031 
00032 typedef void (*OPL_TIMERHANDLER)(int channel,double interval_Sec);
00033 typedef void (*OPL_IRQHANDLER)(int param,int irq);
00034 typedef void (*OPL_UPDATEHANDLER)(int param,int min_interval_us);
00035 
00036 #define OPL_TYPE_WAVESEL   0x01  /* waveform select    */
00037 
00038 /* Saving is necessary for member of the 'R' mark for suspend/resume */
00039 /* ---------- OPL one of slot  ---------- */
00040 typedef struct fm_opl_slot {
00041   int TL;   /* total level     :TL << 8       */
00042   int TLL;  /* adjusted now TL            */
00043   uint8 KSR;  /* key scale rate  :(shift down bit)  */
00044   int *AR;  /* attack rate     :&AR_TABLE[AR<<2]  */
00045   int *DR;  /* decay rate      :&DR_TABLE[DR<<2]  */
00046   int SL;   /* sustain level   :SL_TABLE[SL]    */
00047   int *RR;  /* release rate    :&DR_TABLE[RR<<2]  */
00048   uint8 ksl;  /* keyscale level  :(shift down bits) */
00049   uint8 ksr;  /* key scale rate  :kcode>>KSR      */
00050   uint32 mul; /* multiple        :ML_TABLE[ML]    */
00051   uint32 Cnt; /* frequency count            */
00052   uint32 Incr;  /* frequency step           */
00053   
00054   /* envelope generator state */
00055   uint8 eg_typ;/* envelope type flag          */
00056   uint8 evm;  /* envelope phase           */
00057   int evc;  /* envelope counter           */
00058   int eve;  /* envelope counter end point     */
00059   int evs;  /* envelope counter step        */
00060   int evsa; /* envelope step for AR :AR[ksr]    */
00061   int evsd; /* envelope step for DR :DR[ksr]    */
00062   int evsr; /* envelope step for RR :RR[ksr]    */
00063 
00064   /* LFO */
00065   uint8 ams;    /* ams flag                            */
00066   uint8 vib;    /* vibrate flag                        */
00067   /* wave selector */
00068   int **wavetable;
00069 } OPL_SLOT;
00070 
00071 /* ---------- OPL one of channel  ---------- */
00072 typedef struct fm_opl_channel {
00073   OPL_SLOT SLOT[2];
00074   uint8 CON;      /* connection type          */
00075   uint8 FB;     /* feed back       :(shift down bit)*/
00076   int *connect1;    /* slot1 output pointer       */
00077   int *connect2;    /* slot2 output pointer       */
00078   int op1_out[2];   /* slot1 output for selfeedback   */
00079 
00080   /* phase generator state */
00081   uint32  block_fnum; /* block+fnum           */
00082   uint8 kcode;    /* key code        : KeyScaleCode */
00083   uint32  fc;     /* Freq. Increment base       */
00084   uint32  ksl_base;   /* KeyScaleLevel Base step      */
00085   uint8 keyon;    /* key on/off flag          */
00086 } OPL_CH;
00087 
00088 /* OPL state */
00089 typedef struct fm_opl_f {
00090   uint8 type;     /* chip type                         */
00091   int clock;      /* master clock  (Hz)                */
00092   int rate;     /* sampling rate (Hz)                */
00093   double freqbase;  /* frequency base                    */
00094   double TimerBase; /* Timer base time (==sampling time) */
00095   uint8 address;    /* address register                  */
00096   uint8 status;   /* status flag                       */
00097   uint8 statusmask; /* status mask                       */
00098   uint32 mode;      /* Reg.08 : CSM , notesel,etc.       */
00099 
00100   /* Timer */
00101   int T[2];     /* timer counter                     */
00102   uint8 st[2];    /* timer enable                      */
00103 
00104   /* FM channel slots */
00105   OPL_CH *P_CH;   /* pointer of CH                     */
00106   int max_ch;     /* maximum channel                   */
00107 
00108   /* Rythm sention */
00109   uint8 rythm;    /* Rythm mode , key flag */
00110   
00111   /* time tables */
00112   int AR_TABLE[75]; /* atttack rate tables        */
00113   int DR_TABLE[75]; /* decay rate tables        */
00114   uint32 FN_TABLE[1024];/* fnumber -> increment counter   */
00115 
00116   /* LFO */
00117   int *ams_table;
00118   int *vib_table;
00119   int amsCnt;
00120   int amsIncr;
00121   int vibCnt;
00122   int vibIncr;
00123 
00124   /* wave selector enable flag */
00125   uint8 wavesel;
00126 
00127   /* external event callback handler */
00128   OPL_TIMERHANDLER  TimerHandler;   /* TIMER handler   */
00129   int TimerParam;           /* TIMER parameter */
00130   OPL_IRQHANDLER    IRQHandler;   /* IRQ handler    */
00131   int IRQParam;           /* IRQ parameter  */
00132   OPL_UPDATEHANDLER UpdateHandler;  /* stream update handler   */
00133   int UpdateParam;          /* stream update parameter */
00134 } FM_OPL;
00135 
00136 /* ---------- Generic interface section ---------- */
00137 #define OPL_TYPE_YM3526 (0)
00138 #define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL)
00139 
00140 // Modulation Registers
00141 #define OPL_REG_AVEKM_M   0x20
00142 #define OPL_REG_KSLTL_M   0x40
00143 #define OPL_REG_AD_M    0x60
00144 #define OPL_REG_SR_M    0x80
00145 #define OPL_REG_WAVE_M    0xE0
00146 
00147 // Carrier Registers
00148 #define OPL_REG_AVEKM_C   0x23
00149 #define OPL_REG_KSLTL_C   0x43
00150 #define OPL_REG_AD_C    0x63
00151 #define OPL_REG_SR_C    0x83
00152 #define OPL_REG_WAVE_C    0xE3
00153 
00154 #define OPL_REG_FB_C    0xC0
00155 
00156 
00157 FM_OPL *OPLCreate(int type, int clock, int rate);
00158 void OPLDestroy(FM_OPL *OPL);
00159 void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER TimerHandler,int channelOffset);
00160 void OPLSetIRQHandler(FM_OPL *OPL,OPL_IRQHANDLER IRQHandler,int param);
00161 void OPLSetUpdateHandler(FM_OPL *OPL,OPL_UPDATEHANDLER UpdateHandler,int param);
00162 
00163 void OPLResetChip(FM_OPL *OPL);
00164 int OPLWrite(FM_OPL *OPL,int a,int v);
00165 unsigned char OPLRead(FM_OPL *OPL,int a);
00166 int OPLTimerOver(FM_OPL *OPL,int c);
00167 void OPLWriteReg(FM_OPL *OPL, int r, int v);
00168 void YM3812UpdateOne(FM_OPL *OPL, sint16 *buffer, int length);
00169 
00170 
00171 #endif //USE_FMOPL_MIDI
00172 
00173 #endif //FMOPL_H

Generated on Mon Jul 9 14:42:40 2007 for ExultEngine by  doxygen 1.5.1