资源简介
VC++ 录音并生成wav文件,VC++6.0录音程序,采样频率和采样精度,录音完毕后自动生成WAVE文件。
代码片段和文件信息
//Download by http://www.NewXing.com
// HwMCI.cpp: implementation of the CHwMCI class.
//
//////////////////////////////////////////////////////////////////////
#include “stdafx.h“
#include “xuefeng.h“
#include “HwMCI.h“
// 为 MCI 函数添加库文件
#include
#pragma comment ( lib “winmm.lib“ )
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CHwMCI::CHwMCI()
: m_wDeviceID ( NULL )
{
memset ( m_szErrorStr 0 sizeof(m_szErrorStr) );
}
CHwMCI::~CHwMCI()
{
Close ();
}
MCIERROR CHwMCI::hwMciSendCommand(
MCIDEVICEID IDDevice
UINT uMsg
DWORD fdwCommand
DWORD dwParam
)
{
MCIERROR mciError = ::mciSendCommand ( IDDevice uMsg fdwCommand dwParam );
if ( mciError != 0 )
{
memset ( m_szErrorStr 0 sizeof(m_szErrorStr) );
mciGetErrorString ( mciError m_szErrorStr sizeof(m_szErrorStr) );
#ifdef _DEBUG
AfxMessageBox ( m_szErrorStr );
#endif
}
return mciError;
}
BOOL CHwMCI::Open(LPCTSTR lpszWaveFileName/*=NULL*/)
{
MCI_OPEN_PARMS OpenParms = {0};
OpenParms.lpstrDeviceType = (LPCSTR)(lpszWaveFileName?NULL:MCI_DEVTYPE_WAVEFORM_AUDIO);
OpenParms.lpstrElementName = (LPCSTR)(lpszWaveFileName?lpszWaveFileName:““); // 打开的声音文件名
m_wDeviceID = NULL; // 打开的音频设备的ID
if ( hwMciSendCommand ( NULL
MCI_OPEN
( lpszWaveFileName?0:(MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID) ) | MCI_WAIT | MCI_OPEN_ELEMENT
(DWORD)(LPVOID) &OpenParms ) != 0 )
return FALSE;
m_wDeviceID = OpenParms.wDeviceID;
return TRUE;
}
void CHwMCI::Close()
{
if ( m_wDeviceID != NULL )
{
hwMciSendCommand ( m_wDeviceID MCI_CLOSE NULL NULL );
}
m_wDeviceID = NULL; // 打开的音频设备的ID
}
BOOL CHwMCI::Play(DWORD dwFrom/*=0*/ DWORD dwTo/*=0*/)
{
Stop ();
// 播放wave文件
MCI_PLAY_PARMS PlayParms = {0};
PlayParms.dwFrom = dwFrom; // 这是为了指定从什么地方(时间)播放WAVE文件
PlayParms.dwTo = dwTo;
if ( hwMciSendCommand ( m_wDeviceID MCI_PLAY MCI_FROM
(DWORD)(LPVOID)&PlayParms ) != 0 )
return FALSE;
return TRUE;
}
BOOL CHwMCI::Stop()
{
if ( m_wDeviceID == NULL ) return FALSE;
return ( hwMciSendCommand ( m_wDeviceID MCI_STOP NULL NULL ) == 0 );
}
BOOL CHwMCI::Pause()
{
if ( m_wDeviceID == NULL ) return FALSE;
return ( hwMciSendCommand ( m_wDeviceID MCI_PAUSE NULL NULL ) == 0 );
}
BOOL CHwMCI::Save(CString Filename)
{
Stop ();
MCI_SAVE_PARMS SaveParms = {0};
SaveParms.lpfilename = (LPCSTR) Filename;
return ( hwMciSendCommand ( m_wDeviceID
MCI_SAVE
MCI_SAVE_FILE | MCI_WAIT
(DWORD)(LPVOID) &SaveParms) == 0 );
}
LPSTR CHwMCI::GetErrorStr()
{
return m_szErrorStr;
}
BOOL CHwMCI::Rec ( int nChannelsWORD nSamplesPerSecint wBitsPerSample)
{
if ( nChannels != 1 && nChannels != 2 )
return
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 36596 2007-10-12 15:49 www.NewXing.com\waverecord\xuefeng.aps
....... 1540 2007-10-12 15:50 www.NewXing.com\waverecord\xuefeng.clw
文件 4557 2012-11-28 09:41 www.NewXing.com\waverecord\HwMCI.cpp
文件 247 2012-11-28 09:41 www.NewXing.com\waverecord\StdAfx.cpp
文件 2115 2012-11-28 09:41 www.NewXing.com\waverecord\xuefeng.cpp
文件 6324 2012-11-28 09:41 www.NewXing.com\waverecord\xuefengDlg.cpp
....... 4299 2007-10-12 11:58 www.NewXing.com\waverecord\xuefeng.dsp
....... 539 2007-10-12 11:58 www.NewXing.com\waverecord\xuefeng.dsw
文件 1389 2012-11-28 09:41 www.NewXing.com\waverecord\HwMCI.h
文件 1045 2012-11-28 09:41 www.NewXing.com\waverecord\resource.h
文件 1092 2012-11-28 09:41 www.NewXing.com\waverecord\StdAfx.h
文件 1373 2012-11-28 09:41 www.NewXing.com\waverecord\xuefeng.h
文件 1716 2012-11-28 09:41 www.NewXing.com\waverecord\xuefengDlg.h
....... 1078 2007-10-12 11:57 www.NewXing.com\waverecord\res\xuefeng.ico
....... 66560 2007-10-12 15:50 www.NewXing.com\waverecord\xuefeng.ncb
....... 135680 2007-10-12 15:50 www.NewXing.com\waverecord\xuefeng.opt
....... 1022 2007-10-12 15:50 www.NewXing.com\waverecord\xuefeng.plg
....... 6674 2007-10-12 15:49 www.NewXing.com\waverecord\xuefeng.rc
....... 399 2007-10-12 11:57 www.NewXing.com\waverecord\res\xuefeng.rc2
....... 3597 2007-10-12 11:57 www.NewXing.com\waverecord\ReadMe.txt
....... 46764 2007-10-12 15:48 www.NewXing.com\waverecord\test.wav
目录 0 2007-11-05 12:47 www.NewXing.com\waverecord\Debug
目录 0 2007-10-12 11:57 www.NewXing.com\waverecord\res
目录 0 2007-10-12 15:50 www.NewXing.com\waverecord
----------- --------- ---------- ----- ----
324606 24
- 上一篇:VC++6.0_MFC基于对话框简单计算器设计
- 下一篇:数据结构的迷宫问题 C语言
评论
共有 条评论