DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
src/hardware/snd_pc98/sound/opngen.h
00001 
00002 enum {
00003 #if defined(SUPPORT_PX)
00004         OPNCH_MAX               = 30,
00005 #else   // defined(SUPPORT_PX)
00006         OPNCH_MAX               = 12,
00007 #endif  // defined(SUPPORT_PX)
00008         OPNA_CLOCK              = 55466 * 72,
00009 };
00010 
00011 #define OPN_CHMASK              0x80000000U
00012 #define OPN_STEREO              0x80000000U
00013 #define OPN_MONORAL             0x00000000U
00014 
00015 #if defined(OPNGENX86)
00016 
00017 enum {
00018         FMDIV_BITS              = 8,
00019         FMDIV_ENT               = (1 << FMDIV_BITS),
00020         FMVOL_SFTBIT    = 4
00021 };
00022 
00023 #define SIN_BITS                11
00024 #define EVC_BITS                10
00025 #define ENV_BITS                16
00026 #define KF_BITS                 6
00027 #define FREQ_BITS               21
00028 #define ENVTBL_BIT              14
00029 #define SINTBL_BIT              14
00030 
00031 #elif defined(OPNGENARM)
00032 
00033 enum {
00034         FMDIV_BITS              = 8,
00035         FMDIV_ENT               = (1 << FMDIV_BITS),
00036         FMVOL_SFTBIT    = 4
00037 };
00038 
00039 #define SIN_BITS                8
00040 #define EVC_BITS                7
00041 #define ENV_BITS                16
00042 #define KF_BITS                 6
00043 #define FREQ_BITS               20
00044 #define ENVTBL_BIT              14
00045 #define SINTBL_BIT              14                                                      // env+sin 30bit max
00046 
00047 #else
00048 
00049 enum {
00050         FMDIV_BITS              = 8,
00051         FMDIV_ENT               = (1 << FMDIV_BITS),
00052         FMVOL_SFTBIT    = 4
00053 };
00054 
00055 #define SIN_BITS                10
00056 #define EVC_BITS                10
00057 #define ENV_BITS                16
00058 #define KF_BITS                 6
00059 #define FREQ_BITS               21
00060 #define ENVTBL_BIT              14
00061 #define SINTBL_BIT              15
00062 
00063 #endif
00064 
00065 #define TL_BITS                 (FREQ_BITS+2)
00066 #define OPM_OUTSB               (TL_BITS + 2 - 16)                      // OPM output 16bit
00067 
00068 #define SIN_ENT                 (1L << SIN_BITS)
00069 #define EVC_ENT                 (1L << EVC_BITS)
00070 
00071 #define EC_ATTACK               0                                                               // ATTACK start
00072 #define EC_DECAY                (EVC_ENT << ENV_BITS)                   // DECAY start
00073 #define EC_OFF                  ((2 * EVC_ENT) << ENV_BITS)             // OFF
00074 
00075 #define TL_MAX                  (EVC_ENT * 2)
00076 
00077 enum {
00078         OPNSLOT1                = 0,                            // slot number
00079         OPNSLOT2                = 2,
00080         OPNSLOT3                = 1,
00081         OPNSLOT4                = 3,
00082 
00083         EM_ATTACK               = 4,
00084         EM_DECAY1               = 3,
00085         EM_DECAY2               = 2,
00086         EM_RELEASE              = 1,
00087         EM_OFF                  = 0
00088 };
00089 
00090 typedef struct {
00091         SINT32          *detune1;                       // detune1
00092         SINT32          totallevel;                     // total level
00093         SINT32          decaylevel;                     // decay level
00094 const SINT32    *attack;                        // attack ratio
00095 const SINT32    *decay1;                        // decay1 ratio
00096 const SINT32    *decay2;                        // decay2 ratio
00097 const SINT32    *release;                       // release ratio
00098         SINT32          freq_cnt;                       // frequency count
00099         SINT32          freq_inc;                       // frequency step
00100         SINT32          multiple;                       // multiple
00101         UINT8           keyscale;                       // key scale
00102         UINT8           env_mode;                       // envelope mode
00103         UINT8           envratio;                       // envelope ratio
00104         UINT8           ssgeg1;                         // SSG-EG
00105 
00106         SINT32          env_cnt;                        // envelope count
00107         SINT32          env_end;                        // envelope end count
00108         SINT32          env_inc;                        // envelope step
00109         SINT32          env_inc_attack;         // envelope attack step
00110         SINT32          env_inc_decay1;         // envelope decay1 step
00111         SINT32          env_inc_decay2;         // envelope decay2 step
00112         SINT32          env_inc_release;        // envelope release step
00113 } OPNSLOT;
00114 
00115 typedef struct {
00116         OPNSLOT slot[4];
00117         UINT8   algorithm;                      // algorithm
00118         UINT8   feedback;                       // self feedback
00119         UINT8   playing;
00120         UINT8   outslot;
00121         SINT32  op1fb;                          // operator1 feedback
00122         SINT32  *connect1;                      // operator1 connect
00123         SINT32  *connect3;                      // operator3 connect
00124         SINT32  *connect2;                      // operator2 connect
00125         SINT32  *connect4;                      // operator4 connect
00126         UINT32  keynote[4];                     // key note                             // ver0.27
00127 
00128         UINT8   keyfunc[4];                     // key function
00129         UINT8   kcode[4];                       // key code
00130         UINT8   pan;                            // pan
00131         UINT8   extop;                          // extendopelator-enable
00132         UINT8   stereo;                         // stereo-enable
00133         UINT8   padding2;
00134 } OPNCH;
00135 
00136 typedef struct {
00137         UINT    playchannels;
00138         UINT    playing;
00139         SINT32  feedback2;
00140         SINT32  feedback3;
00141         SINT32  feedback4;
00142         SINT32  outdl;
00143         SINT32  outdc;
00144         SINT32  outdr;
00145         SINT32  calcremain;
00146         UINT8   keyreg[OPNCH_MAX];
00147 } _OPNGEN, *OPNGEN;
00148 
00149 typedef struct {
00150         SINT32  calc1024;
00151         SINT32  fmvol;
00152         UINT    ratebit;
00153         UINT    vr_en;
00154         SINT32  vr_l;
00155         SINT32  vr_r;
00156 
00157         SINT32  sintable[SIN_ENT];
00158         SINT32  envtable[EVC_ENT];
00159         SINT32  envcurve[EVC_ENT*2 + 1];
00160 } OPNCFG;
00161 
00162 
00163 #ifdef __cplusplus
00164 extern "C" {
00165 #endif
00166 
00167 void opngen_initialize(UINT rate);
00168 void opngen_setvol(UINT vol);
00169 void opngen_setVR(REG8 channel, REG8 value);
00170 
00171 void opngen_reset(void);
00172 void opngen_setcfg(REG8 maxch, UINT32 flag);
00173 void opngen_setextch(UINT chnum, REG8 data);
00174 void opngen_setreg(REG8 chbase, UINT reg, REG8 value);
00175 void opngen_keyon(UINT chnum, REG8 value);
00176 
00177 void SOUNDCALL opngen_getpcm(void *hdl, SINT32 *buf, UINT count);
00178 void SOUNDCALL opngen_getpcmvr(void *hdl, SINT32 *buf, UINT count);
00179 
00180 #ifdef __cplusplus
00181 }
00182 #endif
00183