获取WAV文件的相关信息

主要实现代码:

 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);

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值