我有这样的问题,做点对点语音聊天,不压缩,采样8k,单声道,统计发送数据库是8k/秒,接收却在6-7k/秒波动,实际听到对方声音象是被压榨,一顿一顿的。在本机运行2个实例,一个发送一个接收,速度都是8k/秒。我用的是ADSL,512k/2M,不知道是不是对方的带宽问题,但对方也是ADSL。代码如下:
//发送数据
procedure TForm1.WaveInBufferReady(Sender: TObject; lpWaveHdr: PWaveHdr);
var
i:integer;
begin
if SerSocket.Socket.ActiveConnections>0 then begin
for i:=0 to SerSocket.Socket.ActiveConnections-1 do
try SerSocket.Socket.Connections.SendBuf(lpWaveHdr^.lpData^,lpWaveHdr^.dwBytesRecorded);
WaveIn.Tag := WaveIn.Tag + integer(lpWaveHdr^.dwBytesRecorded);
except end;
SBar1.Panels[3].Text :='Server Send';
end else begin
if CliSocket.Active then begin
try CliSocket.Socket.SendBuf(lpWaveHdr^.lpData^,lpWaveHdr^.dwBytesRecorded);
WaveIn.Tag := WaveIn.Tag + integer(lpWaveHdr^.dwBytesRecorded);
except end;
end;
SBar1.Panels[3].Text :='Client Send';
end;
end;
//接收数据
procedure TForm1.WaveOutBufferLoad(Sender: TObject; lpWaveHdr: PWaveHdr; var MoreBuffers: Boolean);
begin
lpWaveHdr^.dwBytesRecorded:=0;
if CliSocket.Active and (CliSocket.Socket.ReceiveLength>0) then begin
lpWaveHdr^.dwBytesRecorded:=CliSocket.Socket.ReceiveBuf(lpWaveHdr^.lpData^,lpWaveHdr^.dwBufferLength);
WaveOut.Tag := WaveOut.Tag + integer(lpWaveHdr^.dwBytesRecorded);
SBar1.Panels[4].Text :='Client Rece';
end else begin
if SerSocket.Socket.ActiveConnections>0 then
if (SerSocket.Socket.Connections[0].ReceiveLength>0) then
try
lpWaveHdr^.dwBytesRecorded:=SerSocket.Socket.Connections[0].ReceiveBuf(lpWaveHdr^.lpData^,lpWaveHdr^.dwBufferLength);
WaveOut.Tag := WaveOut.Tag + integer(lpWaveHdr^.dwBytesRecorded);
except end;
SBar1.Panels[4].Text :='Server Rece';
end;
if lpWaveHdr^.dwBytesRecorded<1 then
begin
MemStream.Position :=0;
MemStream.Read(lpWaveHdr^.lpData^,lpWaveHdr^.dwBufferLength);
lpWaveHdr^.dwBytesRecorded:=lpWaveHdr^.dwBufferLength;
end;
MoreBuffers:=true;
end;