//--------------------------------------------------------------------------- #include
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1; HINSTANCE g_hInstance;
HANDLE m_hMCIWnd;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
m_hMCIWnd=MCIWndCreate(Handle,
g_hInstance,
WS_CHILD | WS_OVERLAPPED | WS_CAPTION | WS_BORDER |
MCIWNDF_RECORD | MCIWNDF_SHOWALL,
NULL );
if ( NULL==m_hMCIWnd )
{
MessageBox(Handle,"Error Creating MCIWnd Window!",NULL, MB_OK);
return;
}
Button1->Enabled=true;
Label1->Caption="IDLE";
}
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1(void)
{
if ( Button2->Enabled )
Button2Click(NULL); MCIWndDestroy(m_hMCIWnd);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
MCIWndNew(m_hMCIWnd, "waveaudio");
// change the default audio setting (which is 11khz 8bit mono)
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; 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 )
{
char buffer[100];
mciGetErrorString(result, buffer, sizeof(buffer));
MessageBox( NULL, buffer, "MCI_WAVE_SET_1", MB_OK);
return;
} MCIWndRecord(m_hMCIWnd); Button1->Enabled=false;
Button2->Enabled=true;
Label1->Caption="RECORDING";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
MCIWndStop(m_hMCIWnd);
MCIWndSave(m_hMCIWnd,"test.wav");
MCIWndClose(m_hMCIWnd); Button1->Enabled=true;
Button2->Enabled=false;
Label1->Caption="IDLE";
}
//---------------------------------------------------------------------------
這個錄音程式很好用,但我用時原本要存成test.wav的檔案,會變成亂碼?
不知道為什麼?請大家試試吧!!!如有解決方式也分享一下吧...呵呵 有收穫記得回饋,讓我們台灣跨出程式的出頭天...