// Read in the wave header
Waveheader Wavhdr;
if (fread(&Wavhdr, sizeof(Wavhdr), 1, fp) != 1)
{
ShowMessage("Read File Header Error ! ");
fclose(fp);
return NULL;
}
// Figure out the size of the data region
DWORD dwSize = Wavhdr.dwDSize;
// Is this a stereo or mono file?
BOOL bStereo = Wavhdr.wChnls > 1 ? TRUE : FALSE;
// Create the sound buffer for the wave file
if (!CreateSoundBuffer(dwSize, Wavhdr.dwSRate, Wavhdr.BitsPerSample, Wavhdr.wBlkAlign, bStereo))
{
// Close the file
fclose(fp);
return false;
}
// Read the data for the wave file into the sound buffer
if (!ReadData(fp, dwSize, sizeof(Wavhdr)))
{
fclose(fp);
return false;
}
// Close out the wave file
fclose(fp);
return TRUE;
}
bool __fastcall TForm1::ReadData(FILE* fp, DWORD dwSize, DWORD dwPos)
{
// Seek to correct position in file (if necessary)
if (dwPos != 0xffffffff)
{
if (fseek(fp, dwPos, SEEK_SET) != 0) return false;
}
// Lock data in buffer for writing
LPVOID pData1;
DWORD dwData1Size;
LPVOID pData2;
DWORD dwData2Size;
HRESULT rval;