#ifndef S_VRC7_H__
#define S_VRC7_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "nestypes.h"
#include "logtable.h"
#include "fmopl/driver.h"
#include "fmopl/fmopl.h"

#define USE_FMOPL 1

#ifdef __cplusplus
}

class OPLLSOUND {
	typedef struct {
		Uint8 freql;
		Uint8 freqh;
		Uint8 volinst;
		Uint8 mtl;
		Uint8 ctl;
		Uint8 mks;
		Uint8 cks;
	} OPLL_CH;

public:
	OPLLSOUND(int frequency = 44100, int clock = 3579545);
	~OPLLSOUND();
	void WriteAddress(Uint8 value);
	void WriteData(Uint8 value);
	void Synth(Int16 *pBuffer, Uint32 numSamples);
	/* Int32 SynthSample(void); */
	void Reset(void);

private:
	FM_OPL *ym3812;
	OPLL_CH ch[9];
	Uint8 inst[19][16];
	Uint8 adr;
	Uint8 rhythmc;
	Uint mastervolume;
	void opll_writeinst(Uint ch, Uint8 *tone);
	void opll_writevol(Uint ch);
	void opll_writefreq(Uint ch);
	void opll_write(Uint address, Uint value);
	void opll_setinst(Uint8 *p);
	void opll_reset(void);
};

#endif


#endif /* S_VRC7_H__ */
