The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Calculating the Duration of a WAV Sound

The length of time for which a waveform will play is determined by the data size and the format.

The following example function returns the duration of a WAV file, in milliseconds:

DWORD GetSoundLength(LPSTR strFileName)
  CWaveFile* pWav;
  DWORD dwLen = 0;
  DWORD dwSize;
  pWav = new CWaveFile();
  if (SUCCEEDED(pWav->Open(strFileName, NULL, WAVEFILE_READ)))
    wfx = pWav->GetFormat();
    dwSize = pWav->GetSize();
    dwLen = (DWORD) (1000 * dwSize / wfx->nAvgBytesPerSec);
  if (pWav) delete pWav;
  return dwLen;

Community Additions

© 2014 Microsoft