Click here to Skip to main content
15,892,480 members
Articles / Desktop Programming / MFC

Using DirectSound to Play Audio Stream Data

Rate me:
Please Sign up or sign in to vote.
3.12/5 (17 votes)
9 Mar 20052 min read 303K   10.3K   66  
An article on how to play audio stream data with DirectSound.
#pragma once

#if _MSC_VER > 1000
#pragma once
#endif

typedef	HRESULT	(WINAPI *LPGETAUDIOSAMPLES_PROGRESS)(LPBYTE lpDesBuf, const DWORD dwRequiredSamples, DWORD &dwRetSamples, LPVOID lpData);

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

	void SetFormat(WAVEFORMATEX WFE);
	void SetCallback(LPGETAUDIOSAMPLES_PROGRESS Function_Callback, LPVOID lpData);
	void Play();
	void Pause();
	void Stop();
	DWORD GetSamplesPlayed();	
	void TimerCallback();
	
private:
	
	//<DirectSound>
	WAVEFORMATEX m_WFE;
	LPDIRECTSOUND m_lpDS;
	LPDIRECTSOUNDBUFFER m_lpDSB;
	HANDLE m_pHEvent[2];
	//</DirectSound>

	//<Audio Buffer>
	LPBYTE m_lpAudioBuf;
	LPGETAUDIOSAMPLES_PROGRESS m_lpGETAUDIOSAMPLES;
	LPVOID m_lpData;
	//</Audio Buffer>

	//<Playing>
	MMRESULT m_timerID;
	DWORD m_dwCircles1;
	DWORD m_dwCircles2;
	int m_iDB;	
	//</Playing>

	//<Error Information>
	CString m_strLastError;
	//</Error Information>
};
//</CMyDirectSound  >

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions