一個簡單的錄音放音程序[1]

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

本文简介:选择自 xu123 的 blog

/*這是以前寫的一個簡單的錄音程序(是dll文件).在此備份.調用時需要映射這幾個消息:

 on_message(mm_wim_open,mmwimopen)
 on_message(mm_wim_data,mmwimdata)
 on_message(mm_wim_close,mmwimclose)
 on_message(mm_wom_close,mmwomclose)
 on_message(mm_wom_open,mmwomopen)
 on_message(mm_wom_done,mmwomdone)
*/

/* .h*/

#include "windows.h"
#include "mmsystem.h"

#pragma comment(lib,"winmm.lib")
#ifdef wavefileex_exports
#define wavefileex_api __declspec(dllexport)
#else
#define wavefileex_api __declspec(dllimport)
#endif


// 森瀎岆植 wavefileex.dll 絳堤腔
class wavefileex_api cwavefileex {
public:
 cwavefileex(void);
 cwavefileex(hwnd hwnd);
 ~cwavefileex();
 /* wave length*/
 dword getwavelen_size();
 dword getwavelen_time();
 /* record */
 bool recordwav(lpstr filename,int devno);
 bool stoprecordwav();
 bool playwav(lpstr filename,int sounddevno = -1);
 bool stopplaywav();
 /* select devno */
 void selectdevno(int devno);
 void pausewav();
 /* call back function wavein*/
 void mmwimopen();
 void mmwimdata(wparam wparam,lparam lparam);
 void mmwimclose();
 /* call back function waveout */
 void mmwomopen();
 void mmwomdone(wparam wparam,lparam lparam);
 void mmwomclose();
 /* the handle of play wave */
 void setwnd(hwnd hwnd);
protected:
 bool createwavefile(void);
 void getlasterrormsg(lpctstr flag);
 
 bool write(char* data,dword dwlen);
 void close();

private:
 char m_filename[256];
 waveformatex m_waveformat;
 dword m_wavelength;
 dword dwdatalength;

 hwavein m_hwi;
 hwaveout m_hwo;
 handle m_hfile;
 int m_devno;
 hwnd m_hwnd;
 mmckinfo m_mminfoparent;
 mmckinfo m_mminfochild;

 pwavehdr pwavehdr1 ;
 pwavehdr pwavehdr2;
 wavehdr waveouthdr;
 hmmio m_hm;
 hmmio m_hmmio;
 char* lpdwdata;
 byte* pbuf1;
 byte* pbuf2;
 dword m_dwsize;
 char* psavebuffer;
 char* pnewbuffer;
};

/*

.cpp

*/

#include "stdafx.h"
#include "wavefileex.h"
#include "windows.h"
#include "assert.h"
#include "tchar.h"
#include <malloc.h>

#pragma comment(lib,"user32.lib")

bool apientry dllmain( handle hmodule,
                       dword  ul_reason_for_call,
                       lpvoid lpreserved
      )
{
 switch (ul_reason_for_call)
 {
 case dll_process_attach:
 case dll_thread_attach:
 case dll_thread_detach:
 case dll_process_detach:
  break;
 }
    return true;
}

/* 蚚懂耼秞 凳婖勤硑*/
cwavefileex::cwavefileex(hwnd hwnd)
{
 assert(hwnd);
 m_hwnd = hwnd;
 m_devno = -1;
 strcpy(this->m_filename,"");
 m_hfile = 0x00;
 m_hwi   = 0x00;
 m_hwo   = 0x00;
 lpdwdata = 0x00;
 /* */
 m_waveformat.wformattag=wave_format_pcm;
 m_waveformat.nchannels=1;
 m_waveformat.nsamplespersec=8000;
 m_waveformat.navgbytespersec=8000;
 m_waveformat.nblockalign=1;
 m_waveformat.wbitspersample=8; //硌隅耼秞踖宒
 m_waveformat.cbsize=0;

 m_dwsize = 10240;
 m_hmmio = 0x00;
 psavebuffer = 0x00;
 pnewbuffer  = 0x00;

 pwavehdr1 =(wavehdr*)malloc(sizeof(wavehdr));
 pwavehdr2 =(wavehdr*)malloc(sizeof(wavehdr));
 pbuf1 = 0x00;
 pbuf2 = 0x00;

}
/* 蚚懂畦溫 凳婖勤硑*/
cwavefileex::cwavefileex()
{
 m_devno = -1;
 strcpy(this->m_filename,"");

本文关键:一個簡單的錄音放音程序
  相关方案
Google
 

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

go top