录音时的图形
//***********************************************************************//
// //
// 画局部音频数据的波形 //
// 参数: //
// Flag : 波形显示周期 //
// Buf : 音频数据 //
// Length : 音频数据的长度 //
// DesCanvas : 要显示波形的目标画布 //
// DH, DW : 目标画布的工作区域的高度与宽度 //
// DesBitMap : 画波形时用的非可视源位图对像 //
// DrawLineColor : 画波形的颜色 //
// DrawBackColor : 画波形的背景颜色 //
// Draw : 是否画波形 //
// 返回值: 无 //
// //
//***********************************************************************//
procedure DrawPartWave(const Flag: Integer; Buf: PChar; Length: LongInt;
DesCanvas: TCanvas; DH, DW: SmallInt; DesBitMap: TBitMap;
DrawLineColor, DrawBackColor: TColor; Draw: Boolean = True);
var
i, j, k, lmax, lmin: LongInt;
Max, Min: LongInt;
X, Y: SmallInt;
begin
with DesBitMap do //初始化图像参数
begin
Width := DW;
Height := DH;
Canvas.Brush.Color := DrawBackColor;
Canvas.Brush.Style := bsSolid;
Canvas.Pen.Color := DrawLineColor;
Canvas.Pen.Mode := pmCopy;
Canvas.FillRect(Rect(0, 0, DW, DH));
end;
if ((Length = 0) Or (Buf = NIL)) then
begin //清除
BitBlt(DesCanvas.Handle, 0, 0, DW, DH, DesBitMap.Canvas.Handle, 0, 0, SRCCOPY);
Exit;
end;
Max := -32768;
Min := 32767;
for i := 0 to (Length div 2 -1 ) do //取到最小值与最大值
begin
j := PCMInt(PChar(Buf) + i * 2)^;
if j > Max then Max := j;
if j < Min then Min := j;
end;
DrawMin := Min;
DrawMax := Max;
if Not Draw then
begin
Exit;
end;
Max := Max - Min; //最大振幅
DesBitMap.Canvas.MoveTo(0, DH div 2);
j := 0;
X := 0;
lmax := 0;
lmin := 32767;
for i := 0 to ((Length) div 2 -1) do
begin
if j < (Flag - 1) then //如果是在一个周期内
begin
INC(j);
end
else begin
j := 0;
X := X + 1;
lmax := 0;
lmin := 32767;
end;
if Max <> 0 then //取音频数据转换在整数
Y := Abs(PCMInt(PChar(buf) + i * 2)^ - Min) * DH div Max
else
Y := DH div 2;
k := 0;
if Y > lmax then
begin
lmax := Y;
k := 1;
end;
if Y < lmin then
begin
lmin := Y;
k := 1;
end;
if k = 1 then
DesBitMap.Canvas.LineTo(X, Y); //画线
if X > DW then break;
end;
//图像复制 拷贝
BitBlt(DesCanvas.Handle, 0, 0, DW, DH, DesBitMap.Canvas.Handle, 0, 0, SRCCOPY);
end;