mp-units/HEAD/blog/2026/07/24/introducing-logarithmic-quantities-and-units/ #827
Replies: 2 comments 3 replies
|
Context about myself: I am an audio software developer working heavily on acoustic measurements, so I deal with all kinds of decibels daily. I have a strong preference for MATLAB and Python. C++ is my fifth language by usage, so please read my comments from that perspective. 1. The first code example in the article is not idealLooking at your opening example, it is hard for me to get the point, because it is hard to understand what the purpose of such a line of code would be: auto half_voltage = (0.5 * V) * (6.0 * dB).linear();It requires guesswork about what is happening under the hood. This pair would make the point faster: auto my_power = (0.5 * W) * (6.0 * dB).linear(); // 0.5 W * 4 ≈ 2 W, RIGHT
auto my_voltage = (0.5 * V) * (6.0 * dB).linear(); // 0.5 V * 4 ≈ 2 V, WRONGThe same expression, the same auto my_power = ((0.5 * W).log_in(dBW) + 6.0 * dB).linear(); // 0.5 W * 4 ≈ 2 W, RIGHT
auto my_voltage = ((0.5 * V).log_in(dBV) + 6.0 * dB).linear(); // 0.5 V * 2 = 1 V, RIGHTIf this is not how it works right now, then I suggest resolving the gain's domain at the point of application. 2. Summing two levels: right decision, wrong rationale text
"Linearize to combine" is misleading and I would change it. If linearizing were all that is needed to combine, why would it not simply be handled in the background for the user? It is not, because linearizing and summing is only correct for uncorrelated sources. In my opinion this should remain a compile-time error. But something like "combining levels depends on correlation and phase, which are not recoverable from the levels alone" is the accurate statement, and it is a stronger argument for ill-formed than the current wording: it says the operation is underdetermined, not merely inconvenient. 3. dBFS is barely specifiedThe article never says which full-scale convention is meant - peak sine versus full-scale square wave (the 3.01 dB AES17 offset), nor peak versus RMS. Given your own rule that each distinct reference needs its own unit symbol, this arguably needs Personally I do not like the AES17 convention, but it is the one most used in the industry. There is also the concept of dBov as a separate unit alongside dBFS, precisely to be explicit about the full-scale convention. See the "RMS levels" section of https://en.wikipedia.org/wiki/DBFS. 4. Sensitivity looks like a first-class kindIn my work it is critical to be able to define multiple sensitivity units and to chain them to calculate values:
Direction matters, and it matters differently depending on whether we are talking about microphones or speakers, inputs or outputs, and so on. The whole thing looks great! |
|
I'm excited to read this article --- looks like amazing progress on a sorely needed issue! I'm only partway through so far and I think I'll have to finish it later. I'm looking forward to digesting this and getting dB support added to Au in an upcoming (although definitely post-0.6.0! 😅) release. I've already seen that you tackle power vs. root power head on, which is very encouraging. I did want to let you know that the nholthaus unit test example doesn't seem entirely fair. It's from the archived 2.x branch of the library. The main branch is now for the 3.x series, and although I could be mistaken, I believe @nholthaus had already fixed the specific issue in the example. It seems most likely to me that the mistake was entirely innocent. The 3.x branch cutover was just a few weeks ago. Au recently had to update our alternatives guide in response to this change, and to the amazing flurry of other changes (a 100+ issue backlog, completely cleared in a matter of days!). So I assume you simply wrote most of this article (including that part of it) a while back, and finished it later, without realizing that the example had become obsolete by the time it was published. Anyway, just wanted to let you know. Excited to read the rest of the article! Not sure when I can finish it, but it looks impressively thoughtful and comprehensive. |
Uh oh!
There was an error while loading. Please reload this page.
mp-units/HEAD/blog/2026/07/24/introducing-logarithmic-quantities-and-units/
The quantities and units library for C++
https://mpusz.github.io/mp-units/HEAD/blog/2026/07/24/introducing-logarithmic-quantities-and-units/
All reactions