how do you interpret the raw data of a WAV file? - Page 1
Forum section: electronics / beginners

author: engineheat
author_rank: Frequent Contributor
timestamp: January 09, 2019, 01:06:24 am
content: I'm trying to do some signal processing on a WAV file. The data is just an array of integers, with some as high as 20000. I believe each data point is 16 bit and I get the concept of bit depth.But I still struggle to understand the "unit" of that amplitude. I get that amplitude is a measure of the intensity of the sound and that sound is a pressure wave. Is it 20000 what?Is this number arbitrary? What if I halved all the data by multiplying by 0.5, I frequency spectrum will be the same but the magnitude at the frequencies will be halved as well. Will the sound be half as loud then?Thanks

author: ataradov
author_rank: Super Contributor
timestamp: January 09, 2019, 01:19:36 am
content: It is exactly like you described. It will have half the amplitude, but the spectrum will remain the same. With 16 bits you should see numbers in the range -23768 - 32767.

author: amyk
author_rank: Super Contributor
timestamp: January 09, 2019, 02:51:24 am
content: Quote from: engineheat on January 09, 2019, 01:06:24 amUltimately it's 20000 relative to the maximum input amplitude of the ADC that digitised the file.

author: engineheat
author_rank: Frequent Contributor
timestamp: January 09, 2019, 05:40:17 am
content: So the magnitude of those numbers depends on a DAC, and are unit-less. And for the same DAC, a louder sound will result in greater magnitude, but the "sound" itself is defined by the frequency profile. Is this a way to understand it?I wonder what will happen if I generate a single sine wave of an audible freq like 5khz, convert it to a WAV file and play it on my computer. I will experiment with this but I'd like to know what to expect now. Maybe playing around with a simple sine wave and listening to the effect will make things clear.thanks

author: Psi
author_rank: Super Contributor
timestamp: January 09, 2019, 05:46:48 am
content: When i was doing this i used cooledit to make a WAV file of silence.Then i zoomed all the way in and edited a few individual samples. Some up to max, some down to max etc..Then i used a hex editor to see what was happening in the data and look for the patterns.It really helped to understand the formatting.

author: ataradov
author_rank: Super Contributor
timestamp: January 09, 2019, 05:53:25 am
content: Quote from: engineheat on January 09, 2019, 05:40:17 amYes. Multiplying all samples by the number is equivalent to turning a volume knob.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: January 09, 2019, 02:26:57 pm
content: Better to think of it as dimensionless. It is just a virtual value, a digital number, until it touches the outside world.Well, it was once touching the outside world -- if it was recorded -- but without knowing the calibration of that microphone, that's pretty much useless.For almost all purposes, just appreciate that the components that make up, say, a song, are layered in just the right amount to sound good. The frequency response, reverb, distortion, volume, compression, stereo balance and phase, etc. are all adjusted in mastering.So, who knows about calibration, in most cases.Once it leaves the sound card's DAC, however, it becomes referenced to a real unit of measure. The reference voltage of that DAC is one unit, and the value the DAC is set to, is some fraction of that unit. That gives us a reasonable calibration point to reason with.It may also help to understand fixed point. When you write out a number 1234.5678, the 1234 part is the integer part, and the 0.5678 is the fractional part. We can compose such a number by starting with an integer (12345678), and shifting it right (shifting the decimal left), which is equivalent to multiplying or dividing by (base)^(shifts), in this case 10^4.In the same way, we can store a binary number as raw packed bits (in this case, 16-bit words), and read them as any representation we like. In particular, if we read them as all-fractional (a 0.16 fixed point format), then we also have the representation used by the DAC -- a fraction of the total VREF.By the way, if you're familiar with U.S. customary length measurements (inches and fractions), you already know binary fractions. For each 1 in the fraction, move to the next tick mark on the ruler, where the height of the mark corresponds to the position of the digit. So, 0.111b means, take 1/2, and 1/4, and 1/8 = 7/8 total. 0.1b is 1/2, 0.101 is 1/8 more than 1/2 = 5/8, etc.Every so often, someone who grew up with Good Old Boys (aka rednecks) then learned a computer trade, realizes Bubba invented this system independently, by -- instead of calling out the total fraction, because that's hard, who wants to add and reduce fractions? -- just calling out the number of tick marks from biggest to smallest.Or to put it still another way -- take the count (-20k to +20k or so), and divide by 32768. Reduce the fraction if you like, but suffice it to say, it's the long-hand way for the same method and answer.Tim

author: soldar
author_rank: Super Contributor
timestamp: January 09, 2019, 02:43:46 pm
content: .WAV is a container which can contain straight uncompressed PCM in different channels and bit rates as well as compressed data with MP3 or other codecs.For basic raw PCM seehttp://soundfile.sapp.org/doc/WaveFormat/