線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1389
推到 Plurk!
推到 Facebook!

錄音程式問題

尚未結案
huei_brother
一般會員


發表:36
回覆:15
積分:10
註冊:2004-08-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-11-18 11:47:17 IP:140.127.xxx.xxx 未訂閱
各位大家好 我依板上建議到Borland網站上下載了一個錄音程式但RUN後都產生檔名為亂碼 是否存檔程式部分有錯啊我試了很多次都一樣不知可不可請大家幫個忙幫我看看是程式哪出問題囉謝謝    #include  #pragma hdrstop #include #include "Unit1.h" //-------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //-------------------------------------------------------------------- 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 ) 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,"audd.wav",GetTickCount()0000L); // 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"; } //--------------------------------------------------------------------
GGL
資深會員


發表:104
回覆:600
積分:335
註冊:2006-11-05

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-11-19 10:57:33 IP:211.76.xxx.xxx 未訂閱
你看一下這篇 http://delphi.ktop.com.tw/topic.php?topic_id=57346 我之前用跟你一樣的程式碼也會有亂碼的問題,這篇下面有人回文,我試過了可以用 關於你在那篇回的問題... 他的 class="code"> MCI_SAVE_PARMS mciSP; mciSP.lpfilename ="c:\\a.wav"; 然後__fastcall TForm1::~TForm1(void)你要先在Unit1.h裡面定義 發表人 - GGL 於 2004/11/19 11:04:23
bugmans
高階會員


發表:95
回覆:322
積分:188
註冊:2003-04-12

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-11-20 19:32:12 IP:218.166.xxx.xxx 未訂閱
謝謝GGL的指正,我已經作修改了
系統時間:2024-11-25 1:51:07
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!