TWaveFormat = wFormatTag: Word;nChannels: Word;nSamplesPerSec: DWORD;nAvgBytesPerSec: DWORD;nBlockAlign: Word; ;TPCMWaveFormat = wf: TWaveFormat;wBitsPerSample: Word; ;TWaveFormatEx = wFormatTag: Word; nChannels: Word; nSamplesPerSec: DWORD; nAvgBytesPerSec: DWORD; nBlockAlign: Word; wBitsPerSample: Word; cbSize: Word; ;
能看出它们是依次递增一个字段, 并且也是 Wave 文件的一个构成部分; 现在要做的就是从 Wave 文件中把它们取出来.
获取函数及测试代码:
Unit1;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;TForm1 = (TForm)Memo1: TMemo;Button1: TButton;Button1Click(Sender: TObject);;Form1: TForm1;MMSystem;GetWaveFmt(FilePath: ; fmt: TWaveFormatEx): Boolean;hFile: HMMIO;ckiRIFF,ckiFmt: TMMCKInfo;Result := False;hFile := mmioOpen(PChar(FilePath), , MMIO_READ);hFile = Exit;ZeroMemory(@ckiRIFF, SizeOf(TMMCKInfo));ZeroMemory(@ckiFmt, SizeOf(TMMCKInfo));ZeroMemory(@fmt, SizeOf(TWaveFormatEx)); ckiFmt.ckid := mmioStringToFOURCC(, ); mmioDescend(hFile, @ckiRIFF, , MMIO_FINDRIFF);(ckiRIFF.ckid = FOURCC_RIFF) (ckiRIFF.fccType = mmioStringToFOURCC(,)) (mmioDescend(hFile, @ckiFmt, @ckiRIFF, MMIO_FINDCHUNK) = MMSYSERR_NOERROR) Result := (mmioRead(hFile, @fmt, ckiFmt.cksize) = ckiFmt.cksize); ;TForm1.Button1Click(Sender: TObject);FilePath = ;WaveFormat: TWaveFormatEx;GetWaveFmt(FilePath, WaveFormat) Memo1.Lines Clear;Add(Format(, [WaveFormat.wFormatTag]));Add(Format(, [WaveFormat.nChannels]));Add(Format(, [WaveFormat.nSamplesPerSec]));Add(Format(, [WaveFormat.nAvgBytesPerSec]));Add(Format(, [WaveFormat.nBlockAlign]));Add(Format(, [WaveFormat.wBitsPerSample]));Add(Format(, [WaveFormat.cbSize]));;;.