DSPRelated.com
Forums

Calculating sound amplitude in dB from a WAV file

Started by Unknown January 27, 2005
Hi everyone,

I suppose this is an easy question for some, but I'm trying to
calculate in dB, the amplitude of a recorded WAV sound file. Is this
possible? How can it be done? Are there any libraries/APIs that do
this?

Thanks,

- Olumide

Olumide,

> I'm trying to calculate in dB, the amplitude of a recorded WAV sound file.
Is this possible? < I'm afraid it's not possible to determine from a recording how loud the sound was when it was recorded originally. If this is not what you're asking, please clarify. --Ethan
On 27 Jan 2005 09:47:53 -0800, 50295@web.de wrote:

>Hi everyone, > >I suppose this is an easy question for some, but I'm trying to >calculate in dB, the amplitude of a recorded WAV sound file. Is this >possible? How can it be done? Are there any libraries/APIs that do >this?
You can compute the dynamic range or the peak-to-average-power ratio, but since most amps have volume controls I don't see how you can do much else. Dynamic range is just the log of the ratio of the max and min amplitudes and papr is the log of the ratio of the max amplitude and the average amplitude. Since dB values are logarithmic you need some sort of reference against which to make a ratio. Using the min amplitude or the average amplitude works reasonably well. Eric Jacobsen Minister of Algorithms, Intel Corp. My opinions may not be Intel's opinions. http://www.ericjacobsen.org
Alas it is. *Sigh* Thanks anyway

50295@web.de wrote:

> Hi everyone, > > I suppose this is an easy question for some, but I'm trying to > calculate in dB, the amplitude of a recorded WAV sound file. Is this > possible? How can it be done? Are there any libraries/APIs that do > this? > > Thanks, > > - Olumide >
assuming you want to maximum level found in the file, the simplest way is to scan for the largest absolute sample value (fraction of 1.0), and then calculate dB = 20 * log10(maxamp); For a 16bit soundfile, the dB will range from 0.0 (maximum) to ~ -90dB (amplitude of one lsb). As an easy example, if the maximum amplitude is 0.5, the level is approx -6dB. Rule of thumb: each successive halving of amplitude equates to a drop by 6dB. More sophisticated approaches will scan for rms or average level over some block length (say, 5msecs-worth). Assuming you are able to do C programming, all you need is a soundfile library such as libsndfile, and the rest is easy. Richard Dobson
50295@web.de wrote:
> > Hi everyone, > > I suppose this is an easy question for some, but I'm trying to > calculate in dB, the amplitude of a recorded WAV sound file. Is this > possible? How can it be done? Are there any libraries/APIs that do > this?
One measure that is useful is the the magnitude of the largest sample value in the file with respect to the maximum possible value. My library libsndfile http://www,mega-nerd.com/libsndfile/ comes with a small command line program called sndfile-info which performs the above calulcation and prints out somethng like this: Version : libsndfile-1.0.11 ======================================== File : Sound/WAV/drop01.wav Length : 378716 RIFF : 378708 WAVE fmt : 16 Format : 0x1 => WAVE_FORMAT_PCM Channels : 1 Sample Rate : 44100 Block Align : 2 Bit Width : 16 Bytes/sec : 88200 data : 378672 End ---------------------------------------- Sample Rate : 44100 Frames : 189336 Channels : 1 Format : 0x00010002 Sections : 1 Seekable : TRUE Duration : 00:00:04.293 Signal Max : 21188 (-3.79 dB) This is a standard 16 bit WAV WAV file. The largest sample value in the files is 21188 and the maximum possible value is 32767. 20*log10 (21188/32767) => -3.79dB HTH, Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo nospam@mega-nerd.com (Yes it's valid) +-----------------------------------------------------------+ "Windows was created to keep stupid people away from UNIX." -- Tom Christiansen
In article <8LidnVK9FtyAs2TcRVn-rg@giganews.com>,
Ethan Winer <ethanw at ethanwiner dot com> wrote:
>Olumide, > >> I'm trying to calculate in dB, the amplitude of a recorded WAV sound file. >Is this possible? < > >I'm afraid it's not possible to determine from a recording how loud the >sound was when it was recorded originally.
Is it possible with some sort of calibration sound file, and knowledge of if and/or how much the input amplification changed between files? If so, how would one go about recording a calibrated sound input? I seem to recall reading some childrens science book which had a table of the sound dB values of whispering, normal conversation, cars, trains, jet aircraft on takeoff, etc. So I might be tempted to take my sound recorder and travel about recording conversations, trains, airport noises, etc., either without changing the input volume or documenting the volume setting for each recording, and then compare the rms amplitude of those files to my unknown. IMHO. YMMV. -- Ron Nicholson rhn AT nicholson DOT com http://www.nicholson.com/rhn/ #include <canonical.disclaimer> // only my own opinions, etc.
"Ronald H. Nicholson Jr." <rhn@mauve.rahul.net> wrote in message
news:ctbl8j$feu$1@blue.rahul.net...
> In article <8LidnVK9FtyAs2TcRVn-rg@giganews.com>, > Ethan Winer <ethanw at ethanwiner dot com> wrote: > >Olumide, > > > >> I'm trying to calculate in dB, the amplitude of a recorded WAV sound file. > >Is this possible? < > > > >I'm afraid it's not possible to determine from a recording how loud the > >sound was when it was recorded originally. > > Is it possible with some sort of calibration sound file, and knowledge > of if and/or how much the input amplification changed between files?
With enough knowledge of _all_ the conditions, this would be possible.
> If so, how would one go about recording a calibrated sound input?
Calibrated microphone, calibrated gain, calibrated environment (echo/damping and noise would affect the result), calibrated microphone-to-source distance, calibrated recorder, etc.. Difficult, but not impossible.
> I seem to recall reading some childrens science book which had a table > of the sound dB values of whispering, normal conversation, cars, trains, > jet aircraft on takeoff, etc.
A very important parameter is the distance between the sound source and the microphone. I think 1m is a typical specification. You also need to make some assumptions about the recording environment--consider that a drum played in a small reflective room sounds louder than the same drum outside on a lawn due to reflections.
> So I might be tempted to take my sound > recorder and travel about recording conversations, trains, airport noises, > etc., either without changing the input volume or documenting the volume > setting for each recording, and then compare the rms amplitude of those > files to my unknown.
You would also want to document microphone-to-source distance as explained above.
"Jon Harris" <goldentully@hotmail.com> wrote in message 
news:35t81qF4r6eq0U1@individual.net...
> "Ronald H. Nicholson Jr." <rhn@mauve.rahul.net> wrote in message > news:ctbl8j$feu$1@blue.rahul.net... >> In article <8LidnVK9FtyAs2TcRVn-rg@giganews.com>, >> Ethan Winer <ethanw at ethanwiner dot com> wrote: >> >Olumide, >> > >> >> I'm trying to calculate in dB, the amplitude of a recorded WAV sound >> >> file. >> >Is this possible? < >> > >> >I'm afraid it's not possible to determine from a recording how loud the >> >sound was when it was recorded originally. >> >> Is it possible with some sort of calibration sound file, and knowledge >> of if and/or how much the input amplification changed between files? > > With enough knowledge of _all_ the conditions, this would be possible. > >> If so, how would one go about recording a calibrated sound input? > > Calibrated microphone, calibrated gain, calibrated environment > (echo/damping and > noise would affect the result), calibrated microphone-to-source distance, > calibrated recorder, etc.. Difficult, but not impossible. > >> I seem to recall reading some childrens science book which had a table >> of the sound dB values of whispering, normal conversation, cars, trains, >> jet aircraft on takeoff, etc. > > A very important parameter is the distance between the sound source and > the > microphone. I think 1m is a typical specification. You also need to make > some > assumptions about the recording environment--consider that a drum played > in a > small reflective room sounds louder than the same drum outside on a lawn > due to > reflections.
1m is a typical *reference* distance for the sound pressure measured. It isn't necessarily typical at all for the distance of the actual measurement. Example: Measure sound pressure level in free space (or reasonable facsimile thereof) at 10 meters distance from projector to receiver. Assume spherical spreading and correct the sound pressure level back to 1m using 20log(R1/R0) so 20dB where R1 is 10m and R0 is 1m. At least that's how I remember it..... Fred
50295@web.de wrote:
> I suppose this is an easy question for some, but I'm trying to > calculate in dB, the amplitude of a recorded WAV sound file. Is this > possible? How can it be done? Are there any libraries/APIs that do > this?
You need to know the sensitivity of the microphone in millivolts per pascal, and the sesitivity od the sound board in amplitude uits per volt. Else, you need to have placed the output tone of a calibrator onto that or accompanying .WAV file, and the board purveyance has to be linear (NO AGC, clipping or compressing). Lots of luck! Angelo Campanella