Author Topic: how do you interpret the raw data of a WAV file?  (Read 4636 times)

0 Members and 1 Guest are viewing this topic.

Offline engineheatTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: us
how do you interpret the raw data of a WAV file?
« on: January 09, 2019, 01:06:24 am »
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
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11905
  • Country: us
    • Personal site
Re: how do you interpret the raw data of a WAV file?
« Reply #1 on: January 09, 2019, 01:19:36 am »
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.
Alex
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8526
Re: how do you interpret the raw data of a WAV file?
« Reply #2 on: January 09, 2019, 02:51:24 am »
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?
Ultimately it's 20000 relative to the maximum input amplitude of the ADC that digitised the file.
 

Offline engineheatTopic starter

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: us
Re: how do you interpret the raw data of a WAV file?
« Reply #3 on: January 09, 2019, 05:40:17 am »
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
 

Online Psi

  • Super Contributor
  • ***
  • Posts: 10385
  • Country: nz
Re: how do you interpret the raw data of a WAV file?
« Reply #4 on: January 09, 2019, 05:46:48 am »
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.
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11905
  • Country: us
    • Personal site
Re: how do you interpret the raw data of a WAV file?
« Reply #5 on: January 09, 2019, 05:53:25 am »
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?
Yes. Multiplying all samples by the number is equivalent to turning a volume knob.
Alex
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22436
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: how do you interpret the raw data of a WAV file?
« Reply #6 on: January 09, 2019, 02:26:57 pm »
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
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline soldar

  • Super Contributor
  • ***
  • Posts: 3595
  • Country: es
Re: how do you interpret the raw data of a WAV file?
« Reply #7 on: January 09, 2019, 02:43:46 pm »
.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 see http://soundfile.sapp.org/doc/WaveFormat/
All my posts are made with 100% recycled electrons and bare traces of grey matter.
 
The following users thanked this post: tooki


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf