123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- #define fltype double
- #if defined(_MSC_VER) && _MSC_VER <= 1600
- #include <windows.h>
- #define uintptr_t ULONG_PTR
- #define intptr_t LONG_PTR
- #define uint32_t DWORD
- #define int32_t INT
- #define uint16_t WORD
- #define int16_t SHORT
- #define uint8_t BYTE
- #define int8_t CHAR
- #else
- #include <stdint.h>
- #endif
- typedef uintptr_t Bitu;
- typedef intptr_t Bits;
- typedef uint32_t Bit32u;
- typedef int32_t Bit32s;
- typedef uint16_t Bit16u;
- typedef int16_t Bit16s;
- typedef uint8_t Bit8u;
- typedef int8_t Bit8s;
- #define OPL_INLINE inline
- #undef NUM_CHANNELS
- #if defined(OPLTYPE_IS_OPL3)
- #define NUM_CHANNELS 18
- #else
- #define NUM_CHANNELS 9
- #endif
- #define MAXOPERATORS (NUM_CHANNELS*2)
- #define FL05 ((fltype)0.5)
- #define FL2 ((fltype)2.0)
- #define PI ((fltype)3.1415926535897932384626433832795)
- #define FIXEDPT 0x10000 // fixed-point calculations using 16+16
- #define FIXEDPT_LFO 0x1000000 // fixed-point calculations using 8+24
- #define WAVEPREC 1024 // waveform precision (10 bits)
- #define INTFREQU ((fltype)(14318180.0 / 288.0)) // clocking of the chip
- #define OF_TYPE_ATT 0
- #define OF_TYPE_DEC 1
- #define OF_TYPE_REL 2
- #define OF_TYPE_SUS 3
- #define OF_TYPE_SUS_NOKEEP 4
- #define OF_TYPE_OFF 5
- #define ARC_CONTROL 0x00
- #define ARC_TVS_KSR_MUL 0x20
- #define ARC_KSL_OUTLEV 0x40
- #define ARC_ATTR_DECR 0x60
- #define ARC_SUSL_RELR 0x80
- #define ARC_FREQ_NUM 0xa0
- #define ARC_KON_BNUM 0xb0
- #define ARC_PERC_MODE 0xbd
- #define ARC_FEEDBACK 0xc0
- #define ARC_WAVE_SEL 0xe0
- #define ARC_SECONDSET 0x100 // second operator set for OPL3
- #define OP_ACT_OFF 0x00
- #define OP_ACT_NORMAL 0x01 // regular channel activated (bitmasked)
- #define OP_ACT_PERC 0x02 // percussion channel activated (bitmasked)
- #define BLOCKBUF_SIZE 512
- #define VIBTAB_SIZE 8
- #define VIBFAC 70/50000 // no braces, integer mul/div
- #define TREMTAB_SIZE 53
- #define TREM_FREQ ((fltype)(3.7)) // tremolo at 3.7hz
- typedef struct opl_chip_struct opl_chip;
- typedef struct operator_struct {
- opl_chip* chip;
- Bit32s cval, lastcval;
- Bit32u tcount, wfpos, tinc;
- fltype amp, step_amp;
- fltype vol;
- fltype sustain_level;
- Bit32s mfbi;
- fltype a0, a1, a2, a3;
- fltype decaymul, releasemul;
- Bit32u op_state;
- Bit32u toff;
- Bit32s freq_high;
- Bit16s* cur_wform;
- Bit32u cur_wmask;
- Bit32u act_state;
- bool sus_keep;
- bool vibrato,tremolo;
-
-
- Bit32u generator_pos;
- Bits cur_env_step;
- Bits env_step_a,env_step_d,env_step_r;
- Bit8u step_skip_pos_a;
- Bits env_step_skip_a;
-
- #if defined(OPLTYPE_IS_OPL3)
- bool is_4op,is_4op_attached;
- Bit32s left_pan,right_pan;
- #endif
- } op_type;
- void enable_operator(Bitu regbase, op_type* op_pt);
- void change_frequency(Bitu chanbase, Bitu regbase, op_type* op_pt);
- void change_attackrate(Bitu regbase, op_type* op_pt);
- void change_decayrate(Bitu regbase, op_type* op_pt);
- void change_releaserate(Bitu regbase, op_type* op_pt);
- void change_sustainlevel(Bitu regbase, op_type* op_pt);
- void change_waveform(Bitu regbase, op_type* op_pt);
- void change_keepsustain(Bitu regbase, op_type* op_pt);
- void change_vibrato(Bitu regbase, op_type* op_pt);
- void change_feedback(Bitu chanbase, op_type* op_pt);
- opl_chip* adlib_init(Bit32u samplerate);
- void adlib_release(opl_chip* opl);
- void adlib_write(opl_chip* opl, Bitu idx, Bit8u val);
- void adlib_getsample(opl_chip* opl, Bit16s* sndptr, Bits numsamples);
- Bitu adlib_reg_read(opl_chip* opl, Bitu port);
- void adlib_write_index(opl_chip* opl, Bitu port, Bit8u val);
|