程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 操作 Wave 文件(6): 獲取 Wave 文件的波形數據

操作 Wave 文件(6): 獲取 Wave 文件的波形數據

編輯:Delphi

 讀取函數及測試代碼:

unit Unit1; 
 
interface 
 
uses 
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
 Dialogs, StdCtrls; 
 
type 
 TForm1 = class(TForm) 
  Button1: TButton; 
  procedure Button1Click(Sender: TObject); 
 end; 
 
var 
 Form1: TForm1; 
 
implementation 
 
{$R *.dfm}  
 
uses MMSystem; 
 
function GetWaveData(FilePath: string; var stream: TMemoryStream): Boolean; 
var 
 hFile: HMMIO; 
 ckiRIFF,ckiData: TMMCKInfo; 
begin 
 Result := False; 
 hFile := mmioOpen(PChar(FilePath), nil, MMIO_READ); 
 if hFile = 0 then Exit; 
 
 ZeroMemory(@ckiRIFF, SizeOf(TMMCKInfo)); 
 ZeroMemory(@ckiData, SizeOf(TMMCKInfo)); 
 ckiData.ckid := mmiOStringToFOURCC('data', 0); 
 
 //先獲取主塊的信息 
 mmioDescend(hFile, @ckiRIFF, nil, MMIO_FINDRIFF); 
 
 //再獲取 data 塊的信息後, 指針將自動指向 data 數據的起點; 然後讀出數據 
 if (ckiRIFF.ckid = FOURCC_RIFF) and (ckiRIFF.fccType = mmiOStringToFOURCC('WAVE',0)) then 
  if mmioDescend(hFile, @ckiData, @ckiRIFF, MMIO_FINDCHUNK) = MMSYSERR_NOERROR then 
  begin 
   stream.Size := ckiData.cksize; 
   if mmioRead(hFile, stream.Memory, ckiData.cksize) = ckiData.cksize then Result := True; 
  end; 
 mmioClose(hFile, 0); 
end; 
 
//調用測試 
procedure TForm1.Button1Click(Sender: TObject); 
const 
 FilePath = 'C:\WINDOWS\Media\Windows XP 啟動.wav'; 
var 
 stream: TMemoryStream; 
 b: Byte; 
 str: string; 
begin 
 stream := TMemoryStream.Create; 
 
 if GetWaveData(FilePath, stream) then 
  ShowMessageFmt('讀出的數據大小是: %d', [stream.Size]); {424600} 
 
 stream.Free; 
end; 
 
end. 


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved