W
wuchunhua
Unregistered / Unconfirmed
GUEST, unregistred user!
音频捕捉部分已经完成。采用pcm 16-bit,44100H,单通道采集。
问题:以下代码如果采用udp发送方式,有吱吱的噪音,如果采用直接播放,没有噪音,
希望有经验的高手能指点迷经。
部分代码
procedure MMInDone(var msg:Tmessage);message MM_WIM_DATA;
...
procedure MMInDone(var msg:Tmessage);
var
HeaderWaveHdr;
memBlockmemBlock;
i:integer;
inLength : integer;
sBuf : array of smallint ;
begin
dec(in_count);
{得到已经接收的数据块}
Header:=PWaveHdr(msg.lparam);
i:=waveInUnPrepareHeader(HWaveIn^,Header,sizeof(TWavehdr));
if i<>0 then
application.messagebox('In Un Prepare error','error',mb_ok);
if not(close_invoked) then
begin
inc(out_count);
//udp发送音频数据
InLength := header.dwBytesRecorded ;
setLength(sbuf,inlength) ;
Move(header.lpdata,sbuf[0],inlength);
UdpServer.SendBuffer(IpStr,1000,sbuf[0],InLength) ;
//udp音频发送数据结束
{不采用upd发送,直接播放,
i:=WaveOutPrepareHeader(HWaveOut^,header,sizeof(TWaveHdr));
if i<> 0 then
showmessage('WaveOutPrepareHeader error');
i:=WaveOutWrite(HWaveOut^,header,sizeof(TWaveHdr));
if i<> 0 then
showmessage('WaveOutWrite error');
//定义一个新的缓存块
Header:=new(PWaveHdr);
memBlock:=new(PmemBlock);
直接播放部分结束,}
with header^do
begin
//lpdata:=pointer(memBlock);{选udp传送时注销,直接播放是必须使用}
dwbufferlength:=500;
dwbytesrecorded:=0;
dwUser:=0;
dwflags:=0;
dwloops:=0;
end;
{准备波形装入块}
i:=waveInPrepareHeader(HWaveIn^,Header,sizeof(TWavehdr));
if i<>0 then
application.messagebox('In Prepare error','error',mb_ok);
{将缓存区发送给波形输入设备}
i:=waveInAddBuffer(HWaveIn^,Header,sizeof(TWaveHdr));
if i<>0 then
application.messagebox('Add buffer error','error',mb_ok);
inc(in_count);
end;
{队列已经为空}
if (in_count=0) then
begin
WaveInClose(HWaveIn^);
HwaveIn:=nil;
CloseStream ;
end;
{判断是否已经处理完输入和输出队列}
if (in_count=0) and (out_count=0) then
begin
close_complete:=true;
close;
end;
end;
//----------------------------------------------
//udp接收到数据,播放声音
//----------------------------------------------
procedure TForm1.UdpServerUDPRead(Sender: TObject;
AData: TStream;
ABinding: TIdSocketHandle);
var
sBuf:array of smallint ;
HeaderWaveHdr;
i : integer;
memblock : PmemBlock ;
size : integer;
begin
size := adata.Size ;
setLength(rBuf,size);
setLength(sBuf,size);
adata.ReadBuffer(sBuf[0],size);
Header:=new(PWaveHdr);
memblock:=new(pointer);
getmem(memblock,size);
move(sBuf[0],memBlock^,size);
Header.lpdata:=Pointer(memBlock);
Header.dwbufferlength:=size;
Header.dwbytesrecorded:=size;
Header.dwUser:=0;
Header.dwflags:=0;
Header.dwloops:=0;
i:=WaveOutPrepareHeader(HWaveOut^,Header,sizeof(TWaveHdr));
if i<> 0 then
showmessage('WaveOutPrepareHeader error');
i:=WaveOutWrite(HWaveOut^,Header,sizeof(TWaveHdr));
if i<> 0 then
showmessage('WaveOutWrite error');
end;
问题:以下代码如果采用udp发送方式,有吱吱的噪音,如果采用直接播放,没有噪音,
希望有经验的高手能指点迷经。
部分代码
procedure MMInDone(var msg:Tmessage);message MM_WIM_DATA;
...
procedure MMInDone(var msg:Tmessage);
var
HeaderWaveHdr;
memBlockmemBlock;
i:integer;
inLength : integer;
sBuf : array of smallint ;
begin
dec(in_count);
{得到已经接收的数据块}
Header:=PWaveHdr(msg.lparam);
i:=waveInUnPrepareHeader(HWaveIn^,Header,sizeof(TWavehdr));
if i<>0 then
application.messagebox('In Un Prepare error','error',mb_ok);
if not(close_invoked) then
begin
inc(out_count);
//udp发送音频数据
InLength := header.dwBytesRecorded ;
setLength(sbuf,inlength) ;
Move(header.lpdata,sbuf[0],inlength);
UdpServer.SendBuffer(IpStr,1000,sbuf[0],InLength) ;
//udp音频发送数据结束
{不采用upd发送,直接播放,
i:=WaveOutPrepareHeader(HWaveOut^,header,sizeof(TWaveHdr));
if i<> 0 then
showmessage('WaveOutPrepareHeader error');
i:=WaveOutWrite(HWaveOut^,header,sizeof(TWaveHdr));
if i<> 0 then
showmessage('WaveOutWrite error');
//定义一个新的缓存块
Header:=new(PWaveHdr);
memBlock:=new(PmemBlock);
直接播放部分结束,}
with header^do
begin
//lpdata:=pointer(memBlock);{选udp传送时注销,直接播放是必须使用}
dwbufferlength:=500;
dwbytesrecorded:=0;
dwUser:=0;
dwflags:=0;
dwloops:=0;
end;
{准备波形装入块}
i:=waveInPrepareHeader(HWaveIn^,Header,sizeof(TWavehdr));
if i<>0 then
application.messagebox('In Prepare error','error',mb_ok);
{将缓存区发送给波形输入设备}
i:=waveInAddBuffer(HWaveIn^,Header,sizeof(TWaveHdr));
if i<>0 then
application.messagebox('Add buffer error','error',mb_ok);
inc(in_count);
end;
{队列已经为空}
if (in_count=0) then
begin
WaveInClose(HWaveIn^);
HwaveIn:=nil;
CloseStream ;
end;
{判断是否已经处理完输入和输出队列}
if (in_count=0) and (out_count=0) then
begin
close_complete:=true;
close;
end;
end;
//----------------------------------------------
//udp接收到数据,播放声音
//----------------------------------------------
procedure TForm1.UdpServerUDPRead(Sender: TObject;
AData: TStream;
ABinding: TIdSocketHandle);
var
sBuf:array of smallint ;
HeaderWaveHdr;
i : integer;
memblock : PmemBlock ;
size : integer;
begin
size := adata.Size ;
setLength(rBuf,size);
setLength(sBuf,size);
adata.ReadBuffer(sBuf[0],size);
Header:=new(PWaveHdr);
memblock:=new(pointer);
getmem(memblock,size);
move(sBuf[0],memBlock^,size);
Header.lpdata:=Pointer(memBlock);
Header.dwbufferlength:=size;
Header.dwbytesrecorded:=size;
Header.dwUser:=0;
Header.dwflags:=0;
Header.dwloops:=0;
i:=WaveOutPrepareHeader(HWaveOut^,Header,sizeof(TWaveHdr));
if i<> 0 then
showmessage('WaveOutPrepareHeader error');
i:=WaveOutWrite(HWaveOut^,Header,sizeof(TWaveHdr));
if i<> 0 then
showmessage('WaveOutWrite error');
end;