Click to See Complete Forum and Search --> : wav parameters retrieving


serges1966
January 7th, 2003, 10:11 AM
I am using in my multimedia project very basic sound playback using PlaySound function.
Now I need to be able get wav file playback duration prior to actual playing. Is there a simple way to do that?
I have scouted MSDN for a several hours but could not get simple and clear answer how to do that.
I believe there supposed to be a function that retrieves all sound file parameters, like ones present in multiple sound players: time length, format, sampling frequency, etc.
Any advise would be helpful.
Serge

ctraill
January 9th, 2003, 11:01 AM
struct
{
DWORD wFormatTag; // Format category
DWORD dwFormatLen; // Length of format chunk - always 0x10
WORD wReserved; // Always 0x01
WORD wChannels; // Number of channels
DWORD dwSamplesPerSec; // Sampling rate
DWORD dwAvgBytesPerSec; // For buffer estimation
WORD wBytesPerSample;
WORD wBitsPerSample;
} FormatChunk;


Can't remember but I think I got that data structure from someone here. That is a list of all the details that are stored in the start of a wav file. So if you used some code like,


char ch[1];
CFile waveFile;
if(waveFile.Open(wavName,CFile::modeRead|CFile::typeBinary)==FALSE)
{
TRACE("Error opening file");
return NULL;
}


//read till we get to the start of above chunk header
while(1)
{
waveFile.Read(ch,1);
TRACE("%c\n",ch[0]);
if(ch[0] == 'E')
break;
}

waveFile.Read(&FormatChunk,sizeof(FormatChunk));


you would get all of those details about the Wav file. I don't know how to get the length though, I suppose you could use the sample rate, bit rate and file-size to calculate it but I've not tried doing that before.

Hope it helps