有那位高手知道关于WAV格式的编程

cxygoo 2002-03-27 08:54:54
给定一个函数(比如SIN),以及函数的周期,振幅,怎样输出一个WAV格式的声音文件?
多谢高手回答!!
...全文
41 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxygoo 2002-03-27
  • 打赏
  • 举报
回复
非常感谢这位高手,可是我能力有限,这位高手能给我一点注释吗?特别是各个变量的意义,多谢了!!
cxygoo 2002-03-27
  • 打赏
  • 举报
回复
非常感谢这位高手,原谅小弟无知,能给我一点注释吗?
forgot 2002-03-27
  • 打赏
  • 举报
回复
procedure TTrack.DrawWave;
type OneBit = array[0..0] of Shortint;
OneBitArray =^OneBit;
TwoBit = array[0..0] of Smallint;
TwoBitArray =^TwoBit;
var ByteRead : integer;
Wave16 : TwoBitArray;
Wave8 : OneBitArray;
Up,Down,Oldy,Lever : Integer;
k : real;
procedure Draw8BitWav(X,Y,W,H,Count,pos,Add:Integer);
var i,j,Bit8 : integer; // 区域 总量 偏移 累加
begin
k:=H/255;
Lever:=Y+H;
Getmem(Wave8,Count);
OldY:=y+H div 2;
for i:=X to X+W-1 do
begin
ByteRead:=FileStream.Read(Wave8^,Count);
if ByteRead=0 then break;
j:=Pos;
//************************
Up:=0 ;Down:=256;
Lever:=Y+H;
While j< count do
begin
if Wave8[j]<0 then Bit8:=256+Wave8[j]
else Bit8:=Wave8[j];
if Bit8>Up then
Up:=Bit8;
if Bit8<Down then
Down:=Bit8;
j:=j+add;
end;
up:=round(up*k);
Down:=round(Down*k);
if Up=Down then Down:=Down-1;
Up:=Lever-Up;
Down:=Lever-Down;
ViewImg.Canvas.MoveTo(i,Up);
ViewImg.Canvas.LineTo(i,Down);
ViewImg.Canvas.MoveTo(i,OldY);
ViewImg.Canvas.LineTo(i,Up);
if Up-1=Down then OldY:=Up else
OldY:=(Up+Down)div 2;
if Byteread<Count then break;
end;
Line(ViewImg.Canvas,x,Y+H div 2,x+w,Y+H div 2,0,1,clred);
Freemem(Wave8,Count);
end;
procedure Draw16BitWav(X,Y,W,H,Count,pos,Add:Integer);
var i,j,Bit16: integer; // 区域 总量 偏移 累加
begin
k:=H/65535;
Lever:=Y+H;
OldY:=Y+H div 2;
Getmem(Wave16,Count);
for i:=X to X+W-1 do
begin
ByteRead:=FileStream.Read(Wave16^,Count);
if ByteRead=0 then break;
j:=pos;
//***************
Up:=0 ;Down:=65535;
While j< count div 2 do
begin
Bit16:=Wave16[j]+32767;
if Bit16>Up then
Up:=Bit16;
if Bit16<Down then
Down:=Bit16;
j:=j+add;
end;
up:=round(up*k);
Down:=round(Down*k);
if Up=Down then Down:=Down-1;
Up:=Lever-Up;
Down:=Lever-Down;
ViewImg.Canvas.MoveTo(i,Up);
ViewImg.Canvas.LineTo(i,Down);
ViewImg.Canvas.MoveTo(i,OldY);
ViewImg.Canvas.LineTo(i,Up);
if Up-1=Down then OldY:=Up else
OldY:=(Up+Down)div 2;
if ByteRead<Count then break;
end;
Line(ViewImg.Canvas,x,Lever-h div 2,x+w,Lever-h div 2,0,1,clred);
Freemem(Wave16,Count);
end;
begin
if Not IsLoad then Exit;

Fill(ViewImg.Canvas,Wx,Wy,Wx+Ww,Wy+Wh,$0);
ViewImg.Canvas.Pen.Color:=cllime;

if FileStream.Size>=VBeg then
begin
FileStream.Position:=VBeg;
case TypeFmt of
1 : begin ////////////// 111111111111
Draw8BitWav(WX,WY,WW,WH,Zoom,0,1);
end;
2 : begin ////////////// 222222222222
Draw16BitWav(WX,WY,WW,WH,Zoom*2,0,1);
end;
3 : begin ////////////// 333333333333
Draw8BitWav(WX,WY,WW,WH div 2,Zoom*2,0,2);
FileStream.Position:=VBeg;
ViewImg.Canvas.Pen.Color:=cllime;
Draw8BitWav(WX,WY+WH div 2,WW,WH div 2,Zoom*2,1,2);
end;
4 : begin ////////////// 444444444444
Draw16BitWav(WX,WY,WW,WH div 2,Zoom*4,0,2);
FileStream.Position:=VBeg;
ViewImg.Canvas.Pen.Color:=cllime;
Draw16BitWav(WX,WY+WH div 2,WW,WH div 2,Zoom*4,1,2);
end;
end;
end;
Setselect(SeleBeg,SeleEnd);
BitBlt(Canvas.handle,Wx,Wy,Ww,Wh+RulerH,ViewImg.canvas.handle,Wx,Wy,SRCCOPY);
end;

828

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧