What do the bytes in a .wav file represent?

后端 未结 6 1008
醉话见心
醉话见心 2020-12-04 08:40

When I store the data in a .wav file into a byte array, what do these values mean? I\'ve read that they are in two-byte representations, but what exactly is contained in the

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 09:25

    As others have pointed out, there's metadata in the wav file, but I think your question may be, specifically, what do the bytes (of data, not metadata) mean? If that's true, the bytes represent the value of the signal that was recorded.

    What does that mean? Well, if you extract the two bytes (say) that represent each sample (assume a mono recording, meaning only one channel of sound was recorded), then you've got a 16-bit value. In WAV, 16-bit is (always?) signed and little-endian (AIFF, Mac OS's answer to WAV, is big-endian, by the way). So if you take the value of that 16-bit sample and divide it by 2^16 (or 2^15, I guess, if it's signed data), you'll end up with a sample that is normalized to be within the range -1 to 1. Do this for all samples and plot them versus time (and time is determined by how many samples/second is in the recording; e.g. 44.1KHz means 44.1 samples/millisecond, so the first sample value will be plotted at t=0, the 44th at t=1ms, etc) and you've got a signal that roughly represents what was originally recorded.

提交回复
热议问题