Repository navigation
P1K: measured native MASTER 48k LUFS-I and 4x intersample dBTP #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
masarray
merged 9 commits into
main
from
feature/p1k-native-measured-lufs-dbtp-20261029
Oct 29, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6542cfb
P1K: bounded RT-safe 48k stereo K-weighted gated LUFS and 4x FIR true…
masarray da45b97
fix: reset exact reference biquad states; initialize immutable histog…
masarray fe25bb5
P1K: bind true native 48k MASTER PCM analysis to DIRECT and dry 10CH …
masarray bb2d05c
test: native measured stereo 997Hz LUFS and 12k intersample 4x true p…
masarray 768ded4
P1K: add direct stereo loudness and true-peak golden vectors to canon…
masarray 22ba2ea
P1K: add direct stereo loudness and true-peak golden vectors to canon…
masarray 5a8239f
P1K UI: render provenance-tagged real native LUFS and dBTP with corre…
masarray fb81383
test: validate measured LUFS/dBTP native provenance, no invented prev…
masarray fdfc794
docs: native real loudness/truepeak provenance, scope, accuracy and h…
masarray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # P1K — Native measured 48 kHz MASTER LUFS-I and dBTP (2026-10-29) | ||
|
|
||
| **Scope:** Native JUCE DIRECT output, 48 kHz and first two physical output channels only. This PR does not certify all device/rate modes or crackle-free physical audio. | ||
|
|
||
| ## Native signal authority | ||
| - Analysis reads **real hardware-bound MASTER PCM after fader, MUTE, routing, FX and ramp**, both from the existing CH1 path and the approved 10CH DRY Routing LAB. It never reads the browser preview meter or substitutes sample-peak telemetry for true peak. | ||
| - `engine/dsp/NativeMasterLoudness.h`: two reference 48-kHz ITU-R BS.1770 K-weight biquads, 400ms/75%-overlap blocks, -70 LUFS absolute gate and -10 LU relative gate; fixed 0.1 LU histogram quantization (maximum nominal 0.05 LU quantization). | ||
| - Native dBTP is measured from 4x interpolated audio via 32-tap Blackman-windowed sinc polyphase FIR, with DC normalization and an absolute maximum since device epoch. Intersample peaks are detected separately from the existing sample peak display. | ||
| - Always initialized **before** audio callbacks. `process()` has fixed-capacity buffers, no locks/allocations/VST/window/file/OS operations. Callback storage is O(samples) with bounded FIR work. Message-thread `read()` publishes provenance-tagged fields at the existing 12Hz status cadence; 10CH + AUX DSP topology and FX/Orbit callbacks remain unchanged. | ||
| - LUFS-I starts only after at least 400ms of valid above-gate signal; offline, silence, disconnected, and unqualified sample rate display **—**, not made-up numbers. dBTP holds maximum observed since current device start. | ||
| - Real JS WebView2 receives `masterAnalysisProvenance="MEASURED_48K_BS1770_K_4X_FIR"` and finite `masterLufs`/`masterDbtp`; the compact two-row black LCD displays numbers in bright green, changing to red only for LUFS-I above −12 or dBTP above −1. Browser standalone keeps its clearly simulated demo. | ||
|
|
||
| ## Limitations/gates | ||
| - INTENTIONALLY unsupported: 44.1/88.2/96/192k until recalibrated K weighting and oversample spectral acceptance; independent WASAPI dual-clock output not yet instrumented (cannot silently reuse the DIRECT capture callback); output multichannel >2 not qualified. When unsupported, native LCD remains unavailable. | ||
| - Loudness histogram is fixed-memory and approximates exact floating-point gated block list by 0.1 LU. Compare against known ITU vectors, silence, stereo vs mono and live pro tooling before asserting broadcast certification. | ||
| - 32-tap 4x Blackman sinc should be compared against a verified Annex 2 / EBU Tech 3341 true-peak reference with intersample worst cases and high-frequency attenuation. The implementation is *measured* and useful, but no claim of formal IEC/ITU certification or guaranteed 0.0 dB numerical agreement. | ||
| - Windows CTest covers 997 Hz −20 dBFS stereo reference, 12 kHz phase-shifted intersample overshoot, unsupported rate, silence, reset. Need CPU callback p95, 44.1/48/96 sample-rate hardware FAT and profile on an onboard GPU Windows PC before expanded production support. | ||
| - Master UI does **not** change meter LEDs, fader, Plugin Catalog, VST3 lifecycle, routing, Orbit, CI matrix, or #15 crackle closure. | ||
|
|
||
| References: [ITU-R BS.1770-5](https://www.itu.int/rec/R-REC-BS.1770-5-202311-I). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-only | ||
| #pragma once | ||
| #include <array> | ||
| #include <algorithm> | ||
| #include <atomic> | ||
| #include <cmath> | ||
| #include <cstdint> | ||
| #include <limits> | ||
|
|
||
| // P1K v1: 48kHz DIRECT output ONLY, 1/2 PCM output channels. | ||
| // 48k coefficients below are from ITU-R BS.1770's exact reference tables. | ||
| // 400ms overlapping gated windows (100ms hop). Histogram quantization <=0.05 LU. | ||
| // 4x windowed-sinc oversampling for intersample peak (not linear sample peak). | ||
| // | ||
| // No locks, allocations, device/OS/UI calls in process(). All expensive | ||
| // preparation occurs before audioDeviceAboutToStart() returns. | ||
| // A second renderer/clock is intentionally NOT supported until bound to its | ||
| // own output stream and verified device epoch. | ||
| namespace armix::dsp { | ||
| class NativeMasterLoudness final { | ||
| public: | ||
| NativeMasterLoudness() noexcept | ||
| { | ||
| for(int i=0;i<bins;++i) | ||
| binEnergy_[i]=std::pow(10.0,(-70.0+(i+0.5)*0.1+0.691)/10.0); | ||
| } | ||
| struct Reading { | ||
| bool supported=false, integratedValid=false, truePeakValid=false; | ||
| double integratedLufs=0.0, dbtp=0.0; | ||
| std::uint64_t gatedWindows=0; | ||
| }; | ||
| static constexpr int taps=32; | ||
| static constexpr int phases=4; | ||
| static constexpr int bins=801; | ||
| static constexpr int quarterFrames=4800; // exact 100ms at 48k | ||
|
|
||
| void prepare (double rate) noexcept | ||
| { | ||
| enabled_.store (false,std::memory_order_release); | ||
| for(auto& band:hist_)band.store(0,std::memory_order_relaxed); | ||
| peak_.store(0.f,std::memory_order_relaxed); | ||
| framesProcessed_.store(0,std::memory_order_relaxed); | ||
| quarterEnergy_.fill(0.0); | ||
| for(auto& ch:history_)ch.fill(0.0f); | ||
| for(auto& f:pre_)f.z1=f.z2=0.0; | ||
| for(auto& f:rlb_)f.z1=f.z2=0.0; | ||
| quarterOffset_=quarterSlot_=completeQuarters_=writeAt_=0; | ||
| if(std::abs(rate-48000.0)>0.5)return; // NEVER invent LUFS at other rates | ||
| constexpr double pi=3.1415926535897932384626433832795; | ||
| for(int phase=0;phase<phases;++phase) { | ||
| double norm=0.0; | ||
| for(int k=0;k<taps;++k) { | ||
| const double t=k-15.0-phase/4.0; | ||
| const double s=std::abs(t)<1e-12?1.0:std::sin(pi*t)/(pi*t); | ||
| const double w=0.42-0.5*std::cos(2*pi*k/(taps-1)) | ||
| +0.08*std::cos(4*pi*k/(taps-1)); | ||
| coeff_[phase][k]=s*w; | ||
| norm+=coeff_[phase][k]; | ||
| } | ||
| for(auto& x:coeff_[phase])x/=norm; // unit DC gain | ||
| } | ||
| enabled_.store(true,std::memory_order_release); | ||
| } | ||
|
|
||
| void process(const float* const* output,int numChannels,int frames) noexcept | ||
| { | ||
| if(!enabled_.load(std::memory_order_relaxed)||!output||numChannels<1||frames<=0) | ||
| return; | ||
| const int count=numChannels>=2?2:1; | ||
| float blockPeak=0.f; | ||
| for(int i=0;i<frames;++i) { | ||
| double energy=0.0; | ||
| for(int c=0;c<count;++c) { | ||
| const float* src=output[c]; | ||
| const float x=src&&std::isfinite(src[i])?src[i]:0.f; | ||
| double y=pre_[c].step(x); | ||
| y=rlb_[c].step(y); | ||
| energy+=y*y; | ||
| history_[c][writeAt_]=x; | ||
| for(int p=0;p<phases;++p) { | ||
| double v=0.0; | ||
| for(int k=0;k<taps;++k) | ||
| v+=coeff_[p][k]*history_[c][(writeAt_+1+k)&(taps-1)]; | ||
| blockPeak=std::max(blockPeak,static_cast<float>(std::abs(v))); | ||
| } | ||
| } | ||
| writeAt_=(writeAt_+1)&(taps-1); | ||
| quarterEnergy_[quarterSlot_]+=energy; | ||
| if(++quarterOffset_==quarterFrames) { | ||
| quarterOffset_=0; | ||
| ++completeQuarters_; | ||
| quarterSlot_=(quarterSlot_+1)&3; | ||
| if(completeQuarters_>=4) { | ||
| double window=0.0; | ||
| for(const double sum:quarterEnergy_) window+=sum; | ||
| window/=4.0*quarterFrames; | ||
| if(window>0.0) { | ||
| const double loudness=-0.691+10.0*std::log10(window); | ||
| if(loudness>-70.0) { | ||
| const int idx=static_cast<int>(std::floor((loudness+70.0)*10.0)); | ||
| hist_[idx<0?0:idx>=bins?bins-1:idx].fetch_add( | ||
| 1,std::memory_order_relaxed); | ||
| } | ||
| } | ||
| } | ||
| quarterEnergy_[quarterSlot_]=0.0; | ||
| } | ||
| } | ||
| float old=peak_.load(std::memory_order_relaxed); | ||
| while(old<blockPeak&&!peak_.compare_exchange_weak( | ||
| old,blockPeak,std::memory_order_relaxed)){} | ||
| framesProcessed_.fetch_add(static_cast<std::uint64_t>(frames),std::memory_order_relaxed); | ||
| } | ||
|
|
||
| Reading read() const noexcept | ||
| { | ||
| Reading out; | ||
| out.supported=enabled_.load(std::memory_order_acquire); | ||
| if(!out.supported)return out; | ||
| const float pk=peak_.load(std::memory_order_relaxed); | ||
| out.truePeakValid=framesProcessed_.load(std::memory_order_relaxed)>=quarterFrames && pk>0.f; | ||
| if(out.truePeakValid)out.dbtp=20.0*std::log10(static_cast<double>(pk)); | ||
| double absoluteSum=0.0, count=0.0; | ||
| for(int i=0;i<bins;++i) { | ||
| const auto n=hist_[i].load(std::memory_order_relaxed); | ||
| absoluteSum+=binEnergy_[i]*n; | ||
| count+=n; | ||
| } | ||
| if(count<1.0)return out; | ||
| const double relative=-0.691+10.0*std::log10(absoluteSum/count)-10.0; | ||
| double gatedEnergy=0.0,gatedCount=0.0; | ||
| for(int i=0;i<bins;++i) { | ||
| const double loudness=-70.0+(i+0.5)*0.1; | ||
| if(loudness<=relative)continue; | ||
| const auto n=hist_[i].load(std::memory_order_relaxed); | ||
| gatedEnergy+=binEnergy_[i]*n; | ||
| gatedCount+=n; | ||
| } | ||
| if(gatedCount>=1.0) { | ||
| out.integratedLufs=-0.691+10.0*std::log10(gatedEnergy/gatedCount); | ||
| out.integratedValid=std::isfinite(out.integratedLufs); | ||
| out.gatedWindows=static_cast<std::uint64_t>(gatedCount); | ||
| } | ||
| if(!enabled_.load(std::memory_order_acquire))return {}; | ||
| return out; | ||
| } | ||
| private: | ||
| struct Biquad { | ||
| // Transposed DF-II states, double precision, zero allocation. | ||
| double z1=0,z2=0; | ||
| double b0=1,b1=0,b2=0,a1=0,a2=0; | ||
| double step(double x) noexcept { | ||
| const double y=b0*x+z1; | ||
| z1=b1*x-a1*y+z2; | ||
| z2=b2*x-a2*y; | ||
| return y; | ||
| } | ||
| }; | ||
| // Exact 48kHz coefficient sets specified in BS.1770 annex 1. | ||
| std::array<Biquad,2> pre_{{ | ||
| {0,0,1.53512485958697,-2.69169618940638,1.19839281085285,-1.69065929318241,0.73248077421585}, | ||
| {0,0,1.53512485958697,-2.69169618940638,1.19839281085285,-1.69065929318241,0.73248077421585} | ||
| }}; | ||
| std::array<Biquad,2> rlb_{{ | ||
| {0,0,1.,-2.,1.,-1.99004745483398,0.99007225036621}, | ||
| {0,0,1.,-2.,1.,-1.99004745483398,0.99007225036621} | ||
| }}; | ||
| std::array<std::array<float,taps>,2> history_{}; | ||
| std::array<std::array<double,taps>,phases> coeff_{}; | ||
| std::array<double,bins> binEnergy_{}; | ||
| std::array<double,4> quarterEnergy_{}; | ||
| std::array<std::atomic<std::uint32_t>,bins> hist_{}; | ||
| std::atomic<float> peak_{0.f}; | ||
| std::atomic<std::uint64_t> framesProcessed_{0}; | ||
| std::atomic<bool> enabled_{false}; | ||
| int writeAt_=0,quarterOffset_=0,quarterSlot_=0,completeQuarters_=0; | ||
| }; | ||
| } // namespace armix::dsp | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When audio becomes silent after a nonzero signal and the callback thread has flush-to-zero disabled, these recursive filter states decay into subnormal doubles and continue doing expensive subnormal arithmetic throughout silence. Neither
process()nor the callingLiveAudioEnginecallback establishes a denormal guard. An optimized standalone reproduction using an impulse followed by silence took approximately 40–51 ms per second of processed audio, versus 16 ms with FTZ/DAZ enabled. Because this meter now runs on every supported DIRECT callback, this unnecessarily consumes realtime processing headroom even while output is muted. Add a scoped denormal guard or explicitly flush sufficiently small filter states to zero, and cover signal-to-silence transitions in the tests.Useful? React with 👍 / 👎.