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

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

本文简介:选择自 slimak 的 blog

             c.调用mmioclose函数来关闭wave文件.

7.麦克录音系统的实现(micdemo)  

下面是该系统的界面:
 

对于录音来说最重要的就是csoundin类,下面就是该类的定义:

namespace perdubug {  // prevent the name-space pollution

class csoundin 
{
public: 
 bool     __initmic(); // get the best wave format supported by your sound card
                                     // and then i will use the format to capture sound.

 void     __closemic();


 bool     __openmic(); // open device and begin to capture with the best format(when
                                        // invoke __initmic function then you will get the best format
                                        // supported by host's sound card
 
 //
 // if your want to capture sound and export into a wav file please invoke this function
 // to tell me the full path then i will create the wav file.
 //
 void     __createoutputwavefile(const tchar * lpszfilename);
 
 // if you invoke any member function return error/false please
 // use this function to get the result...
 dword    __getlasterror();

 //
 // when the capture buffer is filled please invoke this function to 'add buffer'(actually
 // you should create two-circular buffers,when 1st buffer is filled then switch to 2st,1st
 // buffer will be wrote into wav file.
 //
 void addbuffer();
 
 virtual ~csoundin();
 
 friend csoundin & thesoundcapture();
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(); 

private:
 waveincaps  m_waveindevcaps;
 hwavein  m_wavein;
 wavehdr  m_waveheader;
 waveformatex m_waveformat; 
 
 uint    m_waveinsamplerate;
 int         m_nbmaxsamples;
 uint    m_sizerecord;

 dword   m_dwlasterror;

 enum { max_size_input_buffer = 1 * 2 * 1024 }; // samples * voie * size_samples

public:
 short  inputbuffer[max_size_input_buffer];   // used for int fft,many gui application
                                                                                                          // want to display sound peak so..
 bool   m_bterminatethread;                   //  to 'kill' wavecallback function
 bool   m_bimporttowavefile;
 
 cwavefile       m_wavefile;
};

} // end namespace perdubug

对于将录音保存在wav文件的工作主要是由cwavefile类来完成.下面是该类的定义:
//
// encapsulates reading or writing sound data to or from a wave file
//-----------------------------------------------------------------------------
class cwavefile
{
public:
    waveformatex* m_pwfx;        // pointer to waveformatex structure

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

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

go top