Problem when converting the PlaySound sample to simple procedure

Problem when converting the PlaySound sample to simple procedure

Post by Fahad Ashf » Sat, 09 Oct 2004 15:57:20


i,

I am trying to convert the PlaySound sample to one-functioned, for demo. The
problem is I've got all HRESULTs to S_OK but no sound is comming out from
speakers. I've tracked the value of each variable and in debug mode and
compare with PlaySound sample, everything was fine. I've no idea what
problem is. At the end of this message, there is a code

Project files can be downloaded at :
http://www.freewebs.com/fahadash/snd.zip

Thanks,
Fahad Ashfaque

Source Code:


IDirectSound8 *pDsound;
HMMIO hmmio;
MMCKINFO ckInfo;
MMCKINFO lckInfo;
PCMWAVEFORMAT pcmWF;
WAVEFORMATEX *wfex;
VOID* pDSLockedBuffer;
DWORD dwLockedBufferSize;
MMIOINFO mmioInfo;
HRESULT hresult;

void CSoundDlg::OnButton1()
{



Log("Loading file");

hmmio = mmioOpen("c:\\ding.wav",NULL, MMIO_ALLOCBUF | MMIO_READ);

if (hmmio != NULL)
{
Log("Hurra opened");

Log("Descending file");
if (MMSYSERR_NOERROR == mmioDescend(hmmio,&ckInfo, NULL, 0))
{
Log("Hurra! Descended");

lckInfo.ckid = mmioFOURCC('f','m','t',' ');
Log("Ffinding fmt chunk");
if (MMSYSERR_NOERROR == mmioDescend(hmmio,
&lckInfo,&ckInfo,MMIO_FINDCHUNK))
{
Log("Hurra! found");

Log("Reading fmt chunk");
if (mmioRead(hmmio, (HPSTR)&pcmWF,sizeof(pcmWF)) == sizeof(pcmWF))
{
Log("Hurra! Read");

Log("Checking weather it is PCM");
if (pcmWF.wf.wFormatTag == WAVE_FORMAT_PCM)
{
Log("Hurra! it is");

Log("Loading data to buffer");

wfex = (WAVEFORMATEX*) new CHAR[sizeof(WAVEFORMATEX)];

memcpy(wfex,&pcmWF,sizeof(pcmWF));

wfex->cbSize = 0;

Log("done");


Log("Ascending chunk");
if (mmioAscend(hmmio,&lckInfo,0) == MMSYSERR_NOERROR )
{
Log("Hurra! Ascended");

Log("Seeking file to data chunk");

if (mmioSeek(hmmio,ckInfo.dwDataOffset + sizeof(FOURCC),SEEK_SET)
!= -1)
{
Log("Hurra! seeked");

Log("Finding data chunk");

lckInfo.ckid = mmioFOURCC('d','a','t','a');

if (mmioDescend(hmmio, &lckInfo, &ckInfo, MMIO_FINDCHUNK )==
MMSYSERR_NOERROR)

{
Log("Hurra! found");

Log("Loading data into direct sound buffer");
DSBUFFERDESC dsbd;
memset(&dsbd,0,sizeof(dsbd));

dsbd.dwSize = sizeof(dsbd);

dsbd.dwFlags =DSBCAPS_LOCDEFER;
dsbd.dwBufferBytes = ckInfo.cksize;
dsbd.lpwfxFormat = wfex;


Log("Initializing com");
CoInitialize(NULL);

Log("Getting Interface");

if (DirectSoundCreate8(NULL,&pDsound, NULL) == DS_OK)
{
Log("Hurra! got interface");

LPDIRECTSOUNDBUFFER* pSB = new LPDIRECTSOUNDBUFFER[1];




Log("Creating direct sound buffer");
if (SUCCEEDED(pDsound->CreateSoundBuffer(&dsbd, &pSB[0], NULL)))
{
Log("Hurra! Direct sound buffer Created");

Log("Locking the buffer");
if (SUCCEEDED(pSB[0]->Lock(0, ckInfo.cksize, &pDSLockedBuffer,
&dwLockedBufferSize, NULL, 0 , 0)))
{
Log("Hurra! locked");

Log("Getting mmio Info");

if (mmioGetInfo(hmmio,&mmioInfo,0) == MMSYSERR_NOERROR)
{
Log("Hurra info got");

Log("Copying data to buffer");

LONG cData;

cData = ckInfo.cksize;
ckInfo.cksize = 0;

for (DWORD i=0;i<
 
 
 

Problem when converting the PlaySound sample to simple procedure

Post by Phil Taylo » Sun, 10 Oct 2004 01:45:55

n SetCooperativeLevel, whats m_hWnd? and whats 1?

"Fahad Ashfaque" < XXXX@XXXXX.COM > wrote in message
news:%23kQ% XXXX@XXXXX.COM ...