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.wow! you support people's mistake! that's weird. I made sure that I read the wave format specifications correctly and I can tell it works nicely because it reads correctly files from Audition for example. It surely isn't as nice as your library, but I like to have total control over such things, and for example I needed that when I made one of my little programs big-endian compatible (although i'm sure your library is little endian compatible)
WAV to PCM conversion
Started by ●May 11, 2006
Reply by ●May 16, 20062006-05-16
Reply by ●May 16, 20062006-05-16
Ross Clement (Email address invalid - do not use) wrote:> I must agree with Erik. Once you use libsndfile once and find how easy > it is, I can see few reasons not to use it whenever you want to read or > write WAV files. I prefer to think of sampled data as being floating > point rather than integers, and with libsndfile, I don't ever get > exposed to the underlying data format. It's just as easy to read the > data as integers if you prefer.Oh you know, as for my functions, no matter whether it reads 8-bit, 16-bit or 32-bit float it outputs it as a double-precision float in the +/- 1.0 range. Once I did those functions when I started DSP, I hardly ever had to bother with that stuff again. And it has quite some educational value when you're totally new to DSP and you're eager to find out how the stuff works. Feels better than using some wizard's library. Not only that but you can decide how you want your stuff to be, for example I want my tags in an array with macros attributed to the important tags. very handy when using/changing tags inside a function. just an example.
Reply by ●May 16, 20062006-05-16
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.
Reply by ●May 16, 20062006-05-16
Jerry Avins wrote:> Ross Clement (Email address invalid - do not use) wrote: > > > ... I prefer to think of sampled data as being floating > > point rather than integers, ... > > Do you suppose there will ever be a floating-point ADC?There are lots of them already. I haven't gone into these papers in detail, but it appears that they are used in applications when the range of the signal being sampled is very large. The first reference shows "analogue ranging circutry" being used to adjust the signal and outputing an exponent, and the modified signal is then sampled by a commercial ADC, the output of which is the mantissa. http://www-ppd.fnal.gov/EEDOffice-W/ASIC_Development/Assets/Presentations/G3_ZIMMERMAN.pdf http://ir.lib.sfu.ca/handle/1892/640 http://www.ee.iitb.ac.in/~esgroup/es_mtech04_sem/es_sem04_paper_04307416.pdf Cheers, Ross-c
Reply by ●May 16, 20062006-05-16
I would agree that wanting to know how things work is a very good reason for writing things yourself, and that was what I was thinking of when I said "very few reasons". Perhaps I should have used different wording there. I was once criticised strongly on some maths groups for writing my own routines for inverting matrices. I ended up using LAPACK routines, but feel that I gained a fair bit by revising some methods for finding inverses. But in the end, the LAPACK "wizard's library" was the best thing to use for reasons of speed and numerical accuracy. The libsndfile being robust concerning "broken" wav files is a good reason for using it in real applications. Cheers, Ross-c
Reply by ●May 16, 20062006-05-16
Ross Clement (Email address invalid - do not use) wrote:> Jerry Avins wrote: > >>Ross Clement (Email address invalid - do not use) wrote: >> >> >>> ... I prefer to think of sampled data as being floating >>>point rather than integers, ... >> >>Do you suppose there will ever be a floating-point ADC? > > > There are lots of them already. I haven't gone into these papers in > detail, but it appears that they are used in applications when the > range of the signal being sampled is very large. The first reference > shows "analogue ranging circutry" being used to adjust the signal and > outputing an exponent, and the modified signal is then sampled by a > commercial ADC, the output of which is the mantissa. > > http://www-ppd.fnal.gov/EEDOffice-W/ASIC_Development/Assets/Presentations/G3_ZIMMERMAN.pdf > http://ir.lib.sfu.ca/handle/1892/640 > http://www.ee.iitb.ac.in/~esgroup/es_mtech04_sem/es_sem04_paper_04307416.pdfThe wonders of the modern age will never cease! jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●May 16, 20062006-05-16
Michel Rouzic wrote:> Jon Harris wrote: > > 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?Not if you recorded it with Windows Recorder or many other software. You might have an extra 2 bytes padding in the format chunk, and also a fact chunk of 12 bytes for a total of 58 bytes! -- Phil Frisbie, Jr. Hawk Software http://www.hawksoft.com
Reply by ●May 17, 20062006-05-17
Michel Rouzic wrote:> > wow! you support people's mistake! that's weird. I made sure that I > read the wave format specificationsI 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.> It > surely isn't as nice as your library, but I like to have total control > over such things, and for example I needed that when I made one of my > little programs big-endian compatible (although i'm sure your library > is little endian compatible)Yes and its cross platform and it supports more than just WAV files. Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo +-----------------------------------------------------------+ "Why do they protest against France for making it illegal to wear hijabs, but not against Saudi Arabia for making it illegal not to wear them?" -- Irshad Manji http://www.timesonline.co.uk/article/0,,2092-1696968,00.html
Reply by ●May 17, 20062006-05-17
Michel Rouzic wrote:> > When you're sticking to the PCM WAVE, it's quite simple, isn't it?No.> I mean you have a fixed 44 bytes of tags, right?No. I ac supply you with a vaild file where this is not the case.> and you only have 8-bit > unsigned, 16-bit signed and 32-bit IEEE-754 floats, right?No, WAV also supports 24 and 32 bit integers, 64 bit IEEE double precision floats, u-law, a-law, MS ADPCM, IAM ADPCM, GSM 6.10. Libsndfile supports all of the above. In addition, there are also about 20 more APDCM formats, MP3 and about 50 other formats that libsndfile doesn't support. Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo +-----------------------------------------------------------+ "Martyrs are the rock stars of the Muslim world, shown on the internet against a background of funky music. They feed on the self-esteem crisis of young Muslims." -- Irshad Manji http://www.timesonline.co.uk/article/0,,2092-1696968,00.html
Reply by ●May 17, 20062006-05-17
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. 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






