主要实现代码:
HMMIO m_hmmio;
MMCKINFO m_MMCkInfoParent;
WAVEFORMATEX m_PCMWaveFmtRecord;
MMCKINFO m_MMCkInfoChild;
TCHAR bigBuff[2048] = ""; // maximum common dialog buffer size
TCHAR szFilter[] =
"Text Files (*.wav)|*.wav|All Files (*.*)|*.*||";
//TCHAR csFileName[MAX_PATH];
//CString csFileName;
CString m_strFilePath;
CString strWaveInformation;
CString szExtFile;
CFileDialog dlg(TRUE, NULL, NULL,
OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, szFilter);
// Modify OPENFILENAME members directly to point to bigBuff
dlg.m_ofn.lpstrFile = bigBuff;
dlg.m_ofn.nMaxFile = sizeof(bigBuff);
if(dlg.DoModal() == IDOK)
{
m_strFilePath = dlg.GetPathName();
}
else
return;
m_hmmio = mmioOpen((LPSTR)(LPCTSTR)m_strFilePath,NULL,MMIO_READ);
if(!m_hmmio)
{
AfxMessageBox("unable to open Sound MM File");
return ;
}
m_MMCkInfoParent.fccType = mmioFOURCC('W','A','V','E');
int errorCode = mmioDescend(m_hmmio, &m_MMCkInfoParent,NULL,MMIO_FINDRIFF);
if(errorCode)
{
AfxMessageBox("Error descending into file");
mmioClose(m_hmmio,0);
m_hmmio = NULL;
return ;
}
m_MMCkInfoChild.ckid = mmioFOURCC('f','m','t',' ');
errorCode = mmioDescend(m_hmmio,&m_MMCkInfoChild,&m_MMCkInfoParent,MMIO_FINDCHUNK);
if(errorCode)
{
AfxMessageBox("Error descending in file");
mmioClose(m_hmmio,0);
m_hmmio = NULL;
return ;
}
DWORD bytesRead = mmioRead(m_hmmio,(LPSTR)&m_PCMWaveFmtRecord,m_MMCkInfoChild.cksize);
if(bytesRead < 0)
{
AfxMessageBox("Error reading PCM wave format record");
mmioClose(m_hmmio,0);
return ;
}
strWaveInformation.Format("wFormatTag = %d , nChannels = %d, nSamplesPerSec = %d, nAvgBytesPerSec = %d, nBlockAlign = %d, wBitsPerSample = %d, cbSize = %d",
m_PCMWaveFmtRecord.wFormatTag, m_PCMWaveFmtRecord.nChannels,
m_PCMWaveFmtRecord.nSamplesPerSec ,m_PCMWaveFmtRecord.nAvgBytesPerSec ,
m_PCMWaveFmtRecord.nBlockAlign, m_PCMWaveFmtRecord.wBitsPerSample,m_PCMWaveFmtRecord.cbSize);
AfxMessageBox(strWaveInformation);
mmioClose(m_hmmio,0);