DirectSound WAVEFORMATEX Problem

Reply

Join Date: Mar 2005
Posts: 22
Reputation: Mr Violent is an unknown quantity at this point 
Solved Threads: 0
Mr Violent Mr Violent is offline Offline
Newbie Poster

DirectSound WAVEFORMATEX Problem

 
0
  #1
Jul 11th, 2006
Hey there, I'm having a problem with the WAVEFORMATEX format, and setting my primary buffer's format. My code is below:

  1. void ErrorBox(string strMessage) {
  2. MessageBox(NULL, strMessage.c_str(), "Error", MB_OK | MB_ICONEXCLAMATION);
  3. return;
  4. }
  5.  
  6. bool DSPlayer::SetPrimaryBuffer() {
  7.  
  8. if (lpDS == NULL) {
  9. ErrorBox("Direct sound not initialized.");
  10. return false;
  11. }
  12.  
  13. ZeroMemory(&dsBufferDesc, sizeof(DSBUFFERDESC));
  14.  
  15. dsBufferDesc.dwSize = sizeof(DSBUFFERDESC);
  16. dsBufferDesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
  17. dsBufferDesc.dwBufferBytes = 0;
  18. dsBufferDesc.lpwfxFormat = NULL;
  19.  
  20. if (FAILED(lpDS->CreateSoundBuffer(&dsBufferDesc, &lpDSPrimary, NULL))) {
  21. ErrorBox("Unable to create primary buffer.");
  22. return false;
  23. }
  24.  
  25. WAVEFORMATEX wfx;
  26. ZeroMemory(&wfx, sizeof(WAVEFORMATEX));
  27.  
  28.  
  29. // 1ff9fe86
  30. wfx.wFormatTag = WAVE_FORMAT_PCM;
  31. wfx.nChannels = 2;
  32. wfx.nSamplesPerSec = 22050;
  33. wfx.wBitsPerSample = 16;
  34. wfx.nBlockAlign = ((wfx.wBitsPerSample * wfx.nChannels) / 8);
  35. wfx.nAvgBytesPerSec = (wfx.nSamplesPerSec * wfx.nBlockAlign);
  36. wfx.cbSize = 0;
  37.  
  38.  
  39. HRESULT hr;
  40.  
  41. if (FAILED(hr = lpDSPrimary->SetFormat(&wfx))) {
  42. ErrorBox("Failed to set primary buffer's format");
  43. return false;
  44. }
  45.  
  46.  
  47. return true;
  48. }

My error is telling me that I don't have the priority level I need to set the format. How do I get this priority level?
Last edited by Mr Violent; Jul 11th, 2006 at 8:09 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC