// PlaySound.h : header file

#include <mmsystem.h>
#include "IPlaySound.h"
#include "NuMsgDef.h"

/////////////////////////////////////////////////////////////////////////////
// CPlaySound thread

class CPlaySound : public IPlaySound
{
public:
	CPlaySound();
	virtual ~CPlaySound();
	
// Attributes
public:
	// only valid while running
	HANDLE m_hThread;       // this thread's HANDLE
	unsigned int m_nThreadID;      // this thread's ID

// Operations
public:
	BOOL CreateThread(DWORD dwCreateFlags = 0, UINT nStackSize = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL);

    int GetThreadPriority();
	BOOL SetThreadPriority(int nPriority);

	DWORD SuspendThread();
	DWORD ResumeThread();
	BOOL PostThreadMessage(UINT message, WPARAM wParam, LPARAM lParam);

    static unsigned __stdcall ThreadProc(void *p);

// Overrides
	virtual BOOL InitInstance();
	virtual int ExitInstance();

	virtual void StartPlay();
	virtual void StopPlay();
	virtual void Reset();
	virtual void SetWaveFormat(int nChannels, int nBitsPerSample, int nSamplesPerSec);
	virtual void WriteSoundData(BYTE* lpData, DWORD dwBufferLength, int nChannels, int nBitsPerSample, int nSamplesPerSec);

// Implementation
protected:
	void OnStartPlaying(WPARAM wParam, LPARAM lParam);
	void OnStopPlaying(WPARAM wParam, LPARAM lParam);	
	void OnEndPlaySoundData(WPARAM wParam, LPARAM lParam);
	void OnWriteSoundData(WPARAM wParam, LPARAM lParam);
	void OnReset(WPARAM wParam, LPARAM lParam);
	
protected:
	int	m_nOutputBuffers;
	int m_nMaxOutputBuffers;
	WAVEFORMATEX m_WaveFormatEx;
	BOOL m_bPlay;
	HWAVEOUT m_hPlay;
	HANDLE m_hCompleteEvent;
};

