본문 바로가기
Game Programming

OPL3 활용을 위해서

by 게임혼 2017. 4. 19.

일단 위키의 내용을 살펴보자.

typedef struct{
	UINT32	ar; 		/* attack rate: AR<<2			*/
	UINT32	dr; 		/* decay rate:  DR<<2			*/
	UINT32	rr; 		/* release rate:RR<<2			*/
	UINT8	KSR;		/* key scale rate		        */
	UINT8	ksl;		/* keyscale level			*/
	UINT8	ksr;		/* key scale rate: kcode>>KSR	        */
	UINT8	mul;		/* multiple: mul_tab[ML]		*/

	/* Phase Generator */
	UINT32	Cnt;		/* frequency counter			*/
	UINT32	Incr;		/* frequency counter step		*/
	UINT8   FB;		/* feedback shift value		        */
	INT32   *connect;	/* slot output pointer			*/
	INT32   op1_out[2];	/* slot1 output for feedback	        */
	UINT8   CON;		/* connection (algorithm) type	        */

	/* Envelope Generator */
	UINT8	eg_type;	/* percussive/non-percussive mode       */
	UINT8	state;		/* phase type				*/
	UINT32	TL;		/* total level: TL << 2			*/
	INT32	TLL;		/* adjusted now TL			*/
	INT32	volume;		/* envelope counter			*/
	UINT32	sl;		/* sustain level: sl_tab[SL]	        */

	UINT32	eg_m_ar;	/* (attack state)			*/
	UINT8	eg_sh_ar;	/* (attack state)			*/
	UINT8	eg_sel_ar;	/* (attack state)			*/
	UINT32	eg_m_dr;	/* (decay state)			*/
	UINT8	eg_sh_dr;	/* (decay state)			*/
	UINT8	eg_sel_dr;	/* (decay state)			*/
	UINT32	eg_m_rr;	/* (release state)			*/
	UINT8	eg_sh_rr;	/* (release state)			*/
	UINT8	eg_sel_rr;	/* (release state)			*/

	UINT32	key;		/* 0 = KEY OFF, >0 = KEY ON		*/

	/* LFO */
	UINT32	AMmask;		/* LFO Amplitude Modulation enable mask */
	UINT8	vib;		/* LFO Phase Modulation enable flag (active high)*/

	/* waveform select */
	UINT8	waveform_number;
	unsigned int wavetable;

#if 0
unsigned char reserved[128-84];//speedup: pump up the struct size to power of 2
#else
unsigned char reserved[128-100];//speedup: pump up the struct size to power of 2
#endif
} OPL3_SLOT;

typedef struct{
	OPL3_SLOT SLOT[2];

	UINT32	block_fnum;	/* block+fnum			*/
	UINT32	fc;		/* Freq. Increment base		*/
	UINT32	ksl_base;	/* KeyScaleLevel Base step	*/
	UINT8	kcode;		/* key code (for key scaling)	*/

	/*
	   there are 12 2-operator channels which can be combined in pairs
	   to form six 4-operator channel, they are:
		0 and 3,
		1 and 4,
		2 and 5,
		9 and 12,
		10 and 13,
		11 and 14
	*/
	UINT8	extended;	/* set to 1 if this channel forms up a 4op channel with another channel(only used by first of pair of channels, ie 0,1,2 and 9,10,11) */

unsigned char reserved[512-272];//speedup:pump up the struct size to power of 2
} OPL3_CH;

/* OPL3 state */
typedef struct {
	OPL3_CH	P_CH[18];			/* OPL3 chips have 18 channels	*/

	UINT32	pan[18*2];			/* channels output multiplier; 2 per channel */

	UINT32	eg_cnt;				/* global envelope generator counter	*/
	UINT32	eg_timer;			/* global envelope generator counter works at frequency = chipclock/288 (288=8*36) */
	UINT32	eg_timer_add;			/* step of eg_timer						*/
	UINT32	eg_timer_overflow;		/* envelope generator timer overlfows every 1 sample (on real chip) */

	UINT32	fn_tab[1024];			/* fnumber->increment counter	*/

	/* LFO */
	UINT8	lfo_am_depth;
	UINT8	lfo_pm_depth_range;
	UINT32	lfo_am_cnt;
	UINT32	lfo_am_inc;
	UINT32	lfo_pm_cnt;
	UINT32	lfo_pm_inc;

	UINT32	noise_rng;			/* 23 bit noise shift register	*/
	UINT32	noise_p;			/* current noise 'phase'	*/
	UINT32	noise_f;			/* current noise period		*/

	UINT8	OPL3_mode;			/* OPL3 extension enable flag	*/

	UINT8	rhythm;				/* Rhythm mode			*/

	int		T[2];			/* timer counters		*/
	int		TC[2];
	UINT8	st[2];			        /* timer enable			*/

	UINT32	address;			/* address register		*/
	UINT8	status;				/* status flag			*/
	UINT8	statusmask;			/* status mask			*/

	UINT8	nts;				/* NTS (note select)		*/

	/* external event callback handlers */
	OPL3_TIMERHANDLER  TimerHandler;        /* TIMER handler		*/
	int TimerParam;				/* TIMER parameter		*/
	OPL3_IRQHANDLER    IRQHandler;	        /* IRQ handler			*/
	int IRQParam;				/* IRQ parameter		*/
	OPL3_UPDATEHANDLER UpdateHandler;       /* stream update handler	*/
	int UpdateParam;			/* stream update parameter 	*/

	UINT8 type;				/* chip type			*/
	int clock;				/* master clock  (Hz)		*/
	int rate;				/* sampling rate (Hz)		*/
	double freqbase;			/* frequency base		*/
	double TimerBase;			/* Timer base time (==sampling time)*/
} OPL3;

지금 시대에 왠 OPL3라고 하겠지만 일단 필요가 있으니까 어쩔 수 없구나..



'Game Programming' 카테고리의 다른 글

Rooting Crown iOS bug fix?  (0) 2017.06.27
yandex 차단 일지  (0) 2017.05.18
unreal project  (0) 2017.04.18
ANIMA2D  (0) 2017.03.25
module googlemobileads not found  (0) 2017.01.31