我试了半天也没有调用成功,请csdn兄弟们帮忙呀,谁成功调用过,给点建议或资料什么的,最好能附调用成功的代码给我,我急用呢,先谢谢了。 -------------------------------------------------------------
//***********************************************************************//
// //
// 画放音时的动态波形 //
// 参数: //
// Buf : 音频数据指针 //
// Length : 音频数据的长度 //
// DesCanvas : 用来显示波形的目标画布 //
// DH, DW : 目标画布工作区的高度与宽度 //
// Min, Max : 音频数据的最小值与最大值 //
// DrawLineColor : 画波形的颜色 //
// DrawBackColor : 画波形的背景颜色 //
// StartPoi : 开始画波形的位置 //
// DrawLength : 要画的波形的数据的长度 //
// 返回值: 无 //
// //
//***********************************************************************//
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;
//***********************************************************************//
// //
// 画放音时的动态波形 //
// 参数: //
// Buf : 音频数据指针 //
// Length : 音频数据的长度 //
// DesCanvas : 用来显示波形的目标画布 //
// DH, DW : 目标画布工作区的高度与宽度 //
// Min, Max : 音频数据的最小值与最大值 //
// DrawLineColor : 画波形的颜色 //
// DrawBackColor : 画波形的背景颜色 //
// StartPoi : 开始画波形的位置 //
// DrawLength : 要画的波形的数据的长度 //
// 返回值: 无 //
// //
//***********************************************************************//
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;
type
PCMInt=PSmallInt;
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;
procedure TForm1.Button1Click(Sender: TObject);
var
bx:Array[0..200] of SmallInt;
i:Integer;
begin
for i:=Low(bx) to High(bx) do
bx[i]:=Random(65535)-32767;
HawDrawWave(@bx[0],High(bx)*SizeOf(bx[0]),Canvas,100,200,-32768,32767,clRed,clBtnFace);
end;
不过我试过好几次,显示的都是相同的两种波形,不知道我如何对一句完整的发音进行显示呢?我用了Timer1Timer事件也加大了显示长度好象没有效果。请问如何处理呢?谢谢
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
//以下代码测试通过
type
PCMInt=PSmallInt;
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;
procedure TForm1.Button1Click(Sender: TObject);
var
bx:Array[0..200] of SmallInt;
i:Integer;
begin
for i:=Low(bx) to High(bx) do
bx[i]:=Random(65535)-32767;
HawDrawWave(@bx[0],High(bx)*SizeOf(bx[0]),Canvas,100,200,-32768,32767,clRed,clBtnFace);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Button1.Click;
end;end.
我也在Timer1Timer事件里试过了。但是播放声音的时候,波形好象也没有什么规律可寻。不知道为什么