中国程序员联盟 正在重新改版中ing 不便之处还请见谅 改版后将内容涉及java delphi .net php
 
  首页 | 数据库开发 | 网络通讯 | 多线程 | 多媒体开发 | 图像处理 | 程序人生 | 系统函数 | 控件开发 | Web服务
 
  当前位置:笨鱼delphi技术网>多媒体开发>文章内容

delphi 分析多媒体波频文件

来源:国外 关于:Liran Shahar 发布时间:2007-07-15   [收藏] [推荐]
A WAV file is binary file in the RIFF format, RIFF format enables the user to haev multiple information in the same file which can either be used or not.
The information is stored in chunks, each chunk have its type (4 chars) and side (dword) so it can be skipped if you are not interested in the data or to be read from the file.
You can download the demo software that shows wave file in a signal display graph with functions as: paning, zoom, multiple audio channels and more from
(the zip file contains the wavefileparser component and signaldisplay component).
The following code parses WAV files into accessable chunks:
{*==============================================================================
          Copyright (C) 2002, All rights reserved, Com-N-Sense Ltd
================================================================================
File: WaveFileParser.pas
Author: Liran Shahar, Com-N-Sense Ltd
Updated: 24/03/2002
Purpose: Parsing wave file into chunks
================================================================================
  24/03/2002, Liran Shahar
  - Initial release.
==============================================================================*}
unit WaveFileParser;
interface
uses
  Sysutils, Classes;
type
  TChunkType = array[1..4] of char;
  PChunk = ^TChunk;
  TChunk = packed record
    cType: TChunkType;
    dwSize: cardinal;
    pData: pointer;
  end;
  TcnsWaveFileParser = class(TPersistent)
  private
    FFilename: AnsiString;
    Chunks: TList;
  protected
    procedure SetFilename(AFilename: AnsiString); virtual;
    function GetChunksCount: integer; virtual;
    function GetChunk(Index: integer): PChunk; virtual;
    procedure ProcessFile; virtual;
    procedure ClearChunks; virtual;
  public
    constructor Create; virtual;
    destructor Destroy; override;
    function GetChunkByType(ChunkType: TChunkType): PChunk; virtual;
    property Filename: AnsiString read FFilename write SetFilename;
    property ChunksCount: integer read GetChunksCount;
    property Chunk[Index: integer]: PChunk read GetChunk;
  end;
implementation
const
  RIFF_SIGNATURE = 'RIFF';
  WAVE_SIGNATURE = 'WAVE';
type
  TRIFFHeader = packed record
    cSignature: TChunkType;
    dwSize: cardinal;
    cType: TChunkType;
  end;
constructor TcnsWaveFileParser.Create;
begin
  inherited Create;
  FFilename := '';
  Chunks := TList.Create;
end;
destructor TcnsWaveFileParser.Destroy;
begin
  ClearChunks;
  inherited Destroy;
end;
procedure TcnsWaveFileParser.SetFilename(AFilename: AnsiString);
begin
  if FFilename <> AFilename then
  begin
    ClearChunks;
    FFilename := AFilename;
    ProcessFile;
  end; // if
end;
function TcnsWaveFileParser.GetChunksCount: integer;
begin
  Result := Chunks.Count;
end;
function TcnsWaveFileParser.GetChunk(Index: integer): PChunk;
begin
  Result := nil;
  if (Index > -1) and (Index < Chunks.Count) then
    Result := Chunks[Index];
end;
procedure TcnsWaveFileParser.ProcessFile;
var
  WaveFile: TFileStream;
  Header: TRIFFHeader;
  Chunk: PChunk;
begin
  try
    WaveFile := TFileStream.Create(FFilename, fmOpenRead + fmShareDenyWrite);
    WaveFile.Read(Header, sizeof(Header));
    if (AnsiCompareText(Header.cSignature, RIFF_SIGNATURE) = 0) and
      (AnsiCompareText(Header.cType, WAVE_SIGNATURE) = 0) then
    begin
      while WaveFile.Position < WaveFile.Size do
      begin
        Chunk := AllocMem(sizeof(TChunk));
        with Chunk^ do
        begin
          WaveFile.Read(cType, sizeof(cType));
          WaveFile.Read(dwSize, sizeof(dwSize));
          pData := AllocMem(dwSize);
          WaveFile.Read(pData^, dwSize);
        end; // with
        Chunks.Add(Chunk);
      end; // while
    end; // if
  finally
    FreeAndNil(WaveFile);
  end;
end;
procedure TcnsWaveFileParser.ClearChunks;
var
  Chunk: PChunk;
begin
  while Chunks.Count > 0 do
  begin
    Chunk := Chunks[0];
    Chunks.Delete(0);
    if assigned(Chunk^.pData) then
      FreeMem(Chunk^.pData);
    dispose(Chunk);
  end; // while
end;
function TcnsWaveFileParser.GetChunkByType(ChunkType: TChunkType): PChunk;
var
  iIndex: integer;
begin
  Result := nil;
  iIndex := 0;
  while iIndex < Chunks.Count do
    if AnsiCompareText(PChunk(Chunks[iIndex])^.cType, ChunkType) = 0 then
    begin
      Result := Chunks[iIndex];
      break;
    end
    else
      iIndex := iIndex + 1;
end;
end.

[浏览: 次]   
上一篇:delphi 音乐播放器信号显示组件   下一篇:delphi 如何将.wav多媒体文件加载到可的执行程序
[收藏] [推荐] [返回顶部] [打印本页] [关闭窗口]  
    评论加载中…
google adsense热点文章
·delphi 播放wav文件
·delphi 设置声卡音量
·delphi 多媒体wave文件写盘
·delphi 多媒体音量调节
·delphi 如何将.wav多媒体文件加载到可
·delphi 音量输出仪表
·delphi 多媒体wave文件CD音频
·delphi 音乐播放器信号显示组件
·delphi 音乐播放器扬声器类
·delphi 如何处理wave多媒体文件的split
·delphi 如何处理扩展名为.avi的audio流
     delphi技术网 | firefox 下载 | Avant Browser下载 | dedecms 技术网 | drupal 爱好者 | php 技术网
  Copyright@www.delphichm.com,2006-2009.All Rights Reserved.
 
程序员联盟 | delphi Java .net|QQ:707102932