views:

1090

answers:

2

The digital sound is playing using DirectSound device. It is necessary to display sound activity in decibels - like analog devices do.

What is the right way to calculate sound pressure from the WAVE PCM data (44100hz,16bit)?

+2  A: 

if you just need an "idea" of the sound pressure, you can simply compute the log-energy on some time franmes of the signal: split the signal every N samples, compute 10*log(sum(xn**2)) where x are the N samples, and you get a value in the dB domain. If you need to precisely display a measure (that is your 0 dB matches say a mixtable 0dB), it is a bit more complicated.

See here for more details:

http://music.columbia.edu/pipermail/music-dsp/2002-April/048341.html

David Cournapeau
I'm really looking for the complicated way.
LicenseQ
First, dB is not a unit stricly speaking, but a level - you need a reference. So we need more information. For wav files encoding in signed integers of 16 bits, the maximum is 32767, so you can compute the dB with 20log(abs(amplitude)/32767).
David Cournapeau
I added a link with much more details + explanation
David Cournapeau
It looks like answer will be average{10*log((sample[n] / 32768)**2)}?
LicenseQ
20log(x) = 10log(x**2), and it is 32767 because 16 bits encoding is usually between -32768 and 32767 (I am not 100 % sure, though, I don't have a reference in handy). The latter difference is pedantic, though, as it won't change much your result.
David Cournapeau
A: 

Sound pressure is a measure of force per unit area. To determine this you would have to have information about the speaker(s) on which the audio is played. You can obtain a decibel level with respect to an arbitrary reference (as opposed to the threshold of hearing) with the algorithm proposed by cournape.

Calculate the average signal power over a time interval, compute the base-10 logarithm and multiply by 19. The average power is calculated by averaging the the square of each sample over the interval. Note that positive and negative values are necessary (i.e. it must be an AC signal). So, make sure the PCM values are either floating-point, 2's complement or offset unsigned values accordingly.

Also, by applying Parseval's theorum and the Fourier transform you can also generate signal levels for different frequency bands.

Judge Maygarden