![]() |
|
論壇說明 |
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
![]() ![]() |
|
主題工具 | 顯示模式 |
![]() |
#1 |
註冊會員
|
![]() 請問各位大大
我用TNMUDP來連線,傳送聲音 可是我傳送到接收端電腦時,傳送的電腦也為出現聲音,這是為什麼呢? 還有我用4個暫存器,每個暫存器大小是8000,再把8000分四次傳送(此時聲音會一直重複出現)不知是何原因造成的?? 以下是程式 //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" #include <windows.h> #include <mmsystem.h> #include <mmreg.h> #include <string.h> #define bufsize 8000 HWND hWnd; HWAVEIN hwi; HWAVEOUT hwo; WAVEFORMATEX wfx; WAVEHDR wavehdr_in,wavehdr_out; char buf[4][bufsize]; void Sound_set_struct(); void Sound_initial_Record(); void Sound_initial_Play(); void CALLBACK waveInProc(HWAVEIN hwi, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2); void SRecord(); int q,w=0; int cnt; int choosebuf=0; int cnt1; int choosebuf1=0; //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Form1->SoundRx->RemoteHost = Form1->Edit1->Text; Form1->SoundTx->RemoteHost = Form1->Edit1->Text; GetIP(Edit1->Text.c_str()); q=0; } //--------------------------------------------------------------------------- void GetIP(char *temp) { Form1->SoundRx->RemoteHost=temp; Form1->SoundTx->RemoteHost=temp; } //-------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { Sound_set_struct(); Sound_initial_Record(); Sound_initial_Play(); //SRecord(); Sound_initial_Record(); } //--------------------------------------------------------------------------- void Sound_set_struct() { wfx.wFormatTag = WAVE_FORMAT_PCM; wfx.nChannels = 1; wfx.nSamplesPerSec = 8000; wfx.wBitsPerSample = 8; wfx.nBlockAlign = 1; wfx.nAvgBytesPerSec = wfx.nSamplesPerSec*wfx.nBlockAlign; wfx.cbSize = 0; wavehdr_in.lpData =buf[0] ; wavehdr_in.dwBufferLength =bufsize; wavehdr_in.dwFlags =0; wavehdr_out.lpData =buf[0] ; wavehdr_out.dwBufferLength =bufsize; wavehdr_out.dwFlags =0; } void Sound_initial_Record() { waveInOpen(&hwi,WAVE_MAPPER,&wfx,(DWORD)waveInProc,NULL,CALLBACK_FUNCTION); waveInPrepareHeader(hwi,&wavehdr_in,sizeof(WAVEHDR)); waveInAddBuffer(hwi,&wavehdr_in,sizeof(WAVEHDR)); waveInStart(hwi); } void Sound_initial_Play() { waveOutOpen(&hwo,WAVE_MAPPER,&wfx,NULL,NULL,CALLBACK_NULL); waveOutPrepareHeader(hwo,&wavehdr_out,sizeof(WAVEHDR)); } void CALLBACK waveInProc(HWAVEIN hwi, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) { switch(uMsg) { case WIM_OPEN: break; case WIM_DATA: for(int i=0; i<4; i++) { cnt = 2000*i; Form1->SoundTx->SendBuffer((buf[choosebuf]+cnt),2000,2000); } if (choosebuf != 3) choosebuf++; else { choosebuf = 0; } waveInUnprepareHeader(hwi,&wavehdr_in,sizeof(WAVEHDR)); //釋放錄音buffer wavehdr_in.lpData =buf[choosebuf] ; wavehdr_in.dwFlags =0; wavehdr_in.dwBufferLength =bufsize; waveInPrepareHeader(hwi,&wavehdr_in,sizeof(WAVEHDR)); waveInAddBuffer(hwi,&wavehdr_in,sizeof(WAVEHDR)); waveInStart(hwi); w++; Form1->Edit3->Text=w; break; } } //---------------------------------------------------------------------------- void __fastcall TForm1::SoundRxDataReceived(TComponent *Sender, int NumberBytes, AnsiString FromIP, int Port) { for(int f=0; f<4; f++) { cnt1= f*2000; SoundRx->ReadBuffer((buf[choosebuf1]+cnt1),2000,2000); } waveOutUnprepareHeader(hwo,&wavehdr_out,sizeof(WAVEHDR)); wavehdr_out.lpData = buf[choosebuf1] ; wavehdr_out.dwBufferLength =bufsize; waveOutPrepareHeader(hwo,&wavehdr_out,sizeof(WAVEHDR)); waveOutWrite(hwo,&wavehdr_out,sizeof(WAVEHDR)); q++; Form1->Edit2->Text=q; if (choosebuf1!= 3) choosebuf1++; else choosebuf1=0; } //------------------------------------------------------------------------- |
![]() |
送花文章: 0,
![]() |
![]() ![]() |
|
|
![]() |
||||
主題 | 主題作者 | 討論區 | 回覆 | 最後發表 |
請教有關網路連線問題 | sunlei | 一般電腦疑難討論區 | 3 | 2004-05-22 08:55 PM |
ADSL連線問題 | hum | 一般電腦疑難討論區 | 6 | 2004-04-18 01:28 PM |
網路連線問題 | AngusII | 軟體應用問題討論區 | 2 | 2004-03-19 12:47 AM |
cuteftp 使用連線問題 | brucehkn | 一般電腦疑難討論區 | 2 | 2003-12-08 06:09 PM |