Play .wav with WaveOutOpen(C++)

2.5k views Asked by At

I need to play audio file(.wav) with waveOutOpen function. I found manual for this. http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4422&lngWId=3 but I dont know how change this for .wav files. Please help me...

2

There are 2 answers

0
Roman Ryltsov On BEST ANSWER

You need mmioOpen, mmioRead functions to read payload data from .WAV file, and than you will be able to queue buffers using waveOut* API. If the data is PCM you can send it for playback directly, otherwise you might need to decompress using ACM API.

You will fin great code snippets looking up mentioned API functions:

1
cha On

this is how I do it (the wav file is stored in the resource):

static void PlaySound(LPCTSTR lpszSound)
{
   HRSRC hRes; // resource handle to wave file
   HGLOBAL hData;
   BOOL bOk = FALSE;
   if ((hRes = ::FindResource(AfxGetResourceHandle(), lpszSound,
     _T("WAVE"))) != NULL &&
     (hData = ::LoadResource(AfxGetResourceHandle(), hRes)) != NULL)
   {
      // found the resource, play it
    bOk = ::sndPlaySound((LPCTSTR)::LockResource(hData),
         SND_MEMORY|SND_ASYNC|SND_NODEFAULT);
    ::FreeResource(hData);
   }
   //if (!bOk)
   //{
   //   static BOOL bReported = FALSE;
   //   if (!bReported)
   //   {
   //      AfxMessageBox(IDS_CANNOT_PLAY_SOUND);
   //      bReported = TRUE;       // once please
   //   }
   //}
}

inline static void PlaySound(UINT nIDS)
{ ::PlaySound(MAKEINTRESOURCE(nIDS)); }