// WaveForm.h: interface for the CWaveForm class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_WAVEFORM_H__93A199C2_AF33_11D2_B7C8_444553540000__INCLUDED_)
#define AFX_WAVEFORM_H__93A199C2_AF33_11D2_B7C8_444553540000__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#define WAVE_FORM_BUFFER_NUMBER	3

class CWaveIn  
{
public:
	CWaveIn();
	virtual ~CWaveIn();

// Oprations
public:
	BOOL Init(HWND hWnd, int iTime, int iRecordDeviceID = -1, int iSamplingRate = 8000, int iChannel = 1, int iBits = 16);
	void Free();

	BOOL Start();
	void Stop();

	inline BOOL IsRecording()	{	return (m_hWaveIn != NULL);	}

	BOOL ContinueRecording();

// Information functions
public:
	void GetRecordDeviceNames(CStringList& strList);

protected:
	HWND m_hWnd;
	BOOL m_bRecord;

	int  m_iRecordDeviceID;
	int  m_iRecordDeviceNumber;

	HWAVEIN      m_hWaveIn;
	WAVEFORMATEX m_wavFormat;
	int			 m_iWaveLength;

	HANDLE    m_hWaveInHeader[WAVE_FORM_BUFFER_NUMBER];
	LPWAVEHDR m_pWaveInHeader[WAVE_FORM_BUFFER_NUMBER];
	HANDLE    m_hWaveInData[WAVE_FORM_BUFFER_NUMBER];
	LPSTR     m_pWaveInData[WAVE_FORM_BUFFER_NUMBER];

	int m_iWaveInNextBuffer;
};

class CWaveOut  
{
public:
	CWaveOut();
	virtual ~CWaveOut();

// Oprations
public:
	BOOL Init(HWND hWnd, int iTime, int iPlayDeviceID = -1, int iSamplingRate = 8000, int iChannel = 1, int iBits = 16);
	void Free();

	BOOL Start();
	void Stop();

	BOOL Play(char * pData, int iLength);

	inline BOOL IsPlayingData()	{	return (m_iWaveOutIdleBuffer < WAVE_FORM_BUFFER_NUMBER);	}
	inline BOOL IsPlaying()	{	return (m_hWaveOut != NULL);	}

	BOOL ContinuePlaying();

// Information functions
public:
	void GetPlayDeviceNames(CStringList& strList);

protected:
	HWND m_hWnd;
	BOOL m_bPlay;

	int  m_iPlayDeviceID;
	int  m_iPlayDeviceNumber;

	HWAVEOUT      m_hWaveOut;
	WAVEFORMATEX m_wavFormat;
	int			 m_iWaveLength;

	HANDLE    m_hWaveOutHeader[WAVE_FORM_BUFFER_NUMBER];
	LPWAVEHDR m_pWaveOutHeader[WAVE_FORM_BUFFER_NUMBER];
	HANDLE    m_hWaveOutData[WAVE_FORM_BUFFER_NUMBER];
	LPSTR     m_pWaveOutData[WAVE_FORM_BUFFER_NUMBER];

	int m_iWaveOutNextBuffer;
	int m_iWaveOutIdleBuffer;
};

#endif // !defined(AFX_WAVEFORM_H__93A199C2_AF33_11D2_B7C8_444553540000__INCLUDED_)
