From: Richard Dobson on
Jerry Avins wrote:
...
>> And I will quietly note that ~nobody~ else responding to the OP
>> offered this obvious (to those who know...) and simple piece of
>> information!
>
> Because until the OP understands what a .wav file is, the simple (and
> excellent) piece of information won't do him any good. He first needs to
> know that PCM _is_ integer. Then, if he really needs floating point, he
> needs to learn his programming language well enough to change types.
>

Or use (or copy to) a floats WAVE file - then you can just read and
process. Still PCM (at least, in the sense of "not compressed"), or so
I'm told. Lots of integer types in WAVE and AIFF files BTW: covering all
byte-lengths from 1 to 4 inclusive; 2 and 3-byte words of course the
most common by far. And with WAVE_EX, you can in principle have 20bit
words inside a 24bit container. So anyone parsing a PCM WAVE file still
needs to check if the data is integer or floats, what size of
integer/float the file contains, etc etc etc.

It is a ~lot~ less work, and a whole lot safer, just to use an
established library to do the job.

Richard Dobson
From: Jerry Avins on
Richard Dobson wrote:

> It is a ~lot~ less work, and a whole lot safer, just to use an
> established library to do the job.

Yes. I stand corrected and abashed, but the OP still needs to know what
a .wav file is -- in particular, _his_ .wav file. He can use libsndfile
to read the header. (Do you think he knows about headers?)

Jerry
--
Engineering is the art of making what you want from things you can get.
�����������������������������������������������������������������������
From: Richard Dobson on
Jerry Avins wrote:
> Richard Dobson wrote:
>
>> It is a ~lot~ less work, and a whole lot safer, just to use an
>> established library to do the job.
>
> Yes. I stand corrected and abashed, but the OP still needs to know what
> a .wav file is -- in particular, _his_ .wav file. He can use libsndfile
> to read the header. (Do you think he knows about headers?)
>
> Jerry


The only essential point to make in answering that question is that a
WAVE (or AIFF) file does not have a fixed-length header. The OP shoudl
disregard any suggestion to the contrary. You can't take a short cut and
say 'the audio starts at byte 34' or whatever. Well, you could, just, in
writing a file, but not in reading one. There are unfortunately many
examples (including many self-styled "documentation" pages) on the net
where that assumption is made, implicitly or explicitly (the original
matlab implementation of "wavread" suffered just this problem, among
other things). I long ago lost count of the number of unix programs
especially that broke simply because I gave them a WAVE file with a
longer header than the theoretical minimum.

All other things being equal, there are only two primary types of
programmer who should really commit the time and effort to delve into
the minutiae of such file formats - writers of soundfile handling
libraries such as Eric with libsndfile (which as I am sure he will
confirm has taken years of work to reach its present extremely
efficient, accurate and comprehensive state), and people who design file
formats (and thus need a custom soundfile library they can freely
"hack"); which is what I have done from time to time (e.g. for phase
vocoder analysis files, and for Ambisonic B-Format).


Richard Dobson
From: Erik de Castro Lopo on
Jerry Avins wrote:

> Richard Dobson wrote:
>
> > It is a ~lot~ less work, and a whole lot safer, just to use an
> > established library to do the job.
>
> Yes. I stand corrected and abashed, but the OP still needs to know what
> a .wav file is -- in particular, _his_ .wav file. He can use libsndfile
> to read the header. (Do you think he knows about headers?)

Quite honestly, manually read WAV file headers is something to
be avoided unless you have a very good reason not to. WAV files
have a rather poor sepcification and there have been many, many
programs over the years that produced odd or non-standard files.
libsndfile's WAV parser is full of little workarounds and special
cases for some of these non-standard files.

However, for those interested, the sndfile-info program which
comes with libsndfile dumps all the header information in a human
readable form liek this:

erik > sndfile-info drumset01-sep08wallywoods-zettberlin.wav

Version : libsndfile-1.0.21pre1

========================================
File : /home/erik/drumset01-sep08wallywoods-zettberlin.wav
Length : 270608864
RIFF : 270608856
WAVE
fmt : 16
Format : 0x3 => WAVE_FORMAT_IEEE_FLOAT
Channels : 2
Sample Rate : 96000
Block Align : 8
Bit Width : 32
Bytes/sec : 768000
fact : 4
frames : 33826097
PEAK : 24
version : 1
time stamp : 1221772493
Ch Position Value
0 12307085 0.817219
1 12307085 0.712256
data : 270608776
End

----------------------------------------
Sample Rate : 96000
Frames : 33826097
Channels : 2
Format : 0x00010006
Sections : 1
Seekable : TRUE
Duration : 00:05:52.355
Signal Max : 0.817219 (-1.75 dB)

Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
From: Erik de Castro Lopo on
Richard Dobson wrote:

> All other things being equal, there are only two primary types of
> programmer who should really commit the time and effort to delve into
> the minutiae of such file formats - writers of soundfile handling
> libraries such as Eric with libsndfile (which as I am sure he will
> confirm has taken years of work to reach its present extremely
> efficient, accurate and comprehensive state), and people who design file
> formats (and thus need a custom soundfile library they can freely
> "hack"); which is what I have done from time to time (e.g. for phase
> vocoder analysis files, and for Ambisonic B-Format).

I agree with this completely. Reading most files is relatively trivial
but there are a huge number of tiny variations, some within spec and
some no that make reading as many files as possible a pain in the neck.

On a side note, libsndfile has been publicly available for a little
over 10 years. The 10 year retrospective is here:

http://www.mega-nerd.com/erikd/Blog/CodeHacking/libsndfile/ten_years.html

libsndfile actually grew out of code I originally wrote in 1992,
when i decided that microsoft's API for reading WAV files was
simply way too horrible to use.

Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/