delphi 函数写成线程
procedureTForm3.Button4Click(Sender:TObject);varoutF,buff_write:Integer;chalconfig:In...
procedure TForm3.Button4Click(Sender: TObject);
var
outF,buff_write:Integer;
chalconfig:Integer;
audioEncoding:Integer;
i,b:Integer;
a,s2,s3 :double;
//pkointer;
begin
outF:=44100;
chalconfig:= TJAudioFormat.JavaClass.CHANNEL_OUT_MONO;
audioEncoding:=TJAudioFormat.JavaClass.ENCODING_PCM_8BIT;
playBufferSize:= TJAudioTrack.JavaClass.getMinBufferSize(outF, chalconfig, audioEncoding);
playBufferSize:=playBufferSize*2;
at1:= TJAudioTrack.JavaClass.init(TJAudioManager.JavaClass.STREAM_MUSIC,outF,
chalconfig,audioEncoding,playBufferSize,
TJAudioTrack.JavaClass.MODE_STREAM);
i:=0;
a:=frequency1/(outF*2*3.1415926);
soundData := TJavaArray<Byte>.Create(playBufferSize);
for i := 0 to playBufferSize do
begin
s3:=128*sin(a*i);
b:=round(s3);
soundData[i]:=Byte(b);
end;
at1.play;
at1.write(soundData,0,playBufferSize);
end;
按一下Button4Click只有响一下,我需连续响,是不是必须要开线程, at1.write(soundData,0,playBufferSize);一直死循环调用此函数,
新手搞不定,如何开线程?
procedure TForm3.FormShow(Sender: TObject);
begin
I:=0;
frequency1:=1000;
end; 展开
var
outF,buff_write:Integer;
chalconfig:Integer;
audioEncoding:Integer;
i,b:Integer;
a,s2,s3 :double;
//pkointer;
begin
outF:=44100;
chalconfig:= TJAudioFormat.JavaClass.CHANNEL_OUT_MONO;
audioEncoding:=TJAudioFormat.JavaClass.ENCODING_PCM_8BIT;
playBufferSize:= TJAudioTrack.JavaClass.getMinBufferSize(outF, chalconfig, audioEncoding);
playBufferSize:=playBufferSize*2;
at1:= TJAudioTrack.JavaClass.init(TJAudioManager.JavaClass.STREAM_MUSIC,outF,
chalconfig,audioEncoding,playBufferSize,
TJAudioTrack.JavaClass.MODE_STREAM);
i:=0;
a:=frequency1/(outF*2*3.1415926);
soundData := TJavaArray<Byte>.Create(playBufferSize);
for i := 0 to playBufferSize do
begin
s3:=128*sin(a*i);
b:=round(s3);
soundData[i]:=Byte(b);
end;
at1.play;
at1.write(soundData,0,playBufferSize);
end;
按一下Button4Click只有响一下,我需连续响,是不是必须要开线程, at1.write(soundData,0,playBufferSize);一直死循环调用此函数,
新手搞不定,如何开线程?
procedure TForm3.FormShow(Sender: TObject);
begin
I:=0;
frequency1:=1000;
end; 展开
1个回答
展开全部
把at1.play;语句,放到at1.write(soundData,0,playBufferSize);语句的下面试试。
你的问题,跟线程无关,是你的代码逻辑有问题。为简单起见,先在主线程中顺利通过了,才去考虑使用线程。
你的问题,跟线程无关,是你的代码逻辑有问题。为简单起见,先在主线程中顺利通过了,才去考虑使用线程。
更多追问追答
追问
代码逻辑没有有问题,是先播放使能,再压数据,只压一次所以只响一下,
要连续响,就要线程反复压
追答
要反复压,跟线程也完全无关嘛。
最简单的办法测试:
at1.write(soundData,0,playBufferSize);
at1.write(soundData,0,playBufferSize);
at1.write(soundData,0,playBufferSize);
顺序执行几条同样的语句,看能否响多次?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询