Calculating the dB scale in Audacity

Audacity 3.1.3

Hello, I am trying to understand how the spectragrams are calculated in Audacity. If I knew which library folder to look in, with the source code, it might help. I want to replicate the same graph with Python to prove to myself that I understand the plots and where they come from.

Normally dB is calculated as follows:

dB = 20 log_10 (a1/a2), where a1 is the signal and a2 is some reference signal.

For example, the threshold of human hearing at 1 kHz, is 0 dB sound pressure level (spl), is relative to reference sound pressure 20 microPascals.

94 dB_spl = 20 log(1Pa/(20 micro Pa))

Therefore 94dB spl is equivalent to 1 Pa.

In the case of audacity default settings show linear scale, gain of 20 dB, Range of 80 DB, window size = 1024 point FFT (say of a 44,100Hz signal).
according to: https://manual.audacityteam.org/man/spectrogram_view.html#:~:text=It%20consists%20of%2010%20segments,view%2C%20using%20the%20default%20settings

I might expect that our calculation would look like this, FFT:

dB = 20 log_10 (100 x digital FFT signal/some reference)

The factor of 100, is because an increase in signal is equivalent to 20dB gain.

No clue what the some reference used is. Does anybody know what a2 is used as a reference?

Thank you!
Rob

I don’t understand your question but with digital, the reference is the “digital maximum” of 0dBFS = zero decibels full scale. That’s as high as you can count with 16 or 24 bits etc., or 0dBFS is 1.0 in floating-point. 16-bit WAV files can hold numbers between −32,768 and +32,767, and if your positive & negative peaks hit those numbers your peaks are hitting 0dB. And of course silence is a series of zero.

So digital dB levels are always negative except for floating-point where for all practical purposes there is no maximum (or minimum). Audacity uses floating-point internally.

DSP is normally done in floating point and you’ll probably want to do the same in Python.

When you record or play (or open in Audacity) everything is automatically scaled so a 24-bit file isn’t “louder” than an 8-bit file.

There is no calibration between dBFS and dB SPL but there is a correlation (if you don’t touch the volume control, etc.) i.e. A 10dB drop in the digital level makes a 10dB drop in SPL.

You can compile Audacity from source codes in order to include some effects packages. That may help. Read down through this posting.

https://forum.audacityteam.org/t/building-audacity-3-0-3-with-asio-on-windows/62311/1

Koz

I am trying to understand how the spectragrams are calculated in Audacity.

Is there a real-world goal or job? Sometimes someone will post a dry, theoretical question when they really wanted was enough info to do a recording job.

Also, do you really want the spectrogram code? I think staring at the colored bands is nice, but for real sound analysis, Analyze > Plot Spectrum can give you a lot more detailed information.

Koz

It’s the same as for “Plot Spectrum”. The 0 dB reference is a full scale sine wave.


As an example, this is a screenshot of a 4kHz sine wave fading in from -inf dB to 0 dBFS. (Spectrogram settings chosen for demonstration purposes).