//触发捕获音频事件
procedure TSoundCap.DoCapture(passTime : DWORD );
var
EndTime : DWORD ;
begin
EndTime := GetTickCount;
if Assigned(FOnCapture) then FOnCapture(Self, EndTime - StartTime - passTime);
end;
//显示音频强度
procedure TSoundCap.DoShowProgress(position: Integer);
begin
if Assigned(FOnShowProgress) then FOnShowProgress(Self, position);
end;
//显示时间
procedure TSoundCap.DoShowTime;//(Time : Integer);
var
EndTime : DWORD ;
begin
EndTime := GetTickCount;
if Assigned(FOnShowTime) then FOnShowTime(Self, EndTime - StartTime);
end;
//中值过滤
function TSoundCap.GetMidValue(i: Integer): Integer;
var
v0,v1,v2 : integer;
h : integer;
mid : integer;
begin
h := 100;
v0 := p^[i-2].Y;
v1 := p^[i-1].Y;
v2 := p^[i].Y;
mid := (v0 + v1 + v2) div 3;
if abs(abs(mid) - v1) > FilterValve then
Result := mid
Else if abs(mid - h/2) < FilterValve then
Result := 0
Else
Result := v1;
end;
//处理Wave数据采集
procedure TSoundCap.OnWaveIn(var Msg: TMessage);
var
data8 : PData8;
i, x, y : integer;
//判断是否有超出域值的数据
StartPos := 0;
EndPos := 0;
SCount := 0;
for I := 0 to BufSize - 1 do
begin
if abs(p2^[i].Y ) > FilterValve then
Begin
if StartPos = 0 then
StartPos := i;
Inc(SCount);
end Else if StartPos = 0 then
p^[i].Y := 0;//h div 2;
if (SCount > 20) then
if (EndPos = 0) then
EndPos := Min((StartPos + BufSize div 2 ) , BufSize - 1)
Else if EndPos < i then
p^[i].Y := 0;//h div 2;
end;
{
if (SCount > 20) and isCapture then
with PaintBox3.Canvas do begin
Brush.Color := clBlack;
Pen.Color := clGreen;