Windows环境下的麦克风录音系统[7]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 slimak 的 blog

              // 设置定时器是为了画波形用的 
 settimer(1, 200 /*start slow*/, null);
           }
 
    4.在定时器的回调函数中画波形.
           void cmicdemodlg::ontimer(uint nidevent)
            {
     if(nidevent == 1)
    { 
  static const int xcon = 13;
  static const int ycon = 13;
  static const int wcon = 623;
  static const int hcon = 80;
  
  cclientdc dc(this);
  
  cbitmap   bitmap;
  cbitmap * pbmold = null;  
  cdc         dcmem;
  
  dcmem.createcompatibledc(&dc);  
  bitmap.createcompatiblebitmap(&dc,wcon,hcon);
  
  pbmold = dcmem.selectobject(&bitmap);
  
  dcmem.patblt(0,0,wcon,hcon, whiteness);  
  dcmem.moveto(0,hcon/2);
  
  //
  // display incomming signal--key idea!
  //
  for(int x =0 ; x < wcon; x++)  // display input
  {
   dcmem.lineto(x,(hcon >> 1) - (thesoundcapture().inputbuffer[x] >> 7));
  }
  
  dc.bitblt(xcon,ycon,wcon,hcon,&dcmem, 0, 0, srccopy);
  
  dcmem.selectobject(pbmold);
  dcmem.deletedc(); 
   }
   else
          cdialog::ontimer(nidevent);
            }
      
      5.点击停止(stop)按钮的时候停止录音和写wav文件
                  void cmicdemodlg::onstop()
                 {
          // todo: add your control notification handler code here
                     m_btnstop.enablewindow(false);

                       thesoundcapture().__closemic();

         m_btnstart.enablewindow(true);
                 }
看完整段代码你可能会很奇怪怎么在cmicdemodlg中居然都没有定义一个csoundin对象??呵呵,原因很简单,因为设备的独占性所以在一个时刻只能有一个csoundin对象存在(因为csoundin对象需要占据录音设备),所以我们必须限制程序员生成csoundin对象的数量,怎么限制呢?那就是把csoundin的构造函数放在private区域里面:
  
     private:
 bool  getbestwaveformat(waveformatex & waveformatex);
 
 // because sound card is one and only so i must limit the number of csoundin object,
 // but how to limit the class object nums?maybe put constructor into private scope is
 // a good idea,:-)
 csoundin(); 

这样的话就根本无法声明一个csoundin对象,不信你试一下在你的代码中写上:
     csoundin  soundinobj;
 能编译通过吗?肯定是不能,那如何调用csoundin的成员函数呢?答案是通过一个全局函数:

              // global function,:-(
              // client can only through this function to use csoundin object
              csoundin & thesoundcapture()
              {
      static csoundin p;
      return p;
               }

  这时候你应该明白了为什么上面的代码中调用csoundin的成员函数的时候都是用thesoundcapture来做的原因了吧.
 
参考资料

本文关键:Waveform Aduio APIs, Multimedia File I/O APIs,waveInXXX,mmioXXX,麦克风,录音,波形文件,VC6++
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top