fmopl.h

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

Generated on Fri Jul 27 22:27:14 2007 for pentagram by  doxygen 1.4.7