/*==============================================================================
Simple Audio Recording with the MCIWnd* functions
Pankhurst Algorithmics (www.pankhurst.com)
==============================================================================*/
#include <vcl.h>
#pragma hdrstop
#include <vfw.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
extern HINSTANCE g_hInstance;
//---------------------------------------------------------------------------
HANDLE m_hMCIWnd =NULL;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
//
// open our MCI window along with the program
//
m_hMCIWnd=MCIWndCreate(Handle,
g_hInstance,
//
// uncomment 'WS_VISIBLE' line to display the MCI window
//
// WS_VISIBLE |
WS_CHILD | WS_OVERLAPPED | WS_CAPTION | WS_BORDER |
MCIWNDF_RECORD | MCIWNDF_SHOWALL,
NULL );
if ( NULL==m_hMCIWnd ) // error?
{
MessageBox(Handle,"Error Creating MCIWnd Window!",NULL, MB_OK);
return;
}
//
// enable record button
//
Button1->Enabled=true;
Label1->Caption="IDLE";
}
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1(void)
{
//
// close our MCI program as we close the form
//
if ( Button2->Enabled ) // enabled stop button means we are still recording!
Button2Click(NULL); // stop and save file before closing
//
// close our MCI window now
//
MCIWndDestroy(m_hMCIWnd);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//
// start recording
//
// create new .WAV file (internal - not yet on disk)
MCIWndNew(m_hMCIWnd, "waveaudio");
// change the default audio setting (which is 11khz 8bit mono)
// to do this successfully, we need to change all of the following:
// MCI_WAVE_SET_PARMS members: wFormatTag, wBitsPerSample,
// nChannels, nSamplesPerSec, nAvgBytesPerSec, and nBlockAlign
MCI_WAVE_SET_PARMS set_parms;
set_parms.wFormatTag = WAVE_FORMAT_PCM;
set_parms.wBitsPerSample = 16;
set_parms.nChannels = 1;
set_parms.nBlockAlign = (set_parms.nChannels*set_parms.wBitsPerSample)/8;
set_parms.nSamplesPerSec = 44100;
set_parms.nAvgBytesPerSec = ((set_parms.wBitsPerSample) *
set_parms.nChannels *
set_parms.nSamplesPerSec)/8;
// now send the format changes with MCI_SET
int deviceID=MCIWndGetDeviceID(m_hMCIWnd);
int result = mciSendCommand( deviceID, MCI_SET,
MCI_WAIT
| MCI_WAVE_SET_FORMATTAG
| MCI_WAVE_SET_BITSPERSAMPLE
| MCI_WAVE_SET_CHANNELS
| MCI_WAVE_SET_SAMPLESPERSEC
| MCI_WAVE_SET_AVGBYTESPERSEC
| MCI_WAVE_SET_BLOCKALIGN,
(DWORD)(LPVOID)&set_parms);
if ( result ) // failed?
{
char buffer[100];
mciGetErrorString(result, buffer, sizeof(buffer));
MessageBox( NULL, buffer, "MCI_WAVE_SET_1", MB_OK);
return;
}
// now we can record at our audio setting
MCIWndRecord(m_hMCIWnd);
//
// set GUI buttons so we know we can stop
//
Button1->Enabled=false;
Button2->Enabled=true;
Label1->Caption="RECORDING";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
//
// stop recording and save as unique local file
//
// generate unique filename from timer
char file[260]="";
wsprintf(file,"aud%05d.wav",GetTickCount()%100000L); // random filename
//
// now stop audio and save to disk
MCIWndStop(m_hMCIWnd);
MCIWndSave(m_hMCIWnd,file);
MCIWndClose(m_hMCIWnd);
//
// now set buttons so we know we can stop
//
Button1->Enabled=true;
Button2->Enabled=false;
Label1->Caption="IDLE";
}
//---------------------------------------------------------------------------
给程序加上录音的功能
需积分: 9 65 浏览量
2008-06-03
08:58:31
上传
评论
收藏 6KB ZIP 举报
wujianmingstudent
- 粉丝: 0
- 资源: 7
最新资源
- springboot-mavenBaseDemo 内容包含:springboot的maven基础状态,1.8JDK可以直接运行
- otis rsl远程串行接口协议标准.pdf
- buildx构建镜像时所需的镜像文件
- F103-霸道开发板2.8寸电阻触摸屏例程.rar
- Google(高德)地图瓦片python代码下载
- Python实现输出杨辉三角形
- polsarpro官方教程、操作说明 PolSARpro v5.0 Software Training Course
- STM32 TouchGFX的使用二图片显示
- buildx镜像文件,也可以通过网上其他方式获取
- 【中级软件设计师】上午题12-软件工程(2):单元测试、黑盒测试、白盒测试、软件运行与维护
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈