Delphi根据音频数据画波形
来源:互联网 发布:xy坐标转换经纬度软件 编辑:程序博客网 时间:2024/05/16 19:09
- procedure HawDrawWave(Buf: PChar; Length: LongInt; DesCanvas: TCanvas;
- DH, DW: SmallInt; Min, Max: LongInt; DrawLineColor, DrawBackColor: TColor;
- StartPoi: LongInt = 0; DrawLength: LongInt = 0);
- Var
- i: LongInt;
- Y: SmallInt;
- DesBitMap: TBitMap;
- begin
- DesBitMap := TBitMap.Create;
- 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));
- Canvas.MoveTo(0, DH DIV 2);
- Canvas.LineTo(DW, DH DIV 2);
- end;
- if ((Length = 0) or (Buf = NIL)) then
- begin
- BitBlt(DesCanvas.Handle, 0, 0, DW, DH, DesBitMap.Canvas.Handle, 0, 0, SRCCOPY);
- Exit;
- end;
- if (StartPoi MOD 2) = 1 then
- StartPoi := StartPoi + 1;
- if StartPoi >= Length then
- StartPoi := 2;
- if DrawLength div 2 > DW then
- DrawLength := DW * 2;
- if (StartPoi + DrawLength) > Length then
- DrawLength := Length - StartPoi;
- if DrawLength <= 0 then
- DrawLength := DW * 2;
-
- Max := Max - Min;
- for i := 0 to (DrawLength div 2 -1) do
- begin
- if Max <> 0 then
- Y := Abs(PCMInt(PChar(Buf) + StartPoi + i * 2)^ - Min) * DH div Max
- else
- Y := 0;
- Y := ABS(DH DIV 2 - Y);
- if Y >= (DH DIV 2) then
- continue;
-
- DesBitMap.Canvas.MoveTo(i, DH DIV 2 - Y);
- DesBitMap.Canvas.LineTo(i, DH DIV 2 + Y);
- if i > DW then break;
- end;
-
- BitBlt(DesCanvas.Handle, 0, 0, DW, DH, DesBitMap.Canvas.Handle, 0, 0, SRCCOPY);
- DesBitMap.Free;
- end;
- 来自: yostgxf, 时间: 2005-01-18 21:52:21, ID: 2969407
- 录音时的图形
- 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;