Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "DirectSound.h"
  3. #ifndef DSBLOCK_ENTIREBUFFER
  4. #define DSBLOCK_ENTIREBUFFER 0x00000002
  5. #endif
  6. #ifdef _DEBUG
  7. #undef THIS_FILE
  8. static char THIS_FILE[]=__FILE__;
  9. #define new DEBUG_NEW
  10. #endif
  11. BOOL CDirectSound::CreateSoundBuffer(WAVEFORMATEX*pcmwf){DSBUFFERDESC dsbdesc;
  12. memset(&dsbdesc,0,sizeof(DSBUFFERDESC));dsbdesc.dwSize=sizeof(DSBUFFERDESC);
  13. dsbdesc.dwFlags=DSBCAPS_STATIC;dsbdesc.dwBufferBytes=m_dwTheSound;
  14. dsbdesc.lpwfxFormat=pcmwf;HRESULT hRes;if(DS_OK!=(hRes=m_lpDirectSound->
  15. CreateSoundBuffer(&dsbdesc,&m_pDsb,0))){DSError(hRes);m_pDsb=0;return FALSE;}
  16. return TRUE;}BOOL CDirectSound::SetSoundData(void*pSoundData,DWORD dwSoundSize)
  17. {LPVOID lpvPtr1;DWORD dwBytes1;HRESULT hr=m_pDsb->Lock(0,0,&lpvPtr1,&dwBytes1,0
  18. ,0,DSBLOCK_ENTIREBUFFER);if(DSERR_BUFFERLOST==hr){m_pDsb->Restore();hr=m_pDsb->
  19. Lock(0,0,&lpvPtr1,&dwBytes1,0,0,DSBLOCK_ENTIREBUFFER);}if(DS_OK==hr){::
  20. CopyMemory(lpvPtr1,pSoundData,dwBytes1);hr=m_pDsb->Unlock(lpvPtr1,dwBytes1,0,0)
  21. ;if(DS_OK==hr)return TRUE;}return FALSE;}void CDirectSound::Play(DWORD
  22. dwStartPosition,BOOL bLoop){if(!IsValid()||!IsEnabled())return;if(
  23. dwStartPosition>m_dwTheSound)dwStartPosition=m_dwTheSound;m_pDsb->
  24. SetCurrentPosition(dwStartPosition);if(DSERR_BUFFERLOST==m_pDsb->Play(0,0,bLoop
  25. ?DSBPLAY_LOOPING:0)){SetSoundData(m_pTheSound,m_dwTheSound);m_pDsb->Play(0,0,
  26. bLoop?DSBPLAY_LOOPING:0);}}void CDirectSound::Stop(){if(IsValid())m_pDsb->Stop(
  27. );}void CDirectSound::Pause(){Stop();}void CDirectSound::Continue(){if(IsValid(
  28. )){DWORD dwPlayCursor,dwWriteCursor;m_pDsb->GetCurrentPosition(&dwPlayCursor,&
  29. dwWriteCursor);Play(dwPlayCursor);}}BOOL CDirectSound::IsValid()const{return(
  30. m_lpDirectSound&&m_pDsb&&m_pTheSound&&m_dwTheSound)?TRUE:FALSE;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement