TGSM610=packed record //自定义音频文件头
wFormatTag: Word;
nChannels: Word;
nSamplesPerSec: DWORD;
nAvgBytesPerSec: DWORD;
nBlockAlign: Word;
wBitsPerSample: Word;
cbSize: Word;
wSamplesPerBlock:word;
end;var
buf: array[0..65535] of byte;
bufsize: Integer = 0;procedure TForm1.Button1Click(Sender: TObject);
var
format: Pointer;
GSM:TGSM610;
begin
with GSM do
begin
wFormatTag:=$31;
nChannels:=1;
wBitsPerSample:=0;
nSamplesPerSec:=8000;
nBlockAlign:=65;
nAvgBytesPerSec:=1625;
cbSize:=2;
wSamplesPerBlock:=$140;
end;
format:=@gsm;
ACMWaveIn1.Open(format);
ACMWaveOut1.Open(format);
end;procedure TForm1.ACMWaveIn1Data(data: Pointer; size: Integer);
begin
copymemory(pchar(@buf)+bufsize, data, size);
inc(bufsize, size);
if bufsize>=1300 then
begin
ACMWaveOut1.PlayBack(@buf, bufsize);
bufsize:=0;
end;
end;
在传送的时候,如何控制延迟呀?
刚开始的时候是2秒,然后就是5秒,再往后就是10秒,15秒,20秒........
大家帮助出个主意,谢谢!
wFormatTag: Word;
nChannels: Word;
nSamplesPerSec: DWORD;
nAvgBytesPerSec: DWORD;
nBlockAlign: Word;
wBitsPerSample: Word;
cbSize: Word;
wSamplesPerBlock:word;
end;var
buf: array[0..65535] of byte;
bufsize: Integer = 0;procedure TForm1.Button1Click(Sender: TObject);
var
format: Pointer;
GSM:TGSM610;
begin
with GSM do
begin
wFormatTag:=$31;
nChannels:=1;
wBitsPerSample:=0;
nSamplesPerSec:=8000;
nBlockAlign:=65;
nAvgBytesPerSec:=1625;
cbSize:=2;
wSamplesPerBlock:=$140;
end;
format:=@gsm;
ACMWaveIn1.Open(format);
ACMWaveOut1.Open(format);
end;procedure TForm1.ACMWaveIn1Data(data: Pointer; size: Integer);
begin
copymemory(pchar(@buf)+bufsize, data, size);
inc(bufsize, size);
if bufsize>=1300 then
begin
ACMWaveOut1.PlayBack(@buf, bufsize);
bufsize:=0;
end;
end;
在传送的时候,如何控制延迟呀?
刚开始的时候是2秒,然后就是5秒,再往后就是10秒,15秒,20秒........
大家帮助出个主意,谢谢!
解决方案 »
- 大家看看这个结果是多少
- 程序以前的通信用的是windows api 现在想改用第三方的sdk接口,接口名字和功能都和以前api不一样 如何改?
- 奇怪,fastreport2.5 不能显示‘加工’两个字?
- 初学者求助!!
- TChart中Series的Mark属性问题
- 这样的问题怎么解决?
- 有没有倒班的同志?下在这个软件看看,有没有用。
- Delphi 企业版有几个版本?
- 如何遍历adodataset中的一个栏目,我想取到里面的所有值...
- 请问如何隐藏windows的任务栏!??急!!!
- 郁闷!delphi7中选择project/options,出现内存错....
- 一个涉及到vector和链表的DLL声明转换到Delphi的问题
procedure TForm1.Button1Click(Sender: TObject);
var
format: Pointer;
GSM:TGSM610;
begin
with GSM do
begin
wFormatTag:=$31;
nChannels:=1;
wBitsPerSample:=0;
nSamplesPerSec:=8000;
nBlockAlign:=65;
nAvgBytesPerSec:=1625;
cbSize:=2;
wSamplesPerBlock:=$140;
end;
format:=@gsm;
ACMWaveIn1.Open(format);
ACMwaveIn1.BufferSize:=1;
ACMWaveOut1.Open(format);
idTCPClient1.Host:='192.168.1.111';
idTCPClient1.Port:=5000;
if not idTCPClient1.Connected then
idTCPClient1.Connect;
end;procedure TForm1.ACMWaveIn1Data(data: Pointer; size, volume: Integer);
begin
if idTCPClient1.Connected then
begin
copymemory(pchar(@buf)+bufsize, data, size);
inc(bufsize, size);
if bufsize>=800 then
begin
idTCPClient1.WriteInteger(bufsize);
idTCPClient1.WriteBuffer(buf,bufsize);
bufsize:=0;
end;
end;
end;
=========================
服务端:
procedure TForm1.FormCreate(Sender: TObject);
var
format: Pointer;
GSM:TGSM610;
begin
with GSM do
begin
wFormatTag:=$31;
nChannels:=1;
wBitsPerSample:=0;
nSamplesPerSec:=8000;
nBlockAlign:=65;
nAvgBytesPerSec:=1625;
cbSize:=2;
wSamplesPerBlock:=$140;
end;
format:=@gsm;
ACMWaveOut1.Open(format);
idTCPServer1.DefaultPort:=5000;
idTCPServer1.Active:=true;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
idTCPServer1.Active:=false;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
idTCPServer1.Active:=false;
end;procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
AudioStream:TMemoryStream;
AudioBufferLen:integer;
begin
if not AThread.Terminated and AThread.Connection.Connected then
begin
AudioStream := TMemoryStream.Create;
AudioBufferLen := AThread.Connection.ReadInteger;
AudioStream.Size := AudioBufferLen;
AThread.Connection.ReadBuffer(AudioStream.Memory^, AudioBufferLen);
ACMWaveOut1.PlayBack(AudioStream.Memory,AudioBufferLen);
AudioStream.Free;
end;
end;
传送没有问题,能收到,可是就是延迟,而且越来越长
如何解决?
type
TGSM610=packed record //自定义音频文件头
wFormatTag: Word;
nChannels: Word;
nSamplesPerSec: DWORD;
nAvgBytesPerSec: DWORD;
nBlockAlign: Word;
wBitsPerSample: Word;
cbSize: Word;
wSamplesPerBlock:word;
end;var
buf: array[0..65535] of byte;
bufsize: Integer = 0;procedure TForm1.FormCreate(Sender: TObject);
begin
idtcpclient1.Connect;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
idtcpclient1.Disconnect;
end;procedure TForm1.Button1Click(Sender: TObject);
var
format: Pointer;
GSM:TGSM610;
begin
with GSM do
begin
wFormatTag:=$31;
nChannels:=1;
wBitsPerSample:=0;
nSamplesPerSec:=8000;
nBlockAlign:=65;
nAvgBytesPerSec:=1625;
cbSize:=2;
wSamplesPerBlock:=$140;
end;
format:=@gsm;
ACMWaveIn1.Open(format);
end;procedure TForm1.ACMWaveIn1Data(data: Pointer; size: Integer);
begin
copymemory(pchar(@buf)+bufsize, data, size);
inc(bufsize, size);
if bufsize>=1300 then
begin
IdTCPClient1.WriteBuffer(buf, bufsize);
bufsize:=0;
end;
end;服务器:
type
TGSM610=packed record //自定义音频文件头
wFormatTag: Word;
nChannels: Word;
nSamplesPerSec: DWORD;
nAvgBytesPerSec: DWORD;
nBlockAlign: Word;
wBitsPerSample: Word;
cbSize: Word;
wSamplesPerBlock:word;
end;procedure TForm1.FormCreate(Sender: TObject);
var
format: Pointer;
GSM:TGSM610;
begin
with GSM do
begin
wFormatTag:=$31;
nChannels:=1;
wBitsPerSample:=0;
nSamplesPerSec:=8000;
nBlockAlign:=65;
nAvgBytesPerSec:=1625;
cbSize:=2;
wSamplesPerBlock:=$140;
end;
format:=@gsm;
ACMWaveOut1.Open(format);
end;procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
buf: array of byte;
count: Integer;
begin
try
count:=AThread.Connection.ReadFromStack;
if count<>0 then
begin
setlength(buf, count);
AThread.Connection.ReadBuffer(buf[0], count);
ACMWaveOut1.PlayBack(buf, count);
end;
Memo1.Lines.Add(inttostr(count));
finally end;
end;另外,建议你用udp协议传输这种实时数据。