BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to read the WAV header?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Multimedia
View previous topic :: View next topic  
Author Message
Marcelo Muzilli
Guest





PostPosted: Fri Jun 25, 2004 4:57 pm    Post subject: How to read the WAV header? Reply with quote



Howdy all,
how can I read the header of a WAV file?

For example, in C I have the WAV in the code below. This is only the
firsts 44 bytes:

typedef struct wav_header{ /* RIFF */
char riff[4]; /* "RIFF" (4 bytes) */
long TotLen; /* File length - 8 bytes (4 bytes) */
char wavefmt[8]; /* "WAVEfmt " (8 bytes) */
long Len; /* Remaining length (4 bytes) */
short format_tag; /* Tag (1 = PCM) (2 bytes) */
short channels; /* Mono=1 Stereo=2 (2 bytes) */
long SamplesPerSec; /* No samples/sec (4 bytes) */
long AvgBytesPerSec; /* Average bytes/sec (4 bytes) */
short BlockAlign; /* Block align (2 bytes) */
short FormatSpecific; /* 8 or 16 bit (2 bytes) */
char data[4]; /* "data" (4 bytes) */
long datalen; /* Raw data length (4 bytes) */
/* ..data follows. Total header size = 44 bytes */
} wav_header_s;

I declare a variable:
wav_header_s header;
FILE *wav_fp;

Open the file:
wav_fp = fopen(argv[1], "rb")

Read the WAV file:
fread(&header, 44, 1, wav_fp);

In the filelenght variable I will store the size of WAV file (pay
attention in the TotLen WAV property):
filelength = header.TotLen;

Well, this is in C code, but how can I convert this for Delphi? I need
the WAV lenght defined in the header of a WAV file.

Thank you in advance,

Marcelo Muzilli
Back to top
pgx@pgrahams.com
Guest





PostPosted: Sat Jun 26, 2004 4:19 pm    Post subject: Re: How to read the WAV header? Reply with quote



Marcelo Muzilli <marcelo (AT) gelt (DOT) com.br> wrote:

Quote:
Howdy all,

I need
the WAV lenght defined in the header of a WAV file.


Easiest,if you only need the length:

var f:file
len:integer;

assignfile(f,'File.wav');reset(f,1); //binary file,1-byte read length
blockread(f,len); // skip 4 bytes (or you could use "seek" )
blockread(f,len); // this gives you the length
closefile(f);

OR....

you can dig into MMSystem and find the pieces of the wave file header,
define a variable with them, and have access to the whole header.
Note that the header you defined is not the only possiblilty. There
are other chunks that can be present that would mean that the wave
data is not everything past the first 44 bytes, as your header would
suggest.

If you need more than length, let us know.

Phil

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.