#ifndef S_SNG_H__
#define S_SNG_H__

#define USE_MAME_ENGINE 0


#ifdef __cplusplus
extern "C" {
#endif

#include "nestypes.h"
#include "logtable.h"

#ifdef __cplusplus
}
#endif

#if USE_MAME_ENGINE

class SNGSOUND {

public:
	SNGSOUND(int frequency = 44100, int clock = 3579545);
	~SNGSOUND();
	void WriteData(Uint8 value);
	void WriteStereo(Uint8 value);
	void Synth(Int16 *pBuffer, Uint32 numSamples);
	/* Int32 SynthSample(void); */
	void Reset(void);
private:
	void *pSynth;
	int iClock;
	int iFrequency;
};

#else

class SNGSOUND {

	typedef struct {
		Uint32 cps;
		Int32 cycles;
		Uint32 spd;
		Uint32 vol;
		Uint32 regs[2];
		Uint8 update;
		Uint8 adr;
		Uint8 mute;
	} SNG_SQUARE;

	typedef struct {
		Uint32 cps;
		Int32 cycles;
		Uint32 spd;
		Uint32 vol;
		Uint32 regs[2];
		Uint32 rng;
		Uint32 fb;
		Uint8 update;
		Uint8 mode;
		Uint8 mute;
	} SNG_NOISE;

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

private:
	SNG_SQUARE square[3];
	SNG_NOISE noise;
	Uint32 mastervolume;
	Uint first;
	Uint8 ggs;

	Int32 SNGSOUND::SNGSoundSquare(SNG_SQUARE *ch);
	Uint32 SNGSOUND::SNGSoundNoise(SNG_NOISE *ch);
};
#endif

#endif /* S_SNG_H__ */
