Are there a simple C code to read WAV file available? Appreciate it
C code to read WAV file?
Started by ●March 14, 2015
Reply by ●March 14, 20152015-03-14
On 3/14/15 12:51 PM, speech2020@gmail.com wrote:> Are there a simple C code to read WAV file available? > Appreciate itmight not "simple", but there is http://www.mega-nerd.com/libsndfile/ . i might suggest getting a reference on the WAV file format and use fopen() and fclose() and parse it yourself. i found that to be much easier for AIFF files long ago when i used to do that sorta thing (might do it again). there are little-endian issues to worry about, and maybe, for 8-bit files, a constant offset (0x80) to worry about, otherwise, if the WAV file is not compressed, it should be straight-forward. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●March 14, 20152015-03-14
On Saturday, March 14, 2015 at 1:01:14 PM UTC-7, robert bristow-johnson wrote:> On 3/14/15 12:51 PM, wrote: > > Are there a simple C code to read WAV file available? > > Appreciate it > > might not "simple", but there is http://www.mega-nerd.com/libsndfile/ . > > i might suggest getting a reference on the WAV file format and use > fopen() and fclose() and parse it yourself. i found that to be much > easier for AIFF files long ago when i used to do that sorta thing (might > do it again). there are little-endian issues to worry about, and maybe, > for 8-bit files, a constant offset (0x80) to worry about, otherwise, if > the WAV file is not compressed, it should be straight-forward. > > > -- > > r b-j > > "Imagination is more important than knowledge."Actually, the whole point is that I do NOT want to use libsndfile. Thanks for any other pointers.
Reply by ●March 14, 20152015-03-14
speech2020@gmail.com wrote:> On Saturday, March 14, 2015 at 1:01:14 PM UTC-7, robert bristow-johnson wrote: >> On 3/14/15 12:51 PM, wrote: >>> Are there a simple C code to read WAV file available? >>> Appreciate it >> >> might not "simple", but there is http://www.mega-nerd.com/libsndfile/ . >> >> i might suggest getting a reference on the WAV file format and use >> fopen() and fclose() and parse it yourself. i found that to be much >> easier for AIFF files long ago when i used to do that sorta thing (might >> do it again). there are little-endian issues to worry about, and maybe, >> for 8-bit files, a constant offset (0x80) to worry about, otherwise, if >> the WAV file is not compressed, it should be straight-forward. >> >> >> -- >> >> r b-j >> >> "Imagination is more important than knowledge." > > Actually, the whole point is that I do NOT want to use libsndfile. > > Thanks for any other pointers. >I built a C+++ class that lives on top of libsndfile. If it's the API that bugs you ( as opposed to the restrictive licensing requirements ) holler with a munged email and I'll send it to you. It comes with an Arkansas guarantee - if it breaks in half, you get to keep both halves. So no warranty implied or otherwise, all that. But a .wav file parser isn't hard. The header spec is all over the place. -- Les Cargill
Reply by ●March 14, 20152015-03-14
On Saturday, March 14, 2015 at 1:33:45 PM UTC-7, Les Cargill wrote:> wrote: > > On Saturday, March 14, 2015 at 1:01:14 PM UTC-7, robert bristow-johnson wrote: > >> On 3/14/15 12:51 PM, wrote: > >>> Are there a simple C code to read WAV file available? > >>> Appreciate it > >> > >> might not "simple", but there is http://www.mega-nerd.com/libsndfile/ . > >> > >> i might suggest getting a reference on the WAV file format and use > >> fopen() and fclose() and parse it yourself. i found that to be much > >> easier for AIFF files long ago when i used to do that sorta thing (might > >> do it again). there are little-endian issues to worry about, and maybe, > >> for 8-bit files, a constant offset (0x80) to worry about, otherwise, if > >> the WAV file is not compressed, it should be straight-forward. > >> > >> > >> -- > >> > >> r b-j > >> > >> "Imagination is more important than knowledge." > > > > Actually, the whole point is that I do NOT want to use libsndfile. > > > > Thanks for any other pointers. > > > > I built a C+++ class that lives on top of libsndfile. If it's the API > that bugs you ( as opposed to the restrictive licensing requirements ) > holler with a munged email and I'll send it to you. > > It comes with an Arkansas guarantee - if it breaks in half, you get to > keep both halves. So no warranty implied or otherwise, all that. > > But a .wav file parser isn't hard. The header spec is all over > the place. > > -- > Les CargillWith your API, does it still need installation of libsndfile - then it is no good for me. Otherwise, pls send it to me - I do not know your email - mine is speech2020 gmail.
Reply by ●March 14, 20152015-03-14
On Saturday, March 14, 2015 at 1:33:45 PM UTC-7, Les Cargill wrote:> wrote: > > On Saturday, March 14, 2015 at 1:01:14 PM UTC-7, robert bristow-johnson wrote: > >> On 3/14/15 12:51 PM, wrote: > >>> Are there a simple C code to read WAV file available? > >>> Appreciate it > >> > >> might not "simple", but there is http://www.mega-nerd.com/libsndfile/ . > >> > >> i might suggest getting a reference on the WAV file format and use > >> fopen() and fclose() and parse it yourself. i found that to be much > >> easier for AIFF files long ago when i used to do that sorta thing (might > >> do it again). there are little-endian issues to worry about, and maybe, > >> for 8-bit files, a constant offset (0x80) to worry about, otherwise, if > >> the WAV file is not compressed, it should be straight-forward. > >> > >> > >> -- > >> > >> r b-j > >> > >> "Imagination is more important than knowledge." > > > > Actually, the whole point is that I do NOT want to use libsndfile. > > > > Thanks for any other pointers. > > > > I built a C+++ class that lives on top of libsndfile. If it's the API > that bugs you ( as opposed to the restrictive licensing requirements ) > holler with a munged email and I'll send it to you. > > It comes with an Arkansas guarantee - if it breaks in half, you get to > keep both halves. So no warranty implied or otherwise, all that. > > But a .wav file parser isn't hard. The header spec is all over > the place. > > -- > Les CargillWith your API, does it still need installation of libsndfile - then it is no good for me. Otherwise, pls send it to me - I do not know your email - mine is speech2020 gmail.
Reply by ●March 14, 20152015-03-14
On 3/14/15 4:04 PM, speech2020@gmail.com wrote:> On Saturday, March 14, 2015 at 1:01:14 PM UTC-7, robert bristow-johnson wrote: >> On 3/14/15 12:51 PM, wrote: >>> Are there a simple C code to read WAV file available? >>> Appreciate it >> >> might not "simple", but there is http://www.mega-nerd.com/libsndfile/ . >> >> i might suggest getting a reference on the WAV file format and use >> fopen() and fclose() and parse it yourself. i found that to be much >> easier for AIFF files long ago when i used to do that sorta thing (might >> do it again). there are little-endian issues to worry about, and maybe, >> for 8-bit files, a constant offset (0x80) to worry about, otherwise, if >> the WAV file is not compressed, it should be straight-forward. >> >> >> -- >> >> r b-j >> >> "Imagination is more important than knowledge." > > Actually, the whole point is that I do NOT want to use libsndfile. >i understand. i really do.> Thanks for any other pointers.it's been decades since i did this. pointers: !. so find a resource that describes most .wav files like http://soundfile.sapp.org/doc/WaveFormat/ and http://www-mmsp.ece.mcgill.ca/documents/AudioFormats/WAVE/WAVE.html . 2. then use fopen(), fread(), fwrite(), fclose() from the C stdlib (i confess i really dunno how to use the "<<" operator in C++) to get access to the file. you can use fread() to "rewind" in the file to get back to the beginning or to skip ahead to any part in a long file. 3. read the various Chunks. skip over over the Chunks you don't care about. read the Chucks you *do* care about to get the data you're looking for. 4. you need to worry a little about big-ending vs. little-endian issues. you might have to read each byte separately and construct the various salient parameters from that (like file length, sample rate, word width, etc.). it's unlikely that you'll have anything other than normal little-endian, 2's complement signed, binary format. rot o' ruk. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●March 15, 20152015-03-15
On Sat, 14 Mar 2015 20:05:26 -0400, robert bristow-johnson <rbj@audioimagination.com> wrote:>On 3/14/15 4:04 PM, speech2020@gmail.com wrote: >> On Saturday, March 14, 2015 at 1:01:14 PM UTC-7, robert bristow-johnson wrote: >>> On 3/14/15 12:51 PM, wrote: >>>> Are there a simple C code to read WAV file available? >>>> Appreciate it >>> >>> might not "simple", but there is http://www.mega-nerd.com/libsndfile/ . >>> >>> i might suggest getting a reference on the WAV file format and use >>> fopen() and fclose() and parse it yourself. i found that to be much >>> easier for AIFF files long ago when i used to do that sorta thing (might >>> do it again). there are little-endian issues to worry about, and maybe, >>> for 8-bit files, a constant offset (0x80) to worry about, otherwise, if >>> the WAV file is not compressed, it should be straight-forward. >>> >>> >>> -- >>> >>> r b-j >>> >>> "Imagination is more important than knowledge." >> >> Actually, the whole point is that I do NOT want to use libsndfile. >> > >i understand. i really do. > >> Thanks for any other pointers. > >it's been decades since i did this. > >pointers: > >!. so find a resource that describes most .wav files like >http://soundfile.sapp.org/doc/WaveFormat/ and >http://www-mmsp.ece.mcgill.ca/documents/AudioFormats/WAVE/WAVE.html . > >2. then use fopen(), fread(), fwrite(), fclose() from the C stdlib (i >confess i really dunno how to use the "<<" operator in C++) to get >access to the file. you can use fread() to "rewind" in the file to get >back to the beginning or to skip ahead to any part in a long file. > >3. read the various Chunks. skip over over the Chunks you don't care >about. read the Chucks you *do* care about to get the data you're >looking for. > >4. you need to worry a little about big-ending vs. little-endian issues. > you might have to read each byte separately and construct the various >salient parameters from that (like file length, sample rate, word width, >etc.). it's unlikely that you'll have anything other than normal >little-endian, 2's complement signed, binary format.One other issue is that there are (at least) 3 different WAV formats. The oldest is just WAVEFORMAT. Next came WAVEFORMATEX which added a cbSize WORD at the end. These two cover most files out there, but the newest WAVEFORMATEXTENSIBLE is becoming more common. It handles multi-channel "surround sound" outputs, so it has a dwChannelMask DWORD as well as the ever-popular (with Microsoft, anyway, certainly not with me!) GUID subformat code. The first two formats can pretty much be handled identically other than skipping over the cbSize word. The -EXTENSIBLE format requires special handling since you have to read the data using the right data size and the right channel pattern to sort things out. Best regards, Bob Masta DAQARTA v7.60 Data AcQuisition And Real-Time Analysis www.daqarta.com Scope, Spectrum, Spectrogram, Sound Level Meter Frequency Counter, Pitch Track, Pitch-to-MIDI FREE Signal Generator, DaqMusiq generator Science with your sound card!
Reply by ●March 15, 20152015-03-15
On 14/03/2015 22:50, speech2020@gmail.com wrote: ...>> >> I built a C+++ class that lives on top of libsndfile. If it's the API >> that bugs you ( as opposed to the restrictive licensing requirements ) >> holler with a munged email and I'll send it to you. >> >> It comes with an Arkansas guarantee - if it breaks in half, you get to >> keep both halves. So no warranty implied or otherwise, all that. >> >> But a .wav file parser isn't hard. The header spec is all over >> the place. >> >> -- >> Les Cargill > > > With your API, does it still need installation of libsndfile - then it is no good for me. > > Otherwise, pls send it to me - I do not know your email - mine is speech2020 gmail. >As pointed out elsewhere, reading a wav file is not so simple, unless you only intend to support the bare minimum varieties. What usually happens is that programmers start that way, and then get so annoyed by all the legal varities of WAVE (and some illegal ones) their code doesn't handle that they end up either writing a much more comphrehensive library, or using libsndfile. If libsndfile does not suit (any particular reason?) you might like to consider the "portsf" library I wrote for the "Audio Programming Book" (MIT press), where it is documented in detail, along with many example programs using it. It is available by itself from here: https://github.com/daniel-murray/portsf/tree/master/portsf A more recent version is available on the CDP github site**. The API has some superficial similarities with libsndfile (there are after all only so many ways one can write soundfile functions in standard C). It handles plain Linear PCM multichannel wave formats including WAVEFORMATEXTENSIBLE (I use it for all the programs in the CDP multichannel toolkit), along with basic AIFF/C support. Most of the code is in a single very long .c file, and the project is presented as a plain static library. BSD licence. The code is woefully unoptimized compared to libsndfile (such things are "left as an exercise"), but it runs fast enough, really. If nothing else, it shows reasonably clearly and comprehensively what to do to parse a WAVE file header. Richard Dobson ** https://github.com/ComposersDesktop/CDP7/tree/master/dev/externals/portsf
Reply by ●March 15, 20152015-03-15
speech2020@gmail.com wrote:> On Saturday, March 14, 2015 at 1:33:45 PM UTC-7, Les Cargill wrote: >> wrote: >>> On Saturday, March 14, 2015 at 1:01:14 PM UTC-7, robert bristow-johnson wrote: >>>> On 3/14/15 12:51 PM, wrote: >>>>> Are there a simple C code to read WAV file available? >>>>> Appreciate it >>>> >>>> might not "simple", but there is http://www.mega-nerd.com/libsndfile/ . >>>> >>>> i might suggest getting a reference on the WAV file format and use >>>> fopen() and fclose() and parse it yourself. i found that to be much >>>> easier for AIFF files long ago when i used to do that sorta thing (might >>>> do it again). there are little-endian issues to worry about, and maybe, >>>> for 8-bit files, a constant offset (0x80) to worry about, otherwise, if >>>> the WAV file is not compressed, it should be straight-forward. >>>> >>>> >>>> -- >>>> >>>> r b-j >>>> >>>> "Imagination is more important than knowledge." >>> >>> Actually, the whole point is that I do NOT want to use libsndfile. >>> >>> Thanks for any other pointers. >>> >> >> I built a C+++ class that lives on top of libsndfile. If it's the API >> that bugs you ( as opposed to the restrictive licensing requirements ) >> holler with a munged email and I'll send it to you. >> >> It comes with an Arkansas guarantee - if it breaks in half, you get to >> keep both halves. So no warranty implied or otherwise, all that. >> >> But a .wav file parser isn't hard. The header spec is all over >> the place. >> >> -- >> Les Cargill > > > With your API, does it still need installation of libsndfile - then it is no good for me. >Yes, it does.> Otherwise, pls send it to me - I do not know your email - mine is speech2020 gmail. >-- Les Cargill






