Search code examples
c++cencodingwavlame

Lame wav to array and back to wav with c/c++


Can I convert a wav file to a simple c double or int array and convert back to a new wav file? I want to use some c filter in the wav file. I red that with lame it is possible. But I don't know how. Can someone link some documentation or code snippet, how I can use it?

wav file -> array -> some operation -> wav file

Thank you for the answers.


Solution

  • This has nothing to do with Lame. Lame is a tool for encoding MP3 files.

    There are many libraries for reading and writing WAV files. You can even write your own, but that's inconvenient because WAV files have so many different sample formats: 8-bit, 16-bit, 24-bit, floating point, ADPCM, µlaw, etc.

    You can use libsndfile to read WAV files.

    Fields in WAV files do not have fixed offsets

    The reason this is bold + large is because a lot of people think that the data in a WAV file always starts at 44 bytes. This is simply not true. A WAV file is a RIFF file, and can contain an arbitrary number of chunks of data, one or more of which contains sample data. You'd be forgiven for being unable to handle esoteric WAV files, but if you make assumptions about the locations of data in the file you can end up with garbage.