Advertisement

WAV File format

Started by July 12, 2000 12:32 PM
4 comments, last by UraniumRod 24 years, 5 months ago
Could someone please explain to me the file format of a PCM wav file. A web site on the topic would also be very helpful. I need to be able to read the wavs into memory for my playback. The book that I have tells me to use the functions in WAVE.C but that file doesn''t exist on the CD that come with it duh... Thanks for all your help. ------------------------------ "My sword is like a menacing cloud, but instead of rain, blood will pour in its path." - Sehabeddin, Turkish Military Commander 1438.
------------------------------"My sword is like a menacing cloud, but instead of rain, blood will pour in its path." - Sehabeddin, Turkish Military Commander 1438.
Click Here
Advertisement
Here''s some old stuff from a sound wrapper of mine, about how to do mmio reads for your .wav loads... it''s a bit ugly, but it works. To use mmio, import library winmm.lib and include header mmsystem.h. I guess you could read everything yourself using the WAVE canonical but why bother when they give you all the spiffy read functions for riff''s in your winmm libraries?

BOOL CDSoundWAV::Load(CString fileName){  m_szFileName = fileName;  WAVEFORMATEX formatEx;  DWORD bufSize1 = 0;  DWORD bufSize2 = 0;  // file handle  HMMIO hFile;  // chunks  MMCKINFO primary;  MMCKINFO secondary;  // set up the primary chunk  primary.ckid         = (FOURCC)0;  primary.cksize       = 0;  primary.fccType      = (FOURCC)0;  primary.dwDataOffset = 0;  primary.dwFlags      = 0;  // secondary needs the same stuff so copy it over  secondary = primary;  // buffers for storage  UCHAR *tempBuffer = NULL;  UCHAR *buffer1    = NULL;  UCHAR *buffer2    = NULL;  // open the file  // check for validity  if ((hFile = mmioOpen(fileName.GetBuffer(0), NULL, MMIO_READ|MMIO_ALLOCBUF)) == NULL)  {    MessageBox(NULL, "Failed to open the .WAV file.", "Load Failed", MB_OK|MB_ICONEXCLAMATION);    return FALSE;  }    // find the WAV file notice  primary.fccType = mmioFOURCC(''W'',''A'',''V'',''E'');  // make sure it is a real WAV file  if (mmioDescend(hFile, &primary, NULL,MMIO_FINDRIFF))  {    // doh! close it.    mmioClose(hFile,0);    MessageBox(NULL, ".WAV file corrupt.", "Load Failed", MB_OK|MB_ICONEXCLAMATION);    return FALSE;  }  // find the format section  secondary.ckid = mmioFOURCC(''f'',''m'',''t'','' '');  if (mmioDescend(hFile, &secondary, &primary, 0))  {    // no format?  close it.    mmioClose(hFile,0);    MessageBox(NULL, ".WAV format corrupt.", "Load Failed", MB_OK|MB_ICONEXCLAMATION);    return FALSE;  }  // read WAV format info  if (mmioRead(hFile, (char*)&formatEx, sizeof(formatEx)) != sizeof(formatEx))  {    // something else is wrong    mmioClose(hFile,0);    MessageBox(NULL, "Incorrect FormatEx size.", "Load Failed", MB_OK|MB_ICONEXCLAMATION);    return FALSE;  }  // make sure it''s PCM format  if (formatEx.wFormatTag != WAVE_FORMAT_PCM)  {    // so close, and yet so far...    mmioClose(hFile,0);    MessageBox(NULL, "Incorrect .WAV format.", "Load Failed", MB_OK|MB_ICONEXCLAMATION);    return FALSE;  }  // we have a format.  time to get the data...  if(mmioAscend(hFile,&secondary,0))  {    // error.  here we go again.    mmioClose(hFile,0);    MessageBox(NULL, "MMIO ascending error.", "Load Failed", MB_OK|MB_ICONEXCLAMATION);    return FALSE;  }  // trolling for data  secondary.ckid = mmioFOURCC(''d'',''a'',''t'',''a'');  if (mmioDescend(hFile,&secondary,&primary,MMIO_FINDCHUNK))  {    // no data    mmioClose(hFile,0);    MessageBox(NULL, "MMIO descending error.", "Load Failed", MB_OK|MB_ICONEXCLAMATION);    return FALSE;  }  // everything is just peachy, read the data.  // allocate memory for the temporary buffer  m_pByte = (void*)malloc(secondary.cksize);  // read the .WAV data  int check = mmioRead(hFile,(char*)m_pByte,secondary.cksize);  // close the file  mmioClose(hFile,0);  //m_pByte = (LPBYTE)tempBuffer;  m_dwLength = secondary.cksize;  // set up the wave format  m_FormatEx = new WAVEFORMATEX;  memset((void*)m_FormatEx, 0, sizeof(WAVEFORMATEX));  memcpy((void*)m_FormatEx, (void*)&formatEx, sizeof(WAVEFORMATEX));    return TRUE;} // end CDSoundWAV::Load 


-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Damn. and I wrote my own chunk-finding routines. Oh well, that''s what I get for never learning the win32 API.
Ironically, I had the canonical on file because I''m currently writing my own chunk-finding routines as well... because my current project is using filtering to determine the archival parameters for incoming binary streams of various types...
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Thank you to all of your replys you have been a great help.

------------------------------

"My sword is like a menacing cloud, but instead of rain, blood will pour in its path." - Sehabeddin, Turkish Military Commander 1438.
------------------------------"My sword is like a menacing cloud, but instead of rain, blood will pour in its path." - Sehabeddin, Turkish Military Commander 1438.

This topic is closed to new replies.

Advertisement