unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TPCMWaveHeader = record
rID : array[0..3] of char;
// 'RIFF' 标志
rLen : longint;
// 文件长度
wID : array[0..3] of char;
// 'WAVE' 标志
fId : array[0..3] of char;
// 'fmt '标志 以空格结束(fID[3]:=Chr($20)
fLen : longint;
// 过度字节(不定)
wFormatTag : word;
// 格式字节(过度字节为PCM形式的声音数据)
nChannels : word;
// 通道数 单声道=1, 双声道=2 }
nSamplesPerSec : longint;
// 采样频率 (每秒样本数),表示每个通道的播放速度
nAvgBytesPerSec : longint;
// 波形音频数据传送速度(值:通道数X每秒数据位数X每
// 样本的数据位数/8。播放软件利用根据此值估计缓
// 冲区的大小)
nBlockAlign : word;
// 数据块的调整数(按字节计算),值为通道数*没样本的数据位值/8。
// 播放软件需要一次处理多个该值大小的字节数据,以便
// 将其值用于缓冲区的调整。
nBitsPerSample : word;
// 每样本数据位数,表示每个声道中各个样本的数据位
// 数。如果有多个声道,对每个声道而言,样本大
// 小都一样 8 or 16
dId : array[0..3]of char;
// 'data' 标志
dLen : longint;
// 语音数据长度
end;
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
Button3: TButton;
Image1: TImage;
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
filename:string;
pcm:TPCMWaveHeader;
Data:TByteArray;
procedure PrintPcm;
procedure PrintData;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.PrintPcm;
begin
memo1.lines.add('FileName:'+Filename);
memo1.lines.add('RIFF:'+pcm.rID);
memo1.lines.add('RLEN:'+inttostr(pcm.rLen));
memo1.lines.add('WAVE:'+pcm.wID);
memo1.lines.add('fmt:'+pcm.fId);
memo1.lines.add('Fixed:'+inttostr(pcm.fLen));
memo1.lines.add('wFormatTag:'+inttostr(pcm.wFormatTag));
memo1.lines.add('nChannels:'+inttostr(pcm.nChannels));
memo1.lines.add('nSamplesPerSec:'+inttostr(pcm.nSamplesPerSec));
memo1.lines.add('nAvgBytesPerSec:'+inttostr(pcm.nAvgBytesPerSec));
memo1.lines.add('nBlockAlign:'+inttostr(pcm.nBlockAlign));
memo1.lines.add('nBitsPerSample:'+inttostr(pcm.nBitsPerSample));
memo1.lines.add('dLen:'+inttostr(pcm.dLen));
end;
procedure TForm1.Button2Click(Sender: TObject);
var
iFileHandle: Integer;
iFileLength: Integer;
iBytesRead: Integer;
Buffer: PChar;
i, Size: Integer;
begin
iFileHandle := FileOpen(filename, fmOpenRead);
iFileLength := FileSeek(iFileHandle, 0, 2) - FileSeek(iFileHandle, 0, 0);
Buffer := PChar(AllocMem(iFileLength + 1));
iBytesRead := FileRead(iFileHandle, Buffer^, iFileLength);
//把文件读到buffer
FileClose(iFileHandle);
Move((Buffer)^, pcm, sizeof(pcm));
Move((Buffer)^, Data, pcm.dLen);
printpcm;
//显示头信息
printData;
//画波形图
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
filename:='c:/SOUND108.WAV';
end;
procedure TForm1.PrintData;
var
i:Integer;
begin
for i:=0 to pcm.dLen -1do
begin
//memo1.lines.add(inttostr(Data
));
Canvas.LineTo(i,Data)
end;
end;
end.