Need help working with WAV (RIFF) files at the byte level
I am writing an application in C # that will record audio files (* .wav) and automatically tag and name them. Wave files are RIFF files (eg AVI) that can contain chunks of metadata in addition to waveform data blocks. So now I'm trying to figure out how to read and write RIFF metadata to and from recorded wave files.
I am using NAudio to write files and have set their forums as well on SO to read and write RIFF tags. While I got a number of good answers, none of the solutions made it possible to read and write RIFF chunks as easily as I would like.
But more importantly, I have very little experience with files at the byte level, and I think this might be a good opportunity to learn. So now I want to try writing my own class (s) that can read into a RIFF file and allow metadata to be read and written from the file.
I've used streams in C # but always with the whole stream at once. So now I'm a bit lost that I have to consider a byte file by byte. Specifically, how do I go about deleting or inserting bytes in and out of the middle of a file? I've tried reading a file via FileStream into a byte array (byte []) as shown in the code below.
System.IO.FileStream waveFileStream = System.IO.File.OpenRead(@"C:\sound.wav");
byte[] waveBytes = new byte[waveFileStream.Length];
waveFileStream.Read(waveBytes, 0, waveBytes.Length);
And I saw through the Visual Studio debugger that the first four bytes are the header of the RIFF file.

But arrays are a pain to deal with when performing actions that change their size, such as inserting or deleting values. So I thought I could do it in byte [] in a list like this.
List<byte> list = waveBytes.ToList<byte>();
Which would make any file byte byte manipulation much easier, but I'm worried that maybe I missed something like a class in the System.IO namespace that would make it all even easier. Am I on the right track, or is there a better way to do this? I should also mention that I'm not very much interested in performance and prefer not to deal with pointers or unsafe blocks of code like this guy .
If it helps at all, good article in RIFF / WAV format.
source to share
I didn't write in C #, but I can point out some places that are bad from my point of view:
1) Do not read entire WAV files in memory, unless the files are your own files and are small in size.
2) No need to insert data into memory. You can simply, for example, do the following: parse the source file, store chunk offsets, and read the metadata in memory; submit metadata for editing in a dialog box; while saving the RIFF-WAV header record, fmt chunk, transferring audio data from the source file (by reading and writing blocks), adding metadata; update the RIFF-WAV header.
3) Try to keep the metadata in the tail of the file. This will ensure that the striped tag alone does not require the entire file to be rewritten.
It seems that some sources regarding working with RIFF files in C # are present here .
source to share