Einzelnen Beitrag anzeigen

Benutzerbild von p80286
p80286

Registriert seit: 28. Apr 2008
Ort: Stolberg (Rhl)
6.659 Beiträge
 
FreePascal / Lazarus
 
#3

Re: WAV-Datei: Header auslesen

  Alt 11. Mär 2009, 12:38
Hallo CARSTEN1234

vielleicht hilft Dir das hier:
Delphi-Quellcode:
type
  { prototyp für einen chunk in einer RIFF-Datei: }
  T_chunkproto=packed record
                 name:array[0..3] of char;
                 lang:integer;
               end;
  T_RIFF_HEAD=packed record
                name : Array [0..3] of char;
                lange: integer;
                name0: array[0..3] of char; { 'WAVE'  }
              end;
  T_WAVE_FMThead=packed record
               name : array[0..3] of char; {'fmt ' }
               lang : integer; {4Byte }
               ST_M : word; {2Byte  - ST=1 Mono=0 }
               Kanalanz : word; {2Byte }
               SamplRate: integer; {4Byte }
               Byte_sec : integer; {4Byte }
               Byte_sample:word; {2Byte 1=8BMono; 2=8B St oder 16B Mono; 4=16B Stereo }
               Bits_sample:word; {2Byte }
             end;
  T_fact_head=packed record
               name : array[0..3] of char; { 'fact' }
               lang : integer; {4Byte }
               {daten.....lang Byte}
             end;
  t_data_head=packed record
               name : array[0..3] of char; { 'data ' }
               lang : integer; {4Byte }
               {Daten....Lang Byte }
             end;
var
  riff_head: T_RIFF_HEAD;
  wav_head : t_wave_fmthead;
  data16ST : array of word;
  data16MO : array of word;
  data8ST : array of byte;
  data8MO : array of byte;
  pre_data : integer; { Anzahl Daten vor dem Data-Chunk }

function READ_HEADER(efile:string):boolean;
procedure READ_DATA(efile:string;cv:tcanvas;labl:tlabel);
function GET_PRE_DATA(efile:string):integer;

implementation

function GET_PRE_DATA(efile:string):integer;
var
  edat : file;
  buffer : array [0..$FFFF] of byte;
  tb : t_chunkproto absolute buffer;
  lies : integer;
  gelesen : integer;
  ende : boolean;
begin
  result:=0;
  assignfile(edat,efile);
  reset(edat,1);
  blockread(edat,buffer,sizeof(riff_head),gelesen); { RIFF-Header lesen}
  repeat
    blockread(edat,buffer,8,gelesen); { 4 char+ 4Byte länge}
    if tb.name<>'datathen begin
      lies:=tb.lang;
      seek(edat,filepos(edat)+lies);
    end
    else begin
      lies:=0;
      result:=filepos(edat)-8;
    end;
  until eof(edat) or (tb.name='data');
  closefile(edat);
end;{-- GET_PRE_DATA -----------------------------------------------------}

function READ_HEADER(efile:string):boolean;
var
  edat : file;
  buffer : array [0..$FFFF] of byte;
  gelesen : integer;
begin
  result:=false;
  assignfile(edat,efile);
  reset(edat,1);
  blockread(edat,buffer,sizeof(riff_head),gelesen);
  move(buffer[0],riff_head,sizeof(riff_head));
  if (riff_head.name='RIFF') and (riff_head.name0='WAVE') then begin
    result:=true;
    blockread(edat,buffer,sizeof(wav_head),gelesen);
    move(buffer[0],wav_head,sizeof(wav_head));
  end;
  closefile(edat);
end;
Gruß
K-H
  Mit Zitat antworten Zitat