中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Visual C++ > 综合文章
Windows环境下的麦克风录音系统(6)
作者:未知 时间:2004-03-03 12:12 出处:Blog 责编:chinaitpower
              摘要:暂无

对于录音来说最重要的就是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

    HMMIO              m_hmmio;              // MM I/O handle for the WAVE

    MMCKINFO      m_ck;                      // Multimedia RIFF chunk

    MMCKINFO      m_ckRiff;               // Use in opening a WAVE file

    DWORD             m_dwSize;             // The size of the wave file

    MMIOINFO       m_mmioinfoOut;

    DWORD             m_dwFlags;

    BOOL                 m_bIsReadingFromMemory;

    BYTE*               m_pbData;

    BYTE*               m_pbDataCur;

    ULONG              m_ulDataSize;

    CHAR*              m_pResourceBuffer;   

protected:

    HRESULT ReadMMIO();

    HRESULT WriteMMIO( WAVEFORMATEX *pwfxDest );

 

public:

    CWaveFile();

    ~CWaveFile();

 

    HRESULT Open( LPCTSTR strFileName, WAVEFORMATEX* pwfx, DWORD dwFlags );

    HRESULT OpenFromMemory( BYTE* pbData, ULONG ulDataSize,

                                                        WAVEFORMATEX* pwfx, DWORD dwFlags );

    HRESULT Close();

 

    HRESULT Read( BYTE* pBuffer, DWORD dwSizeToRead, DWORD* pdwSizeRead );

    HRESULT Write( UINT nSizeToWrite, BYTE* pbData, UINT* pnSizeWrote );

 

    DWORD   GetSize();

    HRESULT ResetFile();

    WAVEFORMATEX* GetFormat() { return m_pwfx; };

};

 

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有