Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to read the file header of a wave file Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
06-Oct-02
Category
Multimedia
Language
Delphi All Versions
Views
96
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Kniebusch Horst

I want to open a wave file in my application, but how do I know that it is really a 
wave file and not just a file with *.wav extension? 

Answer:

First you have to know what the structure of a wave file is. I'd create a record 
which represent this structure:


1   type
2     TWaveHeader = record
3       ident1: array[0..3] of Char;      // Must be "RIFF"
4       len: DWORD;                       // Remaining length after this header
5       ident2: array[0..3] of Char;      // Must be "WAVE"
6       ident3: array[0..3] of Char;      // Must be "fmt "
7       reserv: DWORD;                    // Reserved 4 bytes
8       wFormatTag: Word;                 // format type
9       nChannels: Word;                  // number of channels (i.e. mono, stereo, 
10  etc.)
11      nSamplesPerSec: DWORD;            //sample rate
12      nAvgBytesPerSec: DWORD;           //for buffer estimation
13      nBlockAlign: Word;                //block size of data
14      wBitsPerSample: Word;             //number of bits per sample of mono data
15      cbSize: Word;                     //the count in bytes of the size of
16      ident4: array[0..3] of Char;      //Must be "data"
17  end;



With this structure you can get all the information's about a wave file you want to.
After this header following the wave data which contains the data for playing the 
wave file.

Now we trying to get the information's from a wave file. To be sure it's really a 
wave file, we test the information's:


18  function GetWaveHeader(FileName: TFilename): TWaveHeader;
19  const
20    riff = 'RIFF';
21    wave = 'WAVE';
22  var
23    f: TFileStream;
24    w: TWaveHeader;
25  begin
26    if not FileExists(Filename) then
27      exit; //exit the function if the file does not exists
28  
29    try
30      f := TFileStream.create(Filename, fmOpenRead);
31      f.read(w, Sizeof(w)); //Reading the file header
32  
33      if w.ident1 <> riff then
34      begin //Test if it is a RIFF file, otherwise exit
35        Showmessage('This is not a RIFF File');
36        exit;
37      end;
38  
39      if w.ident2 <> wave then
40      begin //Test if it is a wave file, otherwise exit
41        Showmessage('This is not a valid wave file');
42        exit;
43      end;
44  
45    finally
46      f.free;
47    end;
48  
49    Result := w;
50  end;




I hope this example will help you to work with wave files in your application.




			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC