| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#define fltype double |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
#define OPL_INLINE INLINE |
| 50 |
|
| 51 |
|
| 52 |
#undef NUM_CHANNELS |
| 53 |
#if defined(OPLTYPE_IS_OPL3) |
| 54 |
#define NUM_CHANNELS 18 |
| 55 |
#else |
| 56 |
#define NUM_CHANNELS 9 |
| 57 |
#endif |
| 58 |
|
| 59 |
#define MAXOPERATORS (NUM_CHANNELS*2) |
| 60 |
|
| 61 |
|
| 62 |
#define FL05 ((fltype)0.5) |
| 63 |
#define FL2 ((fltype)2.0) |
| 64 |
#define PI ((fltype)3.1415926535897932384626433832795) |
| 65 |
|
| 66 |
|
| 67 |
#define FIXEDPT 0x10000 // fixed-point calculations using 16+16 |
| 68 |
#define FIXEDPT_LFO 0x1000000 // fixed-point calculations using 8+24 |
| 69 |
|
| 70 |
#define WAVEPREC 1024 // waveform precision (10 bits) |
| 71 |
|
| 72 |
#define INTFREQU ((fltype)(14318180.0 / 288.0)) // clocking of the chip |
| 73 |
|
| 74 |
|
| 75 |
#define OF_TYPE_ATT 0 |
| 76 |
#define OF_TYPE_DEC 1 |
| 77 |
#define OF_TYPE_REL 2 |
| 78 |
#define OF_TYPE_SUS 3 |
| 79 |
#define OF_TYPE_SUS_NOKEEP 4 |
| 80 |
#define OF_TYPE_OFF 5 |
| 81 |
|
| 82 |
#define ARC_CONTROL 0x00 |
| 83 |
#define ARC_TVS_KSR_MUL 0x20 |
| 84 |
#define ARC_KSL_OUTLEV 0x40 |
| 85 |
#define ARC_ATTR_DECR 0x60 |
| 86 |
#define ARC_SUSL_RELR 0x80 |
| 87 |
#define ARC_FREQ_NUM 0xa0 |
| 88 |
#define ARC_KON_BNUM 0xb0 |
| 89 |
#define ARC_PERC_MODE 0xbd |
| 90 |
#define ARC_FEEDBACK 0xc0 |
| 91 |
#define ARC_WAVE_SEL 0xe0 |
| 92 |
|
| 93 |
#define ARC_SECONDSET 0x100 // second operator set for OPL3 |
| 94 |
|
| 95 |
|
| 96 |
#define OP_ACT_OFF 0x00 |
| 97 |
#define OP_ACT_NORMAL 0x01 // regular channel activated (bitmasked) |
| 98 |
#define OP_ACT_PERC 0x02 // percussion channel activated (bitmasked) |
| 99 |
|
| 100 |
#define BLOCKBUF_SIZE 512 |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
#define VIBTAB_SIZE 8 |
| 105 |
#define VIBFAC 70/50000 // no braces, integer mul/div |
| 106 |
|
| 107 |
|
| 108 |
#define TREMTAB_SIZE 53 |
| 109 |
#define TREM_FREQ ((fltype)(3.7)) // tremolo at 3.7hz |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
typedef struct operator_struct { |
| 124 |
Bit32s cval, lastcval; |
| 125 |
Bit32u tcount, wfpos, tinc; |
| 126 |
fltype amp, step_amp; |
| 127 |
fltype vol; |
| 128 |
fltype sustain_level; |
| 129 |
Bit32s mfbi; |
| 130 |
fltype a0, a1, a2, a3; |
| 131 |
fltype decaymul, releasemul; |
| 132 |
Bit32u op_state; |
| 133 |
Bit32u toff; |
| 134 |
Bit32s freq_high; |
| 135 |
Bit16s* cur_wform; |
| 136 |
Bit32u cur_wmask; |
| 137 |
Bit32u act_state; |
| 138 |
bool sus_keep; |
| 139 |
bool vibrato,tremolo; |
| 140 |
|
| 141 |
|
| 142 |
Bit32u generator_pos; |
| 143 |
Bits cur_env_step; |
| 144 |
Bits env_step_a,env_step_d,env_step_r; |
| 145 |
Bit8u step_skip_pos_a; |
| 146 |
Bits env_step_skip_a; |
| 147 |
|
| 148 |
#if defined(OPLTYPE_IS_OPL3) |
| 149 |
bool is_4op,is_4op_attached; |
| 150 |
Bit32s left_pan,right_pan; |
| 151 |
#endif |
| 152 |
} op_type; |
| 153 |
|
| 154 |
|
| 155 |
Bitu chip_num; |
| 156 |
op_type op[MAXOPERATORS]; |
| 157 |
|
| 158 |
Bits int_samplerate; |
| 159 |
|
| 160 |
Bit8u status; |
| 161 |
Bit32u opl_index; |
| 162 |
#if defined(OPLTYPE_IS_OPL3) |
| 163 |
Bit8u adlibreg[512]; |
| 164 |
Bit8u wave_sel[44]; |
| 165 |
#else |
| 166 |
Bit8u adlibreg[256]; |
| 167 |
Bit8u wave_sel[22]; |
| 168 |
#endif |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
Bit32u vibtab_pos; |
| 173 |
Bit32u vibtab_add; |
| 174 |
Bit32u tremtab_pos; |
| 175 |
Bit32u tremtab_add; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
void enable_operator(Bitu regbase, op_type* op_pt); |
| 180 |
|
| 181 |
|
| 182 |
void change_frequency(Bitu chanbase, Bitu regbase, op_type* op_pt); |
| 183 |
|
| 184 |
void change_attackrate(Bitu regbase, op_type* op_pt); |
| 185 |
void change_decayrate(Bitu regbase, op_type* op_pt); |
| 186 |
void change_releaserate(Bitu regbase, op_type* op_pt); |
| 187 |
void change_sustainlevel(Bitu regbase, op_type* op_pt); |
| 188 |
void change_waveform(Bitu regbase, op_type* op_pt); |
| 189 |
void change_keepsustain(Bitu regbase, op_type* op_pt); |
| 190 |
void change_vibrato(Bitu regbase, op_type* op_pt); |
| 191 |
void change_feedback(Bitu chanbase, op_type* op_pt); |
| 192 |
|
| 193 |
|
| 194 |
void adlib_init(Bit32u samplerate); |
| 195 |
void adlib_write(Bitu idx, Bit8u val); |
| 196 |
void adlib_getsample(Bit16s* sndptr, Bits numsamples); |
| 197 |
|
| 198 |
Bitu adlib_reg_read(Bitu port); |
| 199 |
void adlib_write_index(Bitu port, Bit8u val); |
| 200 |
|
| 201 |
static Bit32u generator_add; |