Viewing a single comment thread. View all comments

RelativeApricot1782 t1_je4t9td wrote

>Bytes 37 through 44 tell the computer: “Okay the actual data is coming now. Just a reminder: this is how big it is.”

Why does the computer need to be reminded?

4

mrpenchant t1_je4vys2 wrote

They misstated it a little bit.

The way the format is set up is the first time it gives a length is for the whole thing, but it is defined to have 2 subchunks. The first subchunk will always have the same size for a wave file, but does provide a length of that subchunk and then the last data length is just for the data in the 2nd subchunk.

This is all to say, it's not a reminder but a slightly different length, which would be the length of the entire thing minus 36.

5

aiusepsi t1_je4u9v5 wrote

A computer doesn't, but software is (at least for now) written by human beings. You could have the size of the actual payload be implicit, and calculated from the information you've already seen, but there's more opportunity for the person writing the code which is reading the file to get the calculation wrong in some subtle way.

If the size is written explicitly just before the data, you can make the code which reads it much simpler and therefore more reliable. Simple and reliable is really good for this kind of code; mistakes can lead to software containing security vulnerabilities. Nobody wants to get a virus because they played a .wav file!

2