Click here to Skip to main content
15,908,581 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Data Transfer at particular Bitrate & Sleep for less than 1 second Pin
CPallini3-May-07 0:07
mveCPallini3-May-07 0:07 
QuestionRead and write Pin
prathuraj2-May-07 23:04
prathuraj2-May-07 23:04 
QuestionRe: Read and write Pin
Rajesh R Subramanian2-May-07 23:12
professionalRajesh R Subramanian2-May-07 23:12 
AnswerRe: Read and write Pin
prathuraj2-May-07 23:19
prathuraj2-May-07 23:19 
GeneralRe: Read and write Pin
Rajesh R Subramanian2-May-07 23:20
professionalRajesh R Subramanian2-May-07 23:20 
GeneralRe: Read and write Pin
prathuraj2-May-07 23:21
prathuraj2-May-07 23:21 
GeneralRe: Read and write Pin
Rajesh R Subramanian2-May-07 23:34
professionalRajesh R Subramanian2-May-07 23:34 
QuestionHelp! about DirectSound? Pin
kcynic2-May-07 22:43
kcynic2-May-07 22:43 
somebody would tell me why the following codes would failed at the calling:
lpDirectSound->CreateSoundBuffer(&BufferDesc,&pSoundBuffer,NULL);

CString strFile_in="sound.wav";<br />
LPVOID lpPtr1=NULL;<br />
LPVOID lpPtr2=NULL;<br />
HRESULT hr;<br />
DWORD dwLen1,dwLen2;<br />
LPVOID lp_mMemory=NULL;//内存指针<br />
LPVOID lpData=NULL;//media data point<br />
LPWAVEFORMATEX lpWaveFormat=NULL;//wave format point<br />
DWORD dwSize=0;//the size of the media file's data<br />
CFile file;<br />
DWORD dwFileSize;//the size of the media file<br />
//open the wave media file<br />
if(!file.Open(strFile_in,CFile::modeRead|CFile::shareDenyNone))<br />
{<br />
	AfxMessageBox("Open the media file failed!");<br />
	return ;<br />
}<br />
dwFileSize=file.Seek(0L,CFile::end);//get the length of the media file<br />
file.Seek(0L,CFile::begin);//locate the begin of the file<br />
//allocate the memory<br />
lp_mMemory=GlobalAlloc(GMEM_FIXED,dwFileSize);<br />
if(lp_mMemory==NULL)<br />
{<br />
	AfxMessageBox("Allocate memory failed!");<br />
	file.Close();<br />
	return ;<br />
}<br />
if(file.ReadHuge(lp_mMemory,dwFileSize)!=dwFileSize)<br />
{<br />
	AfxMessageBox("Read file error!");<br />
	file.Close();<br />
	GlobalFree(lp_mMemory);//free the memory<br />
	return ;<br />
}<br />
file.Close();//the file is no longer useful in this program<br />
<br />
LPDWORD lpdFile,lpdEnd;<br />
DWORD dwRiff,dwType,dwLen;<br />
lpdFile=(DWORD*)lp_mMemory;<br />
dwRiff=*lpdFile++;<br />
dwLen=*lpdFile++;<br />
dwType=*lpdFile++;<br />
if(dwRiff!=mmioFOURCC('R','I','F','F'))<br />
{<br />
	AfxMessageBox("This is not a RIFF file!");<br />
	GlobalFree(lp_mMemory);<br />
	return ;<br />
}<br />
if(dwType!=mmioFOURCC('W','A','V','E'))<br />
{<br />
	AfxMessageBox("This is not a WAVE file!");<br />
	GlobalFree(lp_mMemory);<br />
	return ;<br />
}<br />
<br />
//seek  the format chunk,data chunk and get their length<br />
lpdEnd=(DWORD*)((BYTE*)lp_mMemory+dwFileSize-4);<br />
BOOL bEnd=FALSE;<br />
while((lpdFile<lpdEnd)&&(!bEnd))<br />
{<br />
	dwType=*lpdFile++;<br />
	dwLen=*lpdFile++;<br />
	switch(dwType)<br />
	{<br />
	case mmioFOURCC('f','m','t',' ')://如果是"fmt"标志<br />
		if(!lpWaveFormat)<br />
		{<br />
			if(dwLen<sizeof(LPWAVEFORMATEX))<br />
			{<br />
				AfxMessageBox("There is some wrong in the file struct!");<br />
				return ;<br />
			}<br />
			else<br />
				lpWaveFormat=(LPWAVEFORMATEX)lpdFile;<br />
		}<br />
		break;<br />
	case mmioFOURCC('d','a','t','a')://如果是"data"标志<br />
		if(!lpData||!dwSize)<br />
		{<br />
			lpData=(LPBYTE)lpdFile;<br />
			dwSize=dwLen;<br />
			if(lpWaveFormat)<br />
				bEnd=TRUE;<br />
		}<br />
		break;<br />
	}<br />
<br />
	lpdFile=(DWORD*)((BYTE*)lpdFile+((dwLen+1)&~1));<br />
}<br />
<br />
DSBUFFERDESC BufferDesc;<br />
memset(&BufferDesc,0,sizeof(BufferDesc));<br />
BufferDesc.lpwfxFormat=(LPWAVEFORMATEX)lpWaveFormat;<br />
BufferDesc.dwSize=sizeof(DSBUFFERDESC);<br />
BufferDesc.dwBufferBytes=dwSize;<br />
BufferDesc.dwFlags=0;<br />
<br />
//	HRESULT hr;<br />
LPDIRECTSOUND lpDirectSound;<br />
hr=::DirectSoundCreate(0,&lpDirectSound,NULL);<br />
if(hr!=DS_OK)<br />
{<br />
	AfxMessageBox("Create DirectSound failed!");<br />
	GlobalFree(lp_mMemory);<br />
	return ;<br />
}<br />
//设置设备优先级为"Normal"<br />
hr=lpDirectSound->SetCooperativeLevel(this->GetSafeHwnd(),DSSCL_NORMAL);<br />
if(hr!=DS_OK)<br />
{<br />
	AfxMessageBox("SetCooperativeLevel failed!");<br />
}<br />
lpDirectSound->Initialize(NULL);<br />
//创建声音数据缓冲<br />
LPDIRECTSOUNDBUFFER pSoundBuffer=NULL;<br />
hr=lpDirectSound->CreateSoundBuffer(&BufferDesc,&pSoundBuffer,NULL);<br />
if(hr==DS_OK)<br />
{<br />
	hr=pSoundBuffer->Lock(0,dwSize,&lpPtr1,&dwLen1,&lpPtr2,&dwLen2,0);<br />
	if(hr==DS_OK)<br />
	{<br />
		memcpy(lpPtr1,lpData,dwLen1);<br />
		if(dwLen2>0)<br />
		{<br />
			BYTE* pData=(BYTE*)lpData+dwLen1;<br />
			lpData=(void*)pData;<br />
			memcpy(lpPtr2,lpData,dwLen2);<br />
		}<br />
	}<br />
	pSoundBuffer->Unlock(lpPtr1,dwLen1,lpPtr2,dwLen2);<br />
	DWORD dwFlags=0;<br />
	pSoundBuffer->Play(0,0,dwFlags);<br />
}<br />
else<br />
{<br />
	AfxMessageBox("Create buffer failed!");<br />
	switch(hr)<br />
	{<br />
	case DSERR_ALLOCATED:<br />
		AfxMessageBox("DSERR_ALLOCATED ");<br />
		break;<br />
	case DSERR_BADFORMAT:<br />
		AfxMessageBox("DSERR_BADFORMAT ");<br />
		break;<br />
	case DSERR_INVALIDPARAM:<br />
		AfxMessageBox("DSERR_INVALIDPARAM ");<br />
		break;<br />
	case DSERR_NOAGGREGATION:<br />
		AfxMessageBox("DSERR_NOAGGREGATION ");<br />
		break;<br />
	case DSERR_OUTOFMEMORY :<br />
		AfxMessageBox("DSERR_OUTOFMEMORY ");<br />
                break;<br />
	case DSERR_UNINITIALIZED:<br />
		AfxMessageBox("DSERR_UNINITIALIZED");<br />
		break;<br />
	case DSERR_UNSUPPORTED :<br />
		AfxMessageBox("DSERR_UNSUPPORTED ");<br />
		break;<br />
	case DSERR_INVALIDCALL:<br />
		AfxMessageBox("DSERR_INVALIDCALL");<br />
		break;<br />
	}<br />
}<br />
GlobalFree(lp_mMemory);


Thanks
QuestionRe: Help! about DirectSound? Pin
Mark Salsbery3-May-07 6:20
Mark Salsbery3-May-07 6:20 
AnswerRe: Help! about DirectSound? Pin
kcynic3-May-07 14:57
kcynic3-May-07 14:57 
GeneralRe: Help! about DirectSound? Pin
Mark Salsbery3-May-07 15:03
Mark Salsbery3-May-07 15:03 
GeneralRe: Help! about DirectSound? Pin
kcynic3-May-07 19:07
kcynic3-May-07 19:07 
GeneralRe: Help! about DirectSound? Pin
Mark Salsbery4-May-07 4:53
Mark Salsbery4-May-07 4:53 
GeneralRe: Help! about DirectSound? Pin
kcynic4-May-07 16:28
kcynic4-May-07 16:28 
GeneralRe: Help! about DirectSound? Pin
Mark Salsbery5-May-07 5:21
Mark Salsbery5-May-07 5:21 
Questionwhen and where to retrieve thread's return value Pin
neha.agarwal272-May-07 22:01
neha.agarwal272-May-07 22:01 
AnswerRe: when and where to retrieve thread's return value Pin
CPallini2-May-07 22:38
mveCPallini2-May-07 22:38 
QuestionSearch in vector? Pin
bosfan2-May-07 21:25
bosfan2-May-07 21:25 
AnswerRe: Search in vector? Pin
Stephen Hewitt2-May-07 21:32
Stephen Hewitt2-May-07 21:32 
GeneralRe: Search in vector? Pin
bosfan2-May-07 22:01
bosfan2-May-07 22:01 
GeneralRe: Search in vector? Pin
Stephen Hewitt2-May-07 22:08
Stephen Hewitt2-May-07 22:08 
GeneralRe: Search in vector? Pin
bosfan2-May-07 22:23
bosfan2-May-07 22:23 
GeneralRe: Search in vector? Pin
bosfan2-May-07 23:21
bosfan2-May-07 23:21 
AnswerRe: Search in vector? Pin
Arman S.2-May-07 21:34
Arman S.2-May-07 21:34 
GeneralRe: Search in vector? Pin
bosfan2-May-07 21:51
bosfan2-May-07 21:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.