ivãstival

ESP32 · 03-audio

Architecture: Decibels, From Scratch

Note: This document was generated by an AI agent.

Overview

Every audio document in this section quotes numbers like -44 dBV/Pa, -60 dBFS, or +18.1 dB, and converts between them with lines such as

44 / 20       = 2.2
10^2.2        ≈ 158
1 V / 158     ≈ 0.0063 V
              = 6.3 mV/Pa

That is four lines of arithmetic with no explanation attached, and it is the single thing most likely to stop a reader who has not met decibels before. This document exists so that the rest of the section can keep being terse. It assumes no prior knowledge: no signal processing, no electronics, and no maths beyond multiplication and division.

Read it once and the four lines above become obvious. Then go to Voice hardware, where they are used.


A decibel is a comparison, never a quantity

This is the first and most important idea, and getting it wrong causes every other confusion.

A decibel measures how many times bigger one thing is than another. It is a ratio dressed up in different clothing. "50 dB" on its own is as meaningless as "three times" on its own — three times what?

So a decibel figure is only complete when the reference is attached, and that is what the letters after dB are for:

UnitCompared againstUsed for
dBwhatever the sentence saysa change: "the gain adds 18 dB"
dBV1 voltan electrical signal's size
dBFSthe largest number the format can holda digital sample's level
dB SPL0.00002 Pa, near the quietest audible soundloudness in the air

A positive value means bigger than the reference. A negative value means smaller than the reference. Zero means exactly the reference — which is why 0 dBFS is a digital signal at maximum, not a silent one.


Why anyone would do this

Hearing spans an absurd range. The quietest sound a person can detect and a sound loud enough to hurt differ by a factor of roughly ten million in pressure. Writing that range in plain units is unpleasant:

0.00002 Pa    threshold of hearing
0.02    Pa    ordinary speech at one metre
20      Pa    painfully loud

Three numbers, and already the zeros are hard to count. The same three on a decibel scale:

0   dB SPL
60  dB SPL
120 dB SPL

The trick that flattens those millions into a range of 0 to 120 is the logarithm.

The logarithm, in one paragraph

log₁₀(n) answers one question: how many times do I multiply 10 by itself to get n? So log₁₀(100) = 2, because 10 × 10 = 100. And log₁₀(1000) = 3. Values in between come out as decimals: log₁₀(158) ≈ 2.2, because 158 sits between 100 and 1000, nearer the low end.

Its opposite, 10^x, undoes it: 10^2 = 100, 10^2.2 ≈ 158. Both are one button on a calculator, and the section below only needs the second one.

The useful property is that a logarithm turns multiplying into adding. Two stages that each make a signal 10 times bigger make it 100 times bigger together — but on a decibel scale that is 20 dB + 20 dB = 40 dB. Chains of gain become sums, which is why engineers put up with the extra vocabulary.


The two formulas

To turn a ratio into decibels, for a signal you measure as an amplitude — a voltage, a pressure, a sample value:

dB = 20 · log₁₀(bigger / smaller)

To go the other way, from decibels back to a plain ratio:

ratio = 10^(dB / 20)

These are the same statement read in opposite directions. The second one is the one the opening snippet uses.

Why 20 and not 10

The decibel was originally defined for power — watts — where the factor is 10:

dB = 10 · log₁₀(power ratio)

But power grows as the square of amplitude: double the voltage across a fixed resistance and you get four times the power. Squaring inside a logarithm is the same as multiplying outside it, so 10 · on a squared quantity becomes 20 · on the unsquared one. Both formulas describe the same physical change; which one you use depends only on whether the number in your hand is a power or an amplitude.

Almost everything in this project — sample values, voltages, pressures — is an amplitude, so 20 is the normal factor here.

Four anchors worth memorising

RatioDecibels
×10 dB
×26 dB
×1020 dB
×100060 dB

And their mirror images: ÷2 is −6 dB, ÷10 is −20 dB. With these, most figures in this section can be read without a calculator. A gain setting of 8 is 2 × 2 × 2, so 6 + 6 + 6 = 18 dB — which is exactly where +18.1 dB in Making the agent audible comes from.


What dBV/Pa means

Now the specific unit in the opening snippet, which is a slightly different animal from the ones in the table above.

Microphone datasheets quote sensitivity: how much electrical signal the microphone produces for a given amount of sound pressure pushing on it. That is a rate, not a level, and the /Pa is doing the same work as the /h in km/h — "per pascal".

So -44 dBV/Pa unpacks as:

  • Pa — the pascal, the unit of pressure. One pascal of sound is quite loud; ordinary speech at a metre is about 0.02 Pa.
  • dBV — a voltage compared against 1 volt.
  • −44 — that voltage is 44 dB below 1 volt, so much smaller than a volt.

Read as a sentence: push one pascal of sound onto this microphone and it produces a voltage 44 dB below one volt.

That sentence is useless for circuit design until "44 dB below one volt" becomes a number of millivolts. Which is what the four lines do.


The four lines, one at a time

44 / 20       = 2.2
10^2.2        ≈ 158
1 V / 158     ≈ 0.0063 V
              = 6.3 mV/Pa

Line 1 — 44 / 20 = 2.2. This is ratio = 10^(dB / 20) starting its work: divide the decibel figure by 20 to get the exponent. The minus sign is dropped on purpose and dealt with in line 3, because "44 dB smaller" is easier to handle as a division than as a negative power.

Line 2 — 10^2.2 ≈ 158. Raising 10 to that exponent finishes the conversion. The answer, 158, is the plain ratio: 44 dB is a factor of about 158. Sanity-check it against the anchors — 40 dB would be exactly 100, and 46 dB would be 200, so a number between them near the low end is right.

Line 3 — 1 V / 158 ≈ 0.0063 V. Here the minus sign returns. The reference for dBV is 1 volt, and the signal is 158 times smaller than the reference, so divide rather than multiply. Had the figure been +44 dBV, this line would read 1 V × 158 = 158 V.

Line 4 — = 6.3 mV/Pa. Pure unit tidying: 0.0063 volts is 6.3 millivolts, because a millivolt is a thousandth of a volt. The /Pa carries through untouched from the original unit — nothing in the arithmetic touched the pressure side.

Checking it backwards

A conversion is worth trusting only if it survives the return trip. Take 6.3 mV and go back to decibels with dB = 20 · log₁₀(bigger / smaller):

0.0063 V / 1 V = 0.0063
log₁₀(0.0063)  ≈ −2.2
20 × −2.2      = −44 dBV

The original figure, minus sign and all. The negative appears naturally this time, because dividing a small number by a larger one gives a value below 1, and logarithms of values below 1 are negative.


Using the answer

A sensitivity in millivolts per pascal is only interesting once it is multiplied by a real sound. Ordinary speech a metre away is about 0.02 Pa:

0.02 Pa × 6.3 mV/Pa ≈ 0.13 mV

The units cancel the way they do in any other rate calculation — pascals against per-pascal — leaving millivolts. Move closer, the pressure rises, and so does the output:

speaking at one metre      0.02  Pa  →  0.13 mV
speaking at about 30 cm    0.066 Pa  →  0.42 mV

Those are the numbers Voice hardware compares against the ESP32's analogue-to-digital converter, whose finest step is about 0.8 mV. A signal of 0.42 mV does not fill even one step. That comparison is the entire argument for using a digital microphone, and it cannot be made at all until -44 dBV/Pa has been turned into millivolts.


The same idea in the other units

Once the pattern is clear, every other decibel figure in this section is the same two formulas with a different reference substituted.

dBFS — digital samples. The reference is the largest value the format can represent, which for 16-bit audio is 32,768:

dBFS = 20 · log₁₀(|sample| / 32768)

A sample of 33 is therefore about −60 dBFS. Because nothing can exceed full scale, dBFS values are negative and 0 dBFS is a ceiling rather than a target. Making the agent audible depends on that fact.

dB SPL — loudness in air. The reference is 0.00002 Pa, roughly the quietest sound a person can hear. Speech at 0.02 Pa is a thousand times that, and ×1000 is 60 dB, so ordinary speech is about 60 dB SPL — one of the anchors from the table, used directly.

Plain dB — a change. When no reference is attached, the figure describes a change rather than a level, and the reference is implicitly "what it was before". +8.9 dB of makeup gain means the signal came out about 2.8 times larger than it went in.


Mistakes worth avoiding

MistakeWhat goes wrong
Using 10 · log₁₀ on a voltage or a sampleEvery answer comes out half the size it should be
Reading 0 dBFS as silenceIt is the maximum; silence has no dBFS value at all
Adding decibels of different references-44 dBV and -60 dBFS describe different things and cannot be summed
Multiplying when the figure is negativeA negative decibel means divide, as line 3 above does
Quoting a bare "dB" as a levelWithout a reference it states a change and nothing more

Where this is used

DocumentThe decibels in it
Voice hardwareMicrophone sensitivity in dBV/Pa, and why a bare capsule cannot reach the ADC
I2S audio runtimeSample widths, and what the bits below the noise floor are worth
Making the agent audibledBFS, peak against RMS, crest factor, and the compressor's makeup gain
Audio diagnosticsThe capture gain setting, and the browser's dBFS meter