| | |
Direct Sound Help (Creating a sound buffer)
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2005
Posts: 22
Reputation:
Solved Threads: 0
Okay, I'm learning how to load a WAV file into DirectSound in order to play it. I've successfully surfed through the headers of the WAV file, and loaded it. However, when I go to create a buffer with this WAV sound data I've run into a road block. I'm getting a DSERR_INVALIDPARAM error when I try to create this sound buffer from a WAV format variable. I have successfully created a blank primary buffer with the wfxformat tag being NULL and the size being 0. Here's my code for my WAV buffer:
Here's my class that I use to access my m_lpDSBuffer
I keep getting a DSERR_INVALIDPARAM error, help!
Here's my class that I use to access my m_lpDSBuffer
C Syntax (Toggle Plain Text)
class DSound { private: DWORD m_dwDSBufferSize; DWave* m_lpWaveFile; DWORD m_dwNumBuffers; DWORD m_dwCreationFlags; public: LPDIRECTSOUNDBUFFER m_lpDSBuffer; bool inUse; bool Open(LPTSTR strFileName); };
C Syntax (Toggle Plain Text)
bool DWave::Open(LPTSTR strFileName, WAVEFORMATEX* wavFmt, DWORD dwFlags) { HMMIO hWav; // WAVE's handle WAVEFORMATEX wfmex; // WAVE's format MMCKINFO child, parent; UCHAR *p_wavData; // file loads here UCHAR *p_wavBuffer1; // pointer to first buffer UCHAR *p_wavBuffer2; // second buffer DWORD dwLength1; // length of first write buffer DWORD dwLength2; // length of second write buffer DSound wavFile; // temporary buffer DSound *p_wavFile; int iCurrSize, i; DSBUFFERDESC dsbd; // local direct sound buffer description p_wavFile = &wavFile; hWav = mmioOpen(strFileName, NULL, MMIO_READ | MMIO_ALLOCBUF); if (hWav==NULL) { ErrorBox("Could not find / load file at mmioOpen()"); return false; } parent.fccType = mmioFOURCC('W', 'A', 'V', 'E'); // descend to riff if (mmioDescend(hWav, &parent, NULL, MMIO_FINDRIFF)) { ErrorBox("Could not descend to RIFF, file is corrupt or not a WAVE file."); mmioClose(hWav, 0); return false; } // descend to WAVEfmt child.ckid = mmioFOURCC('f', 'm', 't', ' '); if (mmioDescend(hWav, &child, &parent, 0)) { ErrorBox("Could not descend to WAVEfmt, file is corrupt or not a WAVE file."); mmioClose(hWav, 0); return false; } // open WAV file for reading, check to make sure format is correct if (mmioRead(hWav, (char*)&wfmex, sizeof(WAVEFORMATEX)) != sizeof(WAVEFORMATEX)) { ErrorBox("Error reading WAV format, file is corrupt or not a WAVE file."); mmioClose(hWav, 0); return false; } if (wfmex.wFormatTag != WAVE_FORMAT_PCM) { ErrorBox("WAVE file is not of PCM format."); mmioClose(hWav, 0); return false; } if (mmioAscend(hWav, &child, 0)) { ErrorBox("Error ascending to WAVE data."); mmioClose(hWav, 0); return false; } // descend to data child.ckid = mmioFOURCC('d', 'a', 't', 'a'); if (mmioDescend(hWav, &child, &parent, MMIO_FINDCHUNK)) { ErrorBox("Error descending to the WAVE data level."); mmioClose(hWav, 0); return false; } // verification complete, now read information // allocate memory and load pointer if (!(p_wavData = new UCHAR [child.cksize])) { ErrorBox("Insufficient memory to load WAVE file."); mmioClose(hWav, 0); return false; } // read WAVE data long lBytesRead; lBytesRead = mmioRead(hWav, (char*)p_wavData, child.cksize); if (lBytesRead<0) { ErrorBox("Unable to read WAVE file data."); mmioClose(hWav, 0); return false; } mmioClose(hWav, 0); // place our information on our buffer, prepare our description for direct sound dsbd.dwSize = sizeof(DSBUFFERDESC); dsbd.dwBufferBytes = child.cksize; // size of buffer is equal to the wave's size dsbd.dwFlags = DSBCAPS_STATIC | DSBCAPS_LOCSOFTWARE | // Force loading in software so we can't loose it. DSBCAPS_GLOBALFOCUS | // Don't mute on 'lostfocus' DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY; dsbd.lpwfxFormat = &wfmex; // create our sound buffer HRESULT hr = dsSound.m_lpDS->CreateSoundBuffer(&dsbd, &p_wavFile->m_lpDSBuffer, NULL); if (hr==DSERR_INVALIDPARAM) { delete [] p_wavData; p_wavFile = NULL; ErrorBox("Error creating sound buffer."); return false; } return true; }
I keep getting a DSERR_INVALIDPARAM error, help!
![]() |
Similar Threads
- Music score, midi and sound effects in games (Game Development)
- Missing sound drivers for xp proffessional (Windows NT / 2000 / XP)
- Windows Media Player 10 appears to play audio files but no sound (Windows NT / 2000 / XP)
- can you hook a computer up to a receiver for surround sound? (Troubleshooting Dead Machines)
- Sound Card Problem? (PCI and Add-In Cards)
- sound issue (Windows NT / 2000 / XP)
- Help sound file deleted. (Windows 95 / 98 / Me)
Other Threads in the C Forum
- Previous Thread: need help on sending smtp email
- Next Thread: help in C, Find local Ip address
Views: 6708 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file floatingpointvalidation fork forloop framework function functions getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux hacking histogram homework ide include incrementoperators input intmain() iso kernel keyboard kilometer km lazy license linked linkedlist linux list lists looping loopinsideloop. lowest matrix microsoft mqqueue number oddnumber odf openwebfoundation overwrite owf pause pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprogramming spoonfeeding standard string student systemcall testing threads turboc unix urboc user variable whythiscodecausesegmentationfault windowsapi





