Wave 文件(5): 获取 Wave 文件的格式信息
生活随笔
收集整理的這篇文章主要介紹了
Wave 文件(5): 获取 Wave 文件的格式信息
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
裝載格式信息的結構有:
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]));;;.
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]));;;.
轉載于:https://www.cnblogs.com/lzh-boy/archive/2010/01/13/1646578.html
總結
以上是生活随笔為你收集整理的Wave 文件(5): 获取 Wave 文件的格式信息的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 了解jQuery技巧来提高你的代码
- 下一篇: 解决VS2010 beta2 安装后ht