資源簡介
Windows下局域網(wǎng)語音對講程序 ,親測可行。

代碼片段和文件信息
//?Sound_send.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?
#include?
#include?
#include?
#include?
#pragma?comment(lib?“ws2_32.lib“?)
#pragma?comment(lib“Winmm.lib“)?
#define?MAXDATASIZE?10000
void?readAudioBlock(HWAVEIN?hWaveIn?LPSTR?block?DWORD?size);
int?main(int?argc?char*?argv[])
{
int?iClientSock;
// int?addr_len;
// int?numbytes;
char?buf[?MAXDATASIZE?];
struct?sockaddr_in?ClientAddr;
WSADATA?WSAData;?
if(?WSAStartup(?MAKEWORD(?2?2)?&WSAData?)?)
{
printf(?“initializationing?error!\n“?);
WSACleanup(?);
exit(?0?);
}
iClientSock?=?socket(?AF_INET?SOCK_DGRAM?0?);
if(?iClientSock?==?INVALID_SOCKET?)
{
printf(?“創(chuàng)建套接字失敗!\n“?);
WSACleanup(?);
exit(?0?);
}
ClientAddr.sin_family?=?AF_INET;
ClientAddr.sin_port?=?htons(4600);
ClientAddr.sin_addr.S_un.S_addr?=?inet_addr(?“127.0.0.1“?);//記得換IP
memset(?&(?ClientAddr.sin_zero?)?0?sizeof(?ClientAddr.sin_zero?)?);
HWAVEIN?hWaveIn;?/*?device?handle?*/
WAVEFORMATEX?wfx;?/*?look?this?up?in?your?documentation?*/
// MMRESULT?result;/*?for?waveOut?return?values?*/
/*
*?first?we?need?to?set?up?the?WAVEFORMATEX?structure.?
*?the?structure?describes?the?format?of?the?audio.
*/
wfx.nSamplesPerSec?=?8000; /*?sample?rate?*/
wfx.wBitsPerSample?=?16; /*?sample?size?*/
wfx.nChannels?=?1; /*?channels*/
/*
*?WAVEFORMATEX?also?has?other?fields?which?need?filling.
*?as?long?as?the?three?fields?above?are?filled?this?should
*?work?for?any?PCM?(pulse?code?modulation)?format.
*/
wfx.cbSize?=?0; /*?size?of?_extra_?info?*/
wfx.wFormatTag?=?WAVE_FORMAT_PCM;
wfx.nBlockAlign?=?(wfx.wBitsPerSample?>>?3)?*?wfx.nChannels;
wfx.nAvgBytesPerSec?=?wfx.nBlockAlign?*?wfx.nSamplesPerSec;
//?try?to?open?the?default?wave?device.?
if(waveInOpen(&hWaveIn?WAVE_MAPPER?&wfx?0?0?CALLBACK_NULL)?!=MMSYSERR_NOERROR)?
{
fprintf(stderr?“unable?to?openWAVE_MAPPER?device\n“);
ExitProcess(1);
}
while(1)
{
//numbytes?=?recvfrom(?iServerSock?buf?MAXDATASIZE?0?(?struct?sockaddr?*?)?&?ServerAddr?&addr_len?);
???//?writeAudioBlock(hWaveOutbufnumbytes);
int?t=sizeof(buf);
readAudioBlock(hWaveInbufsizeof(buf));
t=sizeof(buf);
int?sendbytes=sendto(iClientSockbufsizeof(buf)0(sockaddr*)&ClientAddrsizeof(ClientAddr));
printf(“%d\t“sendbytes);
}
/*
*?device?is?now?open?so?print?the?success?message
*?and?then?close?the?device?again.
*/
printf(“The?Wave?Mapper?device?was?opened?successfully!\n“);
// waveOutClose(hWaveIn);
return?0;
}
void?readAudioBlock(HWAVEIN?hWaveIn?LPSTR?block?DWORD?size)
{
WAVEHDR?header;
/*
*?initialize?the?block?header?with?the?size
*?and?pointer.
*/
ZeroMemory(&header?sizeof(WAVEHDR));
header.dwBufferLength?=?size;
header.lpData?=?block;
/*
*?prepare?the?block?for?playback
*/
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
????.......???1139712??2014-09-16?18:35??new_\發(fā)送\Debug\Sound_send.bsc
????.......????172083??2014-09-17?08:39??new_\發(fā)送\Debug\Sound_send.exe
????.......????207588??2014-09-17?08:39??new_\發(fā)送\Debug\Sound_send.ilk
????.......?????30168??2014-09-17?08:39??new_\發(fā)送\Debug\Sound_send.obj
????.......????334800??2014-09-16?18:35??new_\發(fā)送\Debug\Sound_send.pch
????.......????435200??2014-09-17?08:39??new_\發(fā)送\Debug\Sound_send.pdb
????.......????505105??2014-09-16?18:36??new_\發(fā)送\Debug\Sound_send.sbr
????.......??????1828??2014-09-16?18:35??new_\發(fā)送\Debug\StdAfx.obj
????.......??????4003??2014-09-16?18:35??new_\發(fā)送\Debug\StdAfx.sbr
????.......?????99328??2014-09-17?08:39??new_\發(fā)送\Debug\vc60.idb
????.......????143360??2014-09-17?08:39??new_\發(fā)送\Debug\vc60.pdb
????.......??????1232??2014-09-16?16:20??new_\發(fā)送\ReadMe.txt
????.......??????3674??2014-09-17?08:39??new_\發(fā)送\Sound_send.cpp
????.......??????4584??2014-09-16?16:20??new_\發(fā)送\Sound_send.dsp
????.......???????543??2014-09-16?16:20??new_\發(fā)送\Sound_send.dsw
????.......?????41984??2014-09-17?08:39??new_\發(fā)送\Sound_send.ncb
????.......????107520??2014-09-17?08:31??new_\發(fā)送\Sound_send.opt
????.......?????????0??2014-09-17?08:39??new_\發(fā)送\Sound_send.plg
????.......???????297??2014-09-16?16:20??new_\發(fā)送\StdAfx.cpp
????.......???????769??2014-09-16?16:20??new_\發(fā)送\StdAfx.h
????.......???1147904??2014-09-16?16:14??new_\接收\Debug\Sound_win.bsc
????.......????172081??2014-09-16?20:46??new_\接收\Debug\Sound_win.exe
????.......????237144??2014-09-16?20:46??new_\接收\Debug\Sound_win.ilk
????.......?????29678??2014-09-16?20:46??new_\接收\Debug\Sound_win.obj
????.......????334800??2014-09-16?16:14??new_\接收\Debug\Sound_win.pch
????.......????435200??2014-09-16?20:46??new_\接收\Debug\Sound_win.pdb
????.......????502071??2014-09-16?16:14??new_\接收\Debug\Sound_win.sbr
????.......??????1792??2014-09-16?16:14??new_\接收\Debug\StdAfx.obj
????.......??????4000??2014-09-16?16:14??new_\接收\Debug\StdAfx.sbr
????.......?????91136??2014-09-16?20:46??new_\接收\Debug\vc60.idb
............此處省略18個(gè)文件信息
- 上一篇:cyclone引腳定義
- 下一篇:波動(dòng)方程有限差分模擬
評論
共有 條評論