不用控件

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;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;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
            filename: string;
            pcm: TPCMWaveHeader;
            Data: array[0..80 * 10240] of Byte;
            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.PrintData;
    var
            i : Integer;
    begin
            for i := 0 to pcm.dLen - 1 do
            begin
                    //memo1.lines.add(inttostr(Data[i]));
                    Canvas.LineTo(i, Data[i])
            end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
            filename := 'C:\test.wav';
    end;procedure TForm1.Button1Click(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);
            GetMem(Buffer, iFileLength + 1);
            iBytesRead := FileRead(iFileHandle, Buffer^, iFileLength); //把文件读到buffer
            FileClose(iFileHandle);
            Move((Buffer)^, pcm, sizeof(pcm));
            Move((Buffer)^, Data, pcm.dLen);
            printpcm; //显示头信息
            printData; //画波形图
            FreeMem(Buffer);
    end;end.
      

  2.   

    楼上的大哥,您的程序我有,但是有的wav文件这个程序打不开呀,得不到文件的句柄。我有个VB的程序挺好的,但是我不会翻译成delphi。
      

  3.   

    得不到文件的句柄,跟这个程序是没有关系的哈。
    Delphi syntax:function FileOpen(const FileName: string; Mode: LongWord): Integer;C++ syntax:extern PACKAGE int __fastcall FileOpen(const AnsiString FileName, unsigned Mode);DescriptionUse FileOpen to open a file and obtain a file handle. The access mode value is constructed by or-ing one of the fmOpen constants with one of the fmShare constants defined in File open mode constants. If the return value is 0 or greater, the function was successful and the value is the file handle of the opened file. A return value of -1 indicates that an error occurred.: Use of the non-native Delphi language file handlers such as FileOpen is not encouraged. These routines map to system routines and return OS file handles, not normal Delphi file variables. These are low-level file access routines. For normal file operations use AssignFile, Rewrite, and Reset instead.