"Michel Rouzic" <Michel0528@yahoo.fr> wrote in message news:1147809277.909387.219930@i39g2000cwa.googlegroups.com...> > Erik de Castro Lopo wrote: >> >> If you really want to roll your own go for it. If it comes to >> writing, please use libsndfile because if you make a mistake >> I might have to add code to work around the malformed files >> you create. Its not just smaller developers who get this >> wrong either. There are some well know pieces of software >> which have versions which create bad files. > > wow! you support people's mistake! that's weird.I would imagine that if Eric didn't, people will complain about his software. After all, XYZ Pro commercial software in version 12.0 couldn't possibly have a bug writing a wave file--it must be this little free library off the 'net! :-)
WAV to PCM conversion
Started by ●May 11, 2006
Reply by ●May 18, 20062006-05-18
Reply by ●May 18, 20062006-05-18
"Michel Rouzic" <Michel0528@yahoo.fr> wrote in message news:1147809664.732199.213350@i40g2000cwc.googlegroups.com...> > Jon Harris wrote: >> "Michel Rouzic" <Michel0528@yahoo.fr> wrote in message >> news:1147652536.653509.187020@y43g2000cwc.googlegroups.com... >> > >> > Suneeel@gmail.com wrote: >> >> Hi all, >> >> >> >> I've recorded a wav file at 8KHz with an 8bit sample size. I now want >> >> to write code to convert the data from the wav file to PCM, so that I >> >> can send it over my ISDN Card to a phone. I've read that a wav file is >> >> basicaly the PCM data with some headers. If this is true, it shouldnt >> >> be that difficult to convert it. However, I havent been able to figure >> >> out how to do this.... >> >> >> >> Could someone please help me out... >> > >> > Funny, it seems that I'm the only one out there who wrote his own >> > input/output .wav functions. They are quite simple and can read and >> > write 8-bit, 16-bit and 32-bit IEEE-754 float format and output the PCM >> > data to a bidimensional array of doubles as well as an array with the >> > content of each tag in it. Drop me a mail if you'd like to see the code. >> >> It's one of those things where it can be very simple to read a few types of >> wave >> files, but to really handle all the permutations, corner cases, errors, etc. >> gracefully it becomes a much bigger project. > > When you're sticking to the PCM WAVE, it's quite simple, isn't it? I > mean you have a fixed 44 bytes of tags, right? and you only have 8-bit > unsigned, 16-bit signed and 32-bit IEEE-754 floats, right? If not well > those three are really all I need anyways.Those are the "few types" I was talking about. The ones you left out (and Eric mentioned elsewhere) are all the "permutations, corner cases, error cases, etc." I was talking about. If you only need a few types for your own use, by all means use your code! We are just pointing out the advantage of a "real" library.
Reply by ●May 18, 20062006-05-18
Ironically, there is another thread going on dealing with a very similar topic. See "Audio programming - WAV data chunk format issues". -- Jon Harris SPAM blocker in place: Remove 99 (but leave 7) to reply
Reply by ●May 19, 20062006-05-19
Hi Erik, Erik de Castro Lopo wrote:> Michel Rouzic wrote: >> Funny, it seems that I'm the only one out there who wrote his own >> input/output .wav functions. They are quite simple and can read and >> write 8-bit, 16-bit and 32-bit IEEE-754 float format and output the PCM >> data to a bidimensional array of doubles as well as an array with the >> content of each tag in it. Drop me a mail if you'd like to see the code. > > One of the things your WAV parser probably doesn't have is code > that works around the vast number of broken and malformed files > that are generated by software people rolled themselves. > libsndfile has this. > > If you really want to roll your own go for it. If it comes to > writing, please use libsndfile because if you make a mistake > I might have to add code to work around the malformed files > you create. Its not just smaller developers who get this > wrong either. There are some well know pieces of software > which have versions which create bad files. > > ErikOne quirk you don't seem to deal with in libsndfile, which is quite common, is files where the length of the audio chunk is always zero, and the audio extends to the very end of the file. That is, they write the header at the beginning, and don't go back to fill in the length at the end of recording. Several useful tools can read files like that, such as wavesurfer. When I hit these file, I usually use wavesurfer to read in the file, and spit out one with a proper header. Regards, Steve
Reply by ●May 19, 20062006-05-19
Erik de Castro Lopo wrote:> Michel Rouzic wrote: > > > > wow! you support people's mistake! that's weird. I made sure that I > > read the wave format specifications > > I sually find that specfications are often incomplete and at times > plain wrong. > > > correctly and I can tell it works > > nicely because it reads correctly files from Audition for example. > > Audition (previously named Cool Edit I beleive) was actually guilty > of one of the most egregious mistakes when it came to writing WAV > files. The was a version of that software that wrote a file which > according to the headers contained 32 bit integer PCM sample which > were in fact 32 bit float PCM samples.oh alright, the reason why i haven't noticed it is that i determine how to read the data solely using the bits-per-sample tag (although i still read, store and write the format tag properly)
Reply by ●May 19, 20062006-05-19
Richard Dobson wrote:> Erik de Castro Lopo wrote: > > > Audition (previously named Cool Edit I beleive) was actually guilty > > of one of the most egregious mistakes when it came to writing WAV > > files. The was a version of that software that wrote a file which > > according to the headers contained 32 bit integer PCM sample which > > were in fact 32 bit float PCM samples. > > > > > > It's still around in Cool Edit Pro; and just as egregious! The 0dBFS > value is not 1.0 but 32768.0.That's what the app says, but in reality if you input a properly written 32-bit float wave file in the +/- 1.0 range, it will appear in the correct range.> And even old warhorses such as sox have very weak support for WAVE and > AIFF (last version I tried wrote very bad AIFF files where the chunk > sizes didn't even add up correctly). Main problem, all too easily > promulgated by abbreviated 4th-party "documentation" is the total myth > that WAVE has a fixed-size header. > > Unfortunately, one has to read documents deep within Microsoft developer > documentation to know about the more recent extensions to the ~original~ > RIFF spec (of which WAVE is a subset), which latter can be read here: > > http://www.bath.ac.uk/~masrwd/riffmcidoc.zip > > Then there is the latest arcana of WAVEFORMATEXTENSIBLE, relevant to > anyone needing to read or write 24bit files, or files with more than 2 > channels. > > Richard Dobson
Reply by ●May 19, 20062006-05-19
Michel Rouzic wrote: ..>> It's still around in Cool Edit Pro; and just as egregious! The 0dBFS >> value is not 1.0 but 32768.0. > > That's what the app says, but in reality if you input a properly > written 32-bit float wave file in the +/- 1.0 range, it will appear in > the correct range. >Sure, it knows about standard floats WAVE files; it's just CEP's "own" Type-1 floats format that is "unorthodox". Richard Dobson
Reply by ●May 19, 20062006-05-19
Steve Underwood wrote:> > One quirk you don't seem to deal with in libsndfile, which is quite > common, is files where the length of the audio chunk is always zero, and > the audio extends to the very end of the file. That is, they write the > header at the beginning, and don't go back to fill in the length at the > end of recording. Several useful tools can read files like that, such as > wavesurfer. When I hit these file, I usually use wavesurfer to read in > the file, and spit out one with a proper header.I've actually never seen one like this. Do you have a smallist (say up to 100k) example you could send me? If its a problem I'll fix it. Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo +-----------------------------------------------------------+ "life is too long to be an expert at harmful things, including such evilness as C++ and perl." -- Erik Naggum






