Repository navigation
Stage 3c: instruments over span<const Sample>, C ABI and notebook for the four FFT profiles - #30
Conversation
…ble/Q15/Q31 fit_sine, fit_sine_tracked and program_weighted_snr_db take a contiguous range of Sample (span, vector, array) for float, double, std::int16_t and std::int32_t. Floating samples are read as they were; integer samples as Q0.15 / Q0.31 fractions through sample_traits' k_sample_frac_bits, with an optional scale exponent for fixed-point FFT output (read as x * 2^e). The read is one exact power-of-two multiply per sample, so the hot loops stay the plain double loops they were; the joint-fit internals on the double work buffer are unchanged. test_analysis.cpp pins both promises: the float and double instantiations are bit-identical to verbatim copies of the pre-template instruments in the same binary (a same-host A/B, not a golden hash), and the Q15 / Q31 instantiations equal the double instrument on the same fractions bit for bit and agree with it on the unquantised signal to the quantisation noise (measured 2026-09-23: 0.289 LSB rms residual, 92.07 / 188.44 dB SNR on a 0.5 full-scale tone; 83.86 / 180.15 dB program-weighted on the pink comb), pinned at 2x / -0.5 dB / -1 dB. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZPTzNxo5Fe4EtpXXKf7Sy
…icies
dsptap_fft_create accepts DSPTAP_FFT_PROFILE_Q15 and _Q31 (scaling::fixed)
and the appended _Q15_BFP / _Q31_BFP (scaling::block_floating); every
existing value and signature is unchanged. The exponent path, documented
in the header in fft.h's terms:
- dsptap_fft_forward / dsptap_fft_inverse (double I/O) quantize the input
to the profile's Q format by the substrate's round_sat, run the
transform, and return the native result read as fractions times 2^e,
so numpy compares it to the double profile directly; the fixed inverse
carries no 2/N (the exponent is the scale).
- dsptap_fft_forward_exp / _inverse_exp: the same with e written out.
- dsptap_fft_forward_inplace_raw / _inverse_inplace_raw now return e
(>= 0; 0 for the floating profiles, as before) or -1 on error;
dsptap_fft_forward_inplace_raw_exp / _inverse_inplace_raw_exp keep the
0 / -1 status and write e separately, the path for bindings.
- dsptap_fft_fixed_scaling_exponent: the constant / upper bound per size.
- dsptap_fft_sample_bytes reports 2 / 4 for the fixed profiles;
dsptap_fft_backend is documented as the float32 engine only (the
fixed-point kernel is the portable int32 kernel on every host).
tools/capi/test_capi.c is a C smoke test (dsptap_capi_smoke, built when
the root project builds its tests): the header compiles under a C front
end, every profile constructs, the double boundary agrees with the double
profile on the same quantized input, the raw round trip satisfies
x == out * 2^(e_fwd + e_inv + 1 - log2 N), and bad arguments return NULL / -1.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZPTzNxo5Fe4EtpXXKf7Sy
Profiles "q15", "q31", "q15_bfp", "q31_bfp" join "double" and "float". forward / inverse return float64 in the packed layout already scaled by 2^e (the double profile's units); the exponent of the last transform is `last_exponent`, and forward_with_exponent / inverse_with_exponent return (array, e). forward_inplace_raw / inverse_inplace_raw run on the native int16 / int32 dtype and return e (0 for the floating profiles; they previously returned the buffer). to_native / from_native quantize and read back exactly as the C boundary does; exponent_bound is fixed_scaling_exponent(n). The docstring states the exponent contract in fft.h's terms. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZPTzNxo5Fe4EtpXXKf7Sy
… the ABI Section 4 replaces the Stage 3b/3c placeholder, every cell driving the shipping C++ through dsptap_py.RealFFT on the native int16 / int32 raw path: (4.0) the exponent contract at the boundary, the double-I/O and raw paths bit-identical; (4.1) the per-bin noise floor vs input level at 0 / -20 / -40 / -60 dBFS for Q15 and Q31 under both policies at N = 256 / 512 / 2048, white noise and an on-bin tone, the battery's own generators and inputs, with Welch's early-schedule model drawn against the measurements and the battery's recorded rows beside them (every row agrees to the printed rounding; the largest measured/model ratios are exactly half the pins); (4.2) the Q31 DC-path round-half-up bias followed to N = 65536 (levels off under fixed scaling, roughly doubles per octave under block floating point); (4.3) the block-floating exponent per block on synthesized speech-like material against block level, and the per-bin SNR the policy buys in quiet blocks; (4.4) the fixed-point raw round trip in reconstructed and input LSB; (4.5) the battery's sixteen pinned output fingerprints reproduced through the ABI. Every figure carries the pin SHA, host, compiler, backend and date. Executed on Linux x86_64 against 2af3de6; fixed seeds; 1.05 MB. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZPTzNxo5Fe4EtpXXKf7Sy
…C narrowing CI on 35a3150: macOS arm64 failed FloatingSpansAreBitIdenticalToThePre- TemplateInstrument by one ulp of residual_rms in the tracked float fit, and Windows failed to build test_analysis.cpp (C4244, a double->float vector range constructor under /WX). The ulp: the first typed read multiplied every sample by an exact power-of-two step (1.0 for floats at exponent 0), and a product feeding a subtraction contracts into a fused multiply-subtract where a plain operand does not. The header now reads a floating sample as the bare cast the pre-template code evaluated, an integer sample as its exact Q0.15 / Q0.31 fraction, and applies the exponent to the fit's three magnitude fields afterwards (an exact scale; the phase and frequency are invariant). program_weighted_snr_db loses the exponent parameter: its result is a ratio a power-of-two scale cannot move. Even so, GCC's default -ffp-contract=fast fuses across statements by inlining and unrolling context, so two textually identical functions can differ by an ulp on FMA hardware (reproduced: g++ 13 -O3 -mfma on the sub-span and tracked fits; clang, per-expression, and MSVC, no contraction, agree bit for bit). The typed battery therefore moves to its own TU and target, tests/test_analysis_typed.cpp / tap_dsp_analysis_typed, carrying -ffp-contract=off exactly as the Stage 2a Ooura parity gate does, appended as its own block at the end of tests/CMakeLists.txt; the double joint-fit test is excluded on the QEMU legs like MultitoneAnalysis. test_analysis.cpp is back to its pre-Stage-3c content. The float tail in the multitone test is now filled by an explicit static_cast loop. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZPTzNxo5Fe4EtpXXKf7Sy
The design note's host-microbenchmark row (TODO(stage 2b)) takes the tap_dsp_bench_fft numbers measured on the development container with the port (basic_real_fft) and the vendored C (reference_c) built side by side: at parity on x86-64 without -march (round-trip ratio 0.97 - 1.00), one machine, load stated, checksums identical. The PR landed as #31, not #30; the four citations are corrected. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZPTzNxo5Fe4EtpXXKf7Sy
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZPTzNxo5Fe4EtpXXKf7Sy
tap
left a comment
There was a problem hiding this comment.
Hostile review B — ABI compatibility, build/CI, consumers, scope, docs, process — of a3639a5. The numerics reviewer covers the arithmetic, exponent semantics and the notebook's numbers; nothing below is about those. Every finding was reproduced locally or read from the CI logs before being written down. No blocker.
Findings
-
should-fix —
notebooks/fft.ipynb, cells 3, 5 and 9:stamp(fig)is called three times in a row (cell 19's two calls are two different figures and are fine).stamp()re-runstight_layoutand draws the stamp text again at the same position, so the committed PNGs of §1, §2 and §3 carry three overprinted stamps.main's notebook had nostamp(); this arrived with35a3150. Re-execution is cheap (9.8 s wall from a clean kernel, see below) and the fix is deleting four lines, so do it in the same pass as anything else that re-executes the notebook. -
should-fix (coordination, not a defect of this diff) — the notebook cites a file the 2b branch deletes. Cells 12, 14 and 15 of
fft.ipynbrefer todocs/fft-fixed-point.md§5 as the source of the battery's rows;claude/wave3-stage2b-flipremovesdocs/fft-fixed-point.md(402 lines, folded intodocs/fft-design.md). Whichever PR merges second leaves the references dangling; since the notebook isnotebooks/**(this PR's ownership) and the sentence the README hand-off in the PR body proposes also says "the noise-floor table of the fixed-point design note", the cheapest resolution is: after 2b lands, one notebook markdown edit pointing atfft-design.md, re-execute, and the README sentence worded to match. The README target sentence itself ("designed placeholder until Stage 3b/3c", README.md:411-413) is still present in 2b's rewritten README (its lines 428-435), so the hand-off remains applicable. -
should-fix, or accept explicitly —
tools/capi/dsptap_capi.h:146-153, the raw functions' return value. Verified not an ABI break for any existing caller (symbol-level diff of the header againstmainis additions only; the only callers ofdsptap_fft_*_inplace_rawanywhere in DspTap, MuTaporigin/main, MuTap-Max and the notebooks aredsptap_py.py, updated here and now on the_expvariants, and the newtest_capi.c; a fixed-point handle could not be created before this PR). It does introduce a second return convention into a header whose file-level contract was 0 / -1, with noDSPTAP_CAPI_VERSIONto mark it. Detail and two alternatives in the inline comment. -
nit — Windows
dllexport(inline,tools/capi/CMakeLists.txt:34).DSPTAP_APIis unconditionally__declspec(dllexport); the smoke test is the first in-tree importer, so on MSVC the.exegrows an export table. It links and runs (Windows log:dsptap_capi.dll/.lib/dsptap_capi_smoke.exeside by side inbuild\tools\capi\Release,Test #410: dsptap_capi_smoke ... Passed 0.01 sec, noLNK4/C4warnings in the log). Pre-existing header design; Stage 6 if not here. -
nit — header compile cost (inline,
sine_analysis.h:45). Measured, one TU including only the header,-std=c++20 -O2 -c, best of 3:sine_analysis.hg++ 13.3 0.20 s → 0.50 s, clang++ 18.1 0.25 s → 0.62 s;multitone_analysis.hg++ 0.53 → 0.52 s, clang++ 0.47 → 0.81 s. The delta is<ranges>;<iterator>'sstd::data/std::sizeplus acontiguous_iteratorrequirement would give the same call sites without it. -
nit —
sine_analysis.h:201@param x, exponentis not Doxygen syntax (inline). -
nit —
test_capi.c:239dsptap_fft_create(512, 6)hard-codes the first unassigned code;DSPTAP_FFT_PROFILE_Q31_BFP + 1(inline). -
nit —
dsptap_capi.h, the seven new/changed FFT declarations carry no@param/@return(STYLE.md §3; audit Part 8 item 1 asks for@paramper STYLE.md). Consistent with the rest of the header, which predates the rule; the_inplace_rawpair is where a@returnis load-bearing (finding 3).
Verified correct
Scope and ownership (Part 12). Ten files changed, all inside include/tap/dsp/analysis/**, tests/test_analysis*.cpp, tests/CMakeLists.txt, tools/capi/**, notebooks/**. README.md, CLAUDE.md, docs/, fft.h, fft/**, tests/test_fft.cpp, bench/**, workflows, third_party: untouched. tests/test_analysis.cpp is byte-identical to main (git diff --quiet clean). The tests/CMakeLists.txt change is one block appended at the end (lines 268-287), and the new target goes through tap_dsp_add_gtest_executable, so it is registered as tap_dsp_analysis_typed_emulated on the QEMU legs with the TAP_DSP_TESTS_COMPLETE pass regex.
Merge with 2b. git merge-tree --write-tree --merge-base=origin/main a3639a5 origin/claude/wave3-stage2b-flip → clean, tree 3acd583, no conflicts (2b's tests/CMakeLists.txt hunk is at lines 116-133, this PR's at 268+). I built that merged tree (g++ 13.3, -DTAP_DSP_WERROR=ON -DTAP_DSP_BUILD_CAPI=ON): 0 warnings, ctest 409/409 (410 − the 5 icount smoke tests I did not enable + 2b's 4 new tests). Finding 2 is the only cross-branch item.
ABI. Symbol-by-symbol diff of dsptap_capi.h against main: every pre-existing #define, typedef, function name, signature and DSPTAP_NOEXCEPT unchanged; additions only (_Q15_BFP=4, _Q31_BFP=5, dsptap_fft_fixed_scaling_exponent, _forward_exp, _inverse_exp, _forward_inplace_raw_exp, _inverse_inplace_raw_exp). Standalone cmake -B build_capi -S tools/capi (what dsptap_py runs) configures and builds warning-free and does not generate the smoke target (root TAP_DSP_BUILD_TESTS is OFF when not top-level; 0 occurrences of smoke in the generated Makefile, no binary). macOS log: libdsptap_capi.dylib and dsptap_capi_smoke built in the same directory, Test #410: dsptap_capi_smoke ... Passed.
Hosts. Local g++ 13.3 and clang++ 18.1, -DTAP_DSP_WERROR=ON -DTAP_DSP_BUILD_CAPI=ON -DTAP_DSP_BUILD_BENCH=ON: 0 warnings, 410/410 each (CI: linux 410, windows 410, macos 410; main at b08f6c6 was 405 = +4 typed tests +1 smoke). clang-format --dry-run --Werror clean on all six changed C/C++ files; scripts/tidy.sh tools/capi/dsptap_capi.cpp tests/test_analysis_typed.cpp tests/test_analysis.cpp → "clang-tidy clean".
QEMU legs (run 35846161145 vs main run 35799637468). New binary: TAP_DSP_TESTS_COMPLETE rc=0 selected=3 skipped=0 on all four legs, and the per-test lines show the three SineAnalysisTyped tests running with their [ measured ] values printed on target (m33: Q15 residual 0.2886 LSB, 92.07 dB; Q31 0.2873 LSB, 188.44 dB). Wall time added by tap_dsp_analysis_typed_emulated: m4-softfp 12.5 s, m4f 22.8 s, m33 25.6 s, m55 1.9 s. The main battery's own time moved 99→153 s (m4), 159→161 s (m4f), 126→206 s (m33), 36→26 s (m55) with selected=345 unchanged; the slowest tests (psola clock-wrap 17→29 s on m4) scale by the same factor, i.e. runner variance, not this PR. MultitoneAnalysisTyped is excluded by MAIN_FILTER with the same budget justification as MultitoneAnalysis in the main battery, stated in the CMake comment.
MuTap / MuTap-Max. Contrary to the brief I was given, neither MuTap (origin/main or the local checkout) nor MuTap-Max includes sine_analysis.h / multitone_analysis.h anywhere; MuTap's only DspTap includes are tap/dsp/fft.h and tap/dsp/nn.h, which this PR does not touch. Built MuTap origin/main twice from scratch with -DMUTAP_WERROR=ON -DMUTAP_BUILD_TESTS=ON (g++ 13.3): with the current pin b08f6c6 and with this PR's tree as submodules/dsptap: 0 warnings both, ctest 198/198 both, and mutap_fingerprint -V output (16 FINGERPRINT lines, backend=ooura) byte-identical between the two. Python side: tools/ml/kws/kws_features.py uses only dsptap_py.LogMel and the library-path lookup; nothing imports RealFFT or the raw functions' old buffer return.
Notebook. 1,051,717 bytes; 955 KB (91 %) is nine embedded PNGs at 96 dpi, 55 KB source, 20 KB text output; no base64 arrays. Seeds fixed (default_rng(20260917), default_rng(1), default_rng(seed)); the only wall-clock use is TODAY in the stamp. git diff 2af3de6..a3639a5 -- tools notebooks touches only notebooks/fft.ipynb itself (the execution commit), so the capi and bridge the stamp names are those in the head: the 2af3de6 stamp is accurate. Re-executed from a clean kernel in a fresh venv with the pinned requirements.txt (numpy 2.4.6, matplotlib 3.11.2, nbconvert 7.17.1) against the standalone-built capi of this tree: rc=0, 9.8 s; all 26 cells' text outputs identical to the committed ones except the stamp line (host/SHA), PNGs identical in count and within 180-320 bytes (the stamp string differs).
Docs. The exponent paragraph in dsptap_capi.h (profile codes) and the RealFFT docstring state the same contract as fft.h:471-486: buffer scaled by 2^-e, unnormalized inverse, x == out · 2^(e_fwd + e_inv + 1 − log2 N), Q15 e = log2 N, Q31 log2 N + 1, BFP 0 ≤ e ≤ that constant. The README hand-off target sentence exists (README.md:411-413) and survives 2b's README rewrite.
Process. All five commits carry both Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> and Claude-Session: trailers; the PR body follows the template's four sections and ends with the two footer lines; no other model identifiers in the diff (outside base64 image data) or notebook source; commit messages match their diffs (in particular a3639a5's account of the macOS ulp and MSVC C4244 fix matches the 35a3150→a3639a5 diff, which touches only the analysis headers, the two test files and tests/CMakeLists.txt).
Generated by Claude Code
tap
left a comment
There was a problem hiding this comment.
Hostile review A (numerics, exponent semantics, test rigor, notebook honesty) of a3639a5. Everything below was verified against source, a local Release build (g++ 13.3 / clang 18.1, -DTAP_DSP_BUILD_CAPI=ON, full battery green locally), scratch C/C++/ctypes programs, mutation runs on the typed TU, and a re-execution of notebooks/fft.ipynb in a fresh venv from requirements.txt. No blockers. Five should-fix, five nits.
Findings
1. should-fix — dsptap_fft_create does not enforce the fixed profiles' size bound; in the bridge's own build it aborts the interpreter. tools/capi/dsptap_capi.cpp:248 checks only size < 4 || !pow2; fft.h / fft/fixed_point.h state 4 <= N <= 65536 for Q15/Q31 and assert it in the constructor. Measured: in this Release build, dsptap_fft_create(131072 | 262144 | 1048576, Q15/Q31/Q15_BFP/Q31_BFP) all return handles and transform (numerically fine on white noise: Q15 0.500 LSB@e, Q31 4.2 - 5.0 LSB@e — so it is a silent contract violation, not a wrong answer). In the build the ctypes bridge makes for itself (cmake -B build_capi -S tools/capi, no CMAKE_BUILD_TYPE, so assert is live) tap.RealFFT(131072, "q15") kills the Python process: fixed_point.h:221: Assertion 'n >= k_min_size && n <= k_max_size && ...' failed, exit 134 — the noexcept C entry point cannot turn that into the documented NULL / bridge ValueError. dsptap_capi.h:77 promises "NULL on a bad size". Fix: reject size > 65536 for the four fixed profile codes in dsptap_fft_create (use fixed_point_rdft::k_max_size rather than a literal), say so at the profile codes, add CHECK(dsptap_fft_create(131072, DSPTAP_FFT_PROFILE_Q15) == NULL) to test_capi.c, and let the bridge's message mention the fixed-point bound.
2. should-fix — fit_sine_tracked's exponent path is untested. tests/test_analysis_typed.cpp:326-333 exercises the exponent only through fit_sine(q, nu, e); the tracked fit is called with an exponent nowhere. Mutation M8 (return fit_sine(xs, f, exponent) -> return fit_sine(xs, f) in sine_analysis.h) passes all four tests. One line fixes it: add fit_sine_tracked(q, nu * (1 + 5e-6), e) against fit_sine_tracked(q, nu * (1 + 5e-6)) scaled to that loop.
3. should-fix — the header's "pinned bit for bit" claim needs its flag qualification (include/tap/dsp/analysis/sine_analysis.h:16). The PR body and the test-file comment are honest about it; the header is not. Measured on this host by compiling test_analysis_typed.cpp outside CMake: g++ -O3 -mfma at GCC's default -ffp-contract=fast fails FloatingSpansAreBitIdenticalToThePreTemplateInstrument — amplitude 0.49999999984964577 vs ...583, and phase 0.300023576240741 vs ...4094 (so not only the magnitude fields move); g++ -mfma -ffp-contract=off, clang++ -mfma -ffp-contract=on|fast and g++ without FMA pass. A consumer building the instruments at default flags with GCC on an FMA host (Linux arm64, x86 with -march, M55 with the GNU toolchain) therefore sees a <= 1-ulp difference from the pre-3c instrument, which is exactly audit Part 4's (a)/(b) split; the header should state "bit-identical under -ffp-contract=off (the typed target) and on per-statement contracting compilers; <= 1 ulp otherwise, measured". Related, for the record: the gate as compiled cannot catch the regression class that broke macOS CI — reintroducing * 1.0 in the float read (mutation M6) passes all four tests under -ffp-contract=off, and also under clang++ -mfma -ffp-contract=on on x86; the "no multiply, not even by 1.0" rule is enforced by comment only. Worth one sentence in the test file so nobody reads the pass as proof.
4. should-fix — notebook §4.2 / Summary / PR body: "roughly doubles per octave" is not what the table shows, and the fixed-vs-BFP contrast is a unit artefact. notebooks/fft.ipynb (markdown at raw line ~1017, summary at ~1574; PR body "keeps roughly doubling per octave"). The F(x)+F(-x) index-0/1 column for q31_bfp is 14, 26, 25, 32, 67, 66, 137, 141, 279: it doubles per two octaves (per radix-4 stage), in step with the returned exponent (7, 7, 8, 9, 9, 10, 10, 11, 11). Reproduced independently on the header (basic_real_fft<int32_t, block_floating>, the battery's generator, seed 0x9E3779B9 ^ N, amplitude 0.999): identical numbers. Expressed in the fixed-scaling constant's LSB (i.e. the golden model's units, count * 2^(e - const)) the same column is 3.50, 3.25, 3.13, 4.00, 4.19, 4.13, 4.28, 4.41, 4.36 — flat, and no larger than fixed scaling's own 4, 4, 6, 5, 6, 6, 8, 7, 9. So the coherent DC-path bias is the same ~4 LSB@const under both policies; BFP simply retains it as 2^(const - e) of its finer LSB, and (const - e) grows 2 -> 6 bits over the sweep. "Levels off under fixed, keeps doubling under BFP" should be restated as that; the same applies to the round-trip "21 -> 377 reconstructed LSB" (§4.4), which is the same unit effect (k shrinks). The markdown's parenthetical "(in the finer LSB of the lower exponent it returns)" acknowledges the unit but the headline and summary do not.
5. should-fix — bridge raw path does not enforce the alignment the ABI requires. dsptap_capi.h:139 says the raw buffer "must be aligned for that type"; notebooks/dsptap_py.py:311-314 (_check_raw) checks dtype, ndim, size, C-contiguity and writeability but not data.flags.aligned. Verified: np.ndarray(shape=(16,), dtype=np.int16, buffer=bytearray(33), offset=1) is accepted and transformed (flags.aligned == False). Add or not data.flags.aligned. (Byte order is fine: dtype('>i2') != dtype('<i2'), so a big-endian array is rejected — verified.)
6. nit — analysis_sample admits long double. sine_analysis.h:55-56 uses std::floating_point, so std::vector<long double> satisfies the concept (verified by static_assert) and is read through a narrowing static_cast<double>; the docstring lists float / double only. Either std::same_as<float> || std::same_as<double> or say so.
7. nit — the multitone integer-read pin is vacuous. program_weighted_snr_db is exactly scale-invariant — verified bit-identical for tails scaled by 2^-60 ... 2^40 (no absolute epsilon in joint_fit_residual_power / solve_dense) — so same_bits(snr_q15, snr(fractions(q15))) at test_analysis_typed.cpp:365-366 cannot distinguish a fraction read from a raw-integer read: mutation M5 (work[i] = static_cast<double>(ts[i])) passes all four tests. Harmless functionally (it is why the exponent parameter could be dropped), but the comment "the integer instantiations equal the double instrument on the same fractions bit for bit" should not be read as evidence of the read; only the sine tests pin it.
8. nit — notebook §4.3 numbers are blended. "The BFP exponent is 0 for blocks below about -35 dBFS" (raw line ~1577): per profile it is Q15 BFP e = 0 up to -24.8 dBFS (first e > 0 at -31.6) and Q31 BFP e = 0 up to -35.7 (first e > 0 at -42.2) — the two guard bits make Q15 BFP shift a decade later than Q31 BFP. And "55 dB median in quiet blocks vs 1.6 dB fixed" (cell 19 output): 30 of the 44 quiet blocks are pauses at the -60 dBFS noise floor; on the 14 quiet-syllable blocks (-50 ... -30 dBFS) fixed Q15 holds 24.3 dB and BFP 76.9 dB. Both reproduced by re-running the cell's code. Printing the pause / syllable split would make the "quiet syllables" sentence in the summary match its number.
9. nit — "pinned rows" wording. Cell 14 / PR body call the per-row floor numbers "pinned in tests/test_fft_fixed.cpp"; the battery pins the maximum measured/model ratio per configuration and the fingerprints, the rows are recorded in docs/fft-fixed-point.md §5 and printed by -V. The notebook's comparison is still the right one; the word is wrong.
10. nit — source-compatibility edge of the range template. fit_sine({ptr, n}, nu) (braced construction of the old std::span<const float> parameter) no longer deduces. No caller in DspTap or in the MuTap checkout uses that shape (MuTap does not call the instruments at all; its bridge use is LogMel only), SampleRateTap / RatioTap not checked here. One line in the header's compatibility note.
Verified correct
- C ABI exponent path (scratch C++ against
basic_real_fft<double>on the sameround_sat-quantized input, N = 4 ... 2048, 0.999 / 0.1 / 0.001 full scale, all four fixed profiles): forwardout == G.forward(x_q)and inverseout == G.inverse_inplace(a_q)(unnormalized; confirmed the 2/N-normalized inverse does not match) to the kernel's noise — worst Q15 0.500 / 0.500, Q31 3.54 / 3.81, Q15 BFP 0.500 / 0.500, Q31 BFP 25.7 / 67.5 LSB@e. The Q31 BFP inverse maximum is at -60 dBFS with e = 0 (0.018 LSB at the constant), i.e. the documented early-schedule floor, not a plumbing error.in == outaliasing bit-identical to the non-aliased call.sample_bytes8/4/2/4/2/4,profile()round-trips,fixed_scaling_exponentequals the header's,_expvariants,_inplace_rawreturning e (0 for the floating profiles), NULL handle/array/exponent -> -1, bad profile 6 / -1 and sizes 0 / 2 / 3 -> NULL, BFP silence -> e = 0 all-zero,|in| >= 1saturates to the rail as documented:test_capi.cpasses locally and my probes agree. Construction throws are caught; the transforms arenoexceptend to end (the only abort path is finding 1). - Bridge:
to_nativeequalstap::dsp::detail::round_saton 327,792 values including exact half-LSB ties, both rails, +-0.0 and out-of-range inputs (0 mismatches, Q15 and Q31);forward()scales by the exponent of the same call (loud block e = 8, then quiet block e = 0:forward(quiet)equalsforward_with_exponent(quiet)[0]and matchesG(x_q)to 0.50 LSB@e);from_native,exponent_bound,(array, e)variants,dtype.itemsize == sample_bytesasserted; big-endian, strided, read-only, wrong dtype / length / ndim and Python lists rejected on the raw path. Every bridge call site uses the_expentry points; no committed notebook (here or in MuTap) used the raw functions' old return value. - Instruments:
fit_sine(q, nu, e)andfit_sine_tracked(q, nu, e)are bit-identical, in every field includingsnr_db, to feeding the pre-scaled doublesfrac(q) * 2^efor e in {-9, -3, 2, 7} — applying 2^e after the fit is exact for amplitude, dc and residual_rms (hypot / sqrt / the linear solve all commute with a power-of-two scale), phase and frequency invariant, andsnr_dbis a ratio, so nothing squared or floored breaks it.program_weighted_snr_dbscale invariance bit-exact at 2^-60 ... 2^40. Concept acceptsvector,array,span<const T>,span<T>, fixed-extent span, C array, const vector; rejectsbool,char,signed char,unsigned short,int64_t,list,deque, nested vectors. Integer reads go throughsample_traits<Sample>::k_sample_frac_bits, no literal. - Mutation kill matrix (typed TU rebuilt against a mutated copy of
include/,g++ -O3 -mfma -ffp-contract=offas CI builds it): M1 unit = 1/(2^15-1) -> caught byQ15Span...,Q31Span...,MultitoneAnalysisTyped; M2 swap 15 <-> 31 ->Q15Span...,Q31Span...; M3 residual_rms not scaled -> both sine tests; M4 phase scaled too -> both sine tests; M7 exponent ignored infit_sine-> both sine tests. Not caught: M5 (finding 7), M6 (finding 3), M8 (finding 2), M9 (divide by 2^k instead of multiply by the unit — exact, semantically identical, not a defect). - Test rigor: tolerances are measured numbers with stated margins (2x / -0.5 dB / -1 dB), date and host; no
<random>, clock or filesystem in the typed TU (xorshift32,printfonly);MAIN_FILTER "*-MultitoneAnalysisTyped.*"mirrors the main battery'sMultitoneAnalysis.*exclusion and leaves the sine tests on the QEMU legs. PR's GCC / clang / MSVC contraction characterisation reproduced exactly (GCC+FMA default differs, clang on/fast and GCC without FMA do not). - Notebook: re-executed in a fresh venv from
requirements.txt— all 12 code cells' text outputs are identical to the committed ones (only the stamp line differs; seeds fixed, no wall clock in the numbers). Every figure (8) carriesstamp()with SHA / host / compiler / backend / date; no external audio (speech-like material synthesized in-cell). Every measured number in §4 comes throughRealFFT.forward_inplace_raw/forwardon the shipping kernel; the only Python-side model is Welch's, and cell 13'skernel_stages/shifts_for/welch_modelare line-for-line the battery's (test_fft_fixed.cpp) and the formuladocs/fft-fixed-point.md§5 states.BATTERYrows spot-checked against §5 (q15/256, q31/512, q31/2048, q15_bfp/2048, q31_bfp/512, q31_bfp/2048) andPINNED_RATIOagainstk_pins_*: all agree. Fingerprints spot-checked againstk_fingerprints(q15 fwd 512, q31 inv 2048, q15_bfp fwd 2048, q31_bfp inv 512) and the notebook's FNV-1a fold matchesoutput_fingerprintbyte for byte; all sixteen match through the ABI. The 14 -> 279 LSB DC-bias numbers and the 55.0 / 1.6 dB quiet-block medians reproduce (findings 4 and 8 are about wording and units, not the numbers).
Anchors: F1 sits on dsptap_capi.cpp:262 (the first fixed-profile case; the size check at 248 is outside the diff hunk) and F5 on dsptap_py.py:267 (the _check_raw call; the method body at 311-314 is unchanged); F4 / F8 / F9 are file-level comments on notebooks/fft.ipynb because GitHub renders no diff for the 1 MB notebook, with the raw line numbers in the text.
Generated by Claude Code
…h its flags Review of #30 (A3, A6, A10, B5, B6; A2, A7 in the battery). sine_analysis.h: analysis_range is spelled over std::data / std::size, which <span> provides ([iterator.range]), instead of std::ranges::contiguous_range; the header no longer includes <ranges>, which alone had doubled its compile cost. Measured on one TU including only the header (-std=c++20 -O2 -c, best of three): g++ 13.3 0.19 s on main, 0.40 s with <ranges>, 0.35 s with <iterator> (its std::contiguous_iterator would restate what std::data already says, at nearly <ranges>'s price), 0.19 s as written; clang++ 18.1 0.23 / 0.58 / 0.44 / 0.23 s. analysis_sample names exactly float / double / int16_t / int32_t (long double satisfied std::floating_point and would have been narrowed). The banner now says under which flags the floating instantiations are bit-identical to the pre-template instrument (-ffp-contract=off, the typed target; clang per-statement contraction; MSVC) and that GCC's default -ffp-contract=fast on FMA hardware moves the tracked float fit's amplitude and phase by one ulp (measured), notes the one call shape that no longer deduces (a braced span built in the call), and the two @PARAM lines replace the non-Doxygen `@param x, exponent`. test_analysis_typed.cpp: the exponent pin now runs fit_sine_tracked with an exponent beside fit_sine, and both against the fit of the pre-scaled fractions in every field. Mutation proof (typed TU rebuilt against a mutated include/ with g++ -O3 -mfma -ffp-contract=off, CI's flags): dropping the exponent forwarding in fit_sine_tracked passed all four tests before and fails both Q15 / Q31 sine tests now; ignoring the exponent in fit_sine fails the same two. Two comments state what the battery cannot prove: the "no multiply by 1.0" rule in the floating read is enforced by the same-binary A/B only under the flags the target compiles with (a reintroduced `* 1.0` passes under -ffp-contract=off and under clang++ -mfma -ffp-contract=on), and the multitone integer-read equality is vacuous because program_weighted_snr_db is exactly scale-invariant (a raw-integer read passes it too); the fraction read is pinned by the sine tests. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZPTzNxo5Fe4EtpXXKf7Sy
…nvention Review of #30 (A1, B3 / A9, B7, B8). dsptap_fft_create returns NULL for a fixed-point profile above the header's k_max_size (65536), read from basic_real_fft<int16_t>::engine::k_max_size and static_asserted equal across the four fixed-point instantiations, never retyped. Before, a Release build handed out a handle the header does not support and the assert-live standalone build the ctypes bridge makes for itself aborted the interpreter from a noexcept entry point. The bound is stated at the profile codes and in dsptap_fft_create's @PARAM. dsptap_fft_forward_inplace_raw / _inverse_inplace_raw go back to the file-level 0 / -1 convention: a floating handle transforms and returns 0 as before the fixed-point profiles existed; a fixed-point handle is refused with -1 and its buffer left untouched, because these signatures have nowhere to put the exponent and a caller following the file-level convention must never receive a 2^-e-scaled buffer with a success status. The *_exp variants carry e for every profile and are the binding path (dsptap_py already used them). The header's Conventions paragraph is uniform again and carries a dated changelog line; the seven new or changed FFT declarations carry @PARAM / @return per STYLE.md. test_capi.c: the legacy raw pair is checked per profile (0 and a changed buffer for double / float, -1 and an untouched buffer for the fixed-point four); 65536 constructs and 131072 is NULL for the four fixed-point codes and constructs for the floating two; the first unassigned profile code is spelled DSPTAP_FFT_PROFILE_Q31_BFP + 1. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZPTzNxo5Fe4EtpXXKf7Sy
…d-point bound Review of #30 (A5, A1). RealFFT._check_raw requires data.flags.aligned as well: an int16 view at an odd byte offset is contiguous and writeable but not aligned for the type the ABI requires, and was accepted and transformed. The ValueError for a refused size names the fixed-point profiles' [4, 65536] bound (the capi now returns NULL there instead of reaching the header's assert). Verified against the standalone build_capi: RealFFT(131072, q15 | q31 | q15_bfp | q31_bfp) raises, RealFFT(131072, "double") constructs, the odd-offset view raises TypeError, an aligned buffer transforms. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZPTzNxo5Fe4EtpXXKf7Sy
…ngs in both units Review of #30 (A4, A8, A9, B1, B2; the bridge guards of A1 / A5 smoked in §4.0). Executed from a clean kernel against 080862f with the pinned requirements (numpy 2.4.6, matplotlib 3.11.2, nbconvert 7.17.1); every §1-3 number is unchanged, every figure carries one stamp. §1-3: the three figures had stamp(fig) three times in a row and carried three overprinted stamps; once each now. §4.1 / cell 15: the battery's rows are cited from docs/fft-design.md, "The fixed-point profiles: design record", §5 (the file docs/fft-fixed-point.md is folded there by #31, which merges first), and described as recorded and printed by `ctest -V`, not pinned: the battery pins the maximum measured/model ratios and the output fingerprints. §4.2: "levels off under fixed, roughly doubles per octave under block floating point" was a unit artefact. The table now prints F(x) + F(-x) at index 0 / 1 both at the returned exponent (the battery's count) and at the fixed-scaling constant (count * 2^(e - const), the golden model's unit): there the coherent DC-path bias is flat and the same under both policies, fixed 4 .. 9 and block floating 3.5 .. 4.4 LSB over N = 256 .. 65536, while the count (14 -> 279) doubles per radix-4 stage with the exponent (7 .. 11 against a constant of 9 .. 17) because the block comes back 2^(const - e) finer. The figure's right panel is drawn in the common unit, the count kept as a dotted reference. §4.3: the exponent thresholds are per profile (Q15 BFP e = 0 up to a block peak of -24.8 dBFS, first shift at -31.6; Q31 BFP -35.7 / -42.2), and the 44 quiet blocks are split into the 30 pauses at the -60 dBFS floor and the 14 quiet-syllable blocks (-50 .. -30 dBFS): fixed Q15 24.3 dB against block-floating 76.9 dB median per-bin SNR on the syllables, 1.5 against 54.8 dB on the pauses. §4.4: the BFP round trip's 21 -> 377 reconstructed LSB is the same unit effect (k stays at 3 while fixed scaling's k is log2 N + 3); the cell also prints it in fixed scaling's reconstructed LSB, 0.08 falling to 0.006. §4.0 smokes the bridge's guards: RealFFT(131072, <fixed-point profile>) raises ValueError naming the bound, RealFFT(131072, "double") constructs, an int16 view at an odd byte offset raises TypeError. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZPTzNxo5Fe4EtpXXKf7Sy
Fix pass for reviews A (numerics) and B (process) — head
|
| finding | fix | commit |
|---|---|---|
| A1 should-fix: capi ignores the fixed profiles' 65536 bound (assert-abort in the bridge's build) | dsptap_fft_create returns NULL above basic_real_fft<int16_t>::engine::k_max_size for the four fixed-point codes (constant read from the header, static_asserted equal across the four); documented at the profile codes and @param; test_capi.c checks 65536 / 131072 per profile; bridge ValueError names the bound; §4.0 smokes it |
772e69f, 080862f, f7e86fe |
A2 should-fix: fit_sine_tracked exponent path untested |
tracked fit with exponent added to the pin, both entry points also compared to the fit of the pre-scaled fractions in every field | 761afe3 |
| A3 should-fix: "pinned bit for bit" without its flags | header states: bit-identical under -ffp-contract=off and per-statement-contracting compilers, ≤ 1 ulp under GCC default on FMA (amplitude and phase, measured); test file says the * 1.0 rule is enforced only under the target's flags |
761afe3 |
| A4 should-fix: "doubles per octave under BFP" is a unit artefact | §4.2 / §4.4 / Summary / PR body restated: ~4 LSB at the fixed-scaling constant under both policies (fixed 4 … 9, BFP 3.5 … 4.4), the count grows only because the block comes back 2^(const − e) finer; both units printed; figure drawn in the common unit; round trip also in fixed scaling's reconstructed LSB (0.08 → 0.006) | f7e86fe |
| A5 should-fix: bridge accepts unaligned raw views | _check_raw requires flags.aligned; smoked in §4.0 |
080862f, f7e86fe |
| B1 should-fix: three overprinted stamps | one stamp(fig) per figure, re-executed |
f7e86fe |
B2 should-fix: citations of docs/fft-fixed-point.md |
cells 12 / 14 / 15 cite docs/fft-design.md, The fixed-point profiles: design record, §5; PR body's README hand-off sentence likewise |
f7e86fe |
| B3 + A9 should-fix: second return convention; "pinned rows" | legacy raw pair back on 0 / −1 (−1 for fixed-point handles, buffer untouched; _exp carries e), @return, dated changelog line in the header; cell 14 / PR body say the rows are recorded and printed by -V, the ratios and fingerprints are what is pinned |
772e69f, f7e86fe |
A6 nit: long double admitted |
analysis_sample names exactly float / double / int16 / int32 |
761afe3 |
| A7 nit: multitone integer-read pin vacuous | comment states the scale invariance and that the sine tests pin the fraction read; no honest non-invariant multitone case exists | 761afe3 |
| A8 nit: §4.3 numbers blended | per-profile e = 0 thresholds (Q15 BFP −24.8 / −31.6, Q31 BFP −35.7 / −42.2 dBFS) and pauses vs quiet syllables (q15 1.5 / 24.3 dB vs q15_bfp 54.8 / 76.9 dB) printed and quoted | f7e86fe |
| A10 nit: braced-span call shape | source-compatibility note in the header | 761afe3 |
B5 nit: <ranges> doubles include cost |
concept over std::data / std::size from <span>; g++ 0.19 s on main / 0.40 with <ranges> / 0.35 with <iterator> / 0.19 as pushed; clang++ 0.23 / 0.58 / 0.44 / 0.23 |
761afe3 |
B6 nit: @param x, exponent |
two @param lines |
761afe3 |
B7 nit: hard-coded 6 |
DSPTAP_FFT_PROFILE_Q31_BFP + 1 |
772e69f |
B8 nit: @param / @return on the new capi declarations |
added | 772e69f |
B4 nit: unconditional dllexport |
deferred to Stage 6 as offered; listed under Deferred in the PR body | — |
Mutation proofs (typed TU rebuilt against a mutated include/, g++ -O3 -mfma -ffp-contract=off, CI's flags): M8 drop the exponent forwarding in fit_sine_tracked — passed 4/4 on a3639a5, now fails Q15Span… and Q31Span…; M7 ignore the exponent in fit_sine — fails the same two; M1 unit 1/(2^15 − 1) — fails both sine tests; M5 raw-integer read in the multitone prologue and M6 * 1.0 in the floating read — still pass, and the test file now says why each cannot be caught there.
Verification of the head: g++ 13.3 and clang++ 18.1 -DTAP_DSP_WERROR=ON -DTAP_DSP_BUILD_CAPI=ON -DTAP_DSP_BUILD_BENCH=ON 0 warnings, ctest 410/410 each; standalone cmake -B build_capi -S tools/capi warning-free; pre-commit clang-format and scripts/tidy.sh clean on the changed TUs; notebook executed from a clean kernel against 080862f with the pinned requirements (9 s), every §1–3 number unchanged, nine figures each stamped once, 1.07 MB of which 90 % PNG, no base64 arrays.
Generated by Claude Code
Review A finding 1: the "no output bit changed" sentences in README.md and fft.h's class docstring were unconditional while D9 two paragraphs down said x86-64 with -march was not measured. Now measured, and the D9 table in docs/fft-design.md carries the rows: g++ 13.3.0 -O3 -march=haswell keeps double at 0 ulp and moves basic_real_fft<float> at N = 1024, 4096, 16384, 65536 and 2^20 (a few float ulp relative to the block peak, 3.6e-7 in the review's harness); clang++ 18.1.3 at the same flags is identical for both; the -ffp-contract=off gate is 6/6 on both. Both sentences now say "at default contraction on every CI platform and on clang with FMA", name the g++ -march exception, and keep the MuTap fingerprint statement, which is measured at MuTap's flags. Review B finding 1: "the same number on the M55 / macOS backend legs" was false. The head's CI (run 35847675386) prints FloatEngineTracksDoubleAtN512 = 1.1236e-7 on cortex-m4-softfp and x86-64 and 1.1650e-7 on the VFMA legs cortex-m4f / m33 / m55; DoubleForwardTracksCompensatedDft = 1.8928e-16 on the M4 / M33 legs and 1.6643e-16 on the M55 against 1.8455e-16 on x86-64. Same engine, last bits moved by libm and contraction (D9), all inside the pins. The contract table, the README table and both test comments now carry the per-leg values with the run and job ids; the hosted legs run ctest non-verbose and print no value, which the table says. Review B finding 2: the "~3x fewer instructions on the M55 / ~3x faster on Apple Silicon" claims cited bench/README.md and the design note, which measure otherwise. The M55 figure is now the bench's own: on the m55 key the vendored C executes 1.81x (N = 512) / 1.97x (N = 2048) the CMSIS build's instructions over the whole ratchet scenario (run 35844483811, counts in the design note). The Apple figure is attributed to MuTap's transform-only measurement on the C (tap/MuTap#31) and marked not re-measured here (Stage 4). The host-microbenchmark paragraph says which claim went where. Nits: the port-vs-_port range is 0.00 - 0.26 % per the file's own tables (A2); the folded fixed-point record's "keeps growing with the stage count" was a unit artifact (A3, and #30's numerics review): re-measured on the header, the Q31 DC-path bias at index 0/1 is about 4 LSB at the constant exponent under both policies and flat in N (fixed 4 ... 9, BFP 3.5 ... 4.4 for N = 256 ... 65536); block floating point returns e 2 ... 6 bits under the constant there, so in its finer output LSB the same bias reads 14 ... 279, growing by the exponent gap, not with N. The compile-time cost of the flip is recorded beside the port record (B7): a TU including fft.h preprocesses to 81,042 lines against 78,558 on main; a TU instantiating both floating profiles compiles in g++ -O2 0.69 -> 1.73 s, -O0 0.68 -> 0.89 s, clang++ -O2 0.83 -> 1.36 s, -O0 0.75 -> 0.84 s (min of 5, this host), consistent with the review's independent numbers; D8 stands. No transform code changes: the fft.h and test diffs are comment lines only. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZPTzNxo5Fe4EtpXXKf7Sy
Review B finding 3. The section still called the fixed-point part of notebooks/fft.ipynb "a designed placeholder until Stage 3b/3c lands"; #30 (Stage 3c) fills it and hands this README sentence over in its body, since README is this PR's file this wave. Carried here as what the verification layer measures from #30 onward, cited to #30, and pointing at the fixed-point design record in docs/fft-design.md rather than the folded docs/fft-fixed-point.md. #31 merges first; #30 rebases onto it (merge-tree clean, disjoint hunks in tests/CMakeLists.txt). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZPTzNxo5Fe4EtpXXKf7Sy
What this changes
Stage 3c of
docs/audit-fft-and-code-smells.md(Part 3; Part 8 item 6): the verification layer reaches the Q15 / Q31 profiles that Stage 3b (#27) shipped. Five commits, one per surface plus the CI fix, followed by the review fix pass (four commits, see the end of Verification):float/double/std::int16_t/std::int32_t(sine_analysis.h,multitone_analysis.h):fit_sine,fit_sine_tracked,program_weighted_snr_dbread integer samples as Q0.15 / Q0.31 fractions throughsample_traits<Sample>::k_sample_frac_bits. A range template (span, vector, array, C array all deduce; the concept is spelled overstd::data/std::size, which<span>provides, so the header pulls neither<ranges>nor<iterator>and its compile cost is main's) rather than a barestd::span<const Sample>so no consumer call site changes (the one shape that no longer deduces, a braced span built in the call, is documented; no caller in DspTap or MuTap uses it). The two sine fits take an optional scale exponent for fixed-point FFT output: the fit is reported forx · 2^e(the three magnitude fields scaled after the fit, an exact power of two; phase and frequency invariant).program_weighted_snr_dbtakes no exponent: its result is a ratio a power-of-two scale cannot move. How the read is done is stated in the header because bit identity depends on it: a floating sample enters as the barestatic_cast<double>it always did (no multiply, not even by 1.0), an integer sample as its exact fraction; the hot loops are the same plain double loops; the joint-fit internals are untouched.tools/capi):DSPTAP_FFT_PROFILE_Q15/_Q31un-reserved (fixed scaling),_Q15_BFP/_Q31_BFPappended (block floating point). Every existing value and signature unchanged, and the file-level 0 / −1 return convention kept (dated changelog line in the header).dsptap_fft_createrefuses a fixed-point size above the header'sk_max_size(65536, read from the header) instead of handing out a handle the header asserts against. Plus a C smoke test (dsptap_capi_smoke, built with the root tests, next to the DLL).dsptap_py.RealFFT: profiles"q15","q31","q15_bfp","q31_bfp";forward/inversereturn float64 already scaled by 2^e (the double profile's units),last_exponent/forward_with_exponent;forward_inplace_raw/inverse_inplace_rawon the native dtype now return e (they returned the buffer; 0 for the floating profiles) and require an aligned buffer, as the ABI does;to_native/from_nativeare the boundary's quantization and reading;exponent_bound; a cleanValueErrornaming the fixed-point size bound.notebooks/fft.ipynbre-executed (§4 replaces the placeholder; every figure stamped once with pin SHA, host, compiler, backend, date; 1.07 MB, 90 % PNG, fixed seeds;requirements.txtunchanged).a3639a5, see Verification): the typed-instrument battery lives in its own TU and target,tests/test_analysis_typed.cpp/tap_dsp_analysis_typed, carrying-ffp-contract=offexactly as the Stage 2a Ooura parity gate does (its own block appended at the end oftests/CMakeLists.txt);test_analysis.cppis back to its pre-3c content.The exponent's path through the ABI (documented in
dsptap_capi.hinfft.h's terms)dsptap_fft_forward/_inverse(double I/O)round_sat(half away from zero, saturating at ±full scale), transform, output = native result as fractions × 2^e → directly comparable to the DOUBLE profile on the same quantized input. The inverse carries no 2/N (unnormalized,out == G.inverse_inplace(a_q)); a forward result × 2^e can exceed [-1, 1), so the double round trip is the raw path's job (stated).dsptap_fft_forward_exp/_inverse_exp(new)*exponent = 0*exponent = e; 0 / -1 statusdsptap_fft_forward_inplace_raw/_inverse_inplace_raw(existing)@returnin the header)dsptap_fft_forward_inplace_raw_exp/_inverse_inplace_raw_exp(new)*exponent = 0*exponent = e— the binding pathdsptap_fft_fixed_scaling_exponent(new)fixed_scaling_exponent(N): the constant / BFP upper bounddsptap_fft_sample_bytesdsptap_fft_backendPacking, exp(+i) sign, the size bound and the round-trip identity
x == out · 2^(e_fwd + e_inv + 1 − log₂N)are restated at the profile codes.Why
Until now the notebooks could not measure the fixed-point profiles at all, the capi returned NULL for them, and the instruments could score only floating tails. Part 8 item 6 asks for the executed notebook to carry the Q15/Q31 floors under Welch's model, the BFP exponent on speech-like material and the backend comparison; Part 3 Stage 3c asks for the instruments to score Q15/Q31 output.
Verification
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DTAP_DSP_WERROR=ON -DTAP_DSP_BUILD_CAPI=ON -DTAP_DSP_BUILD_BENCH=ON→ build →ctest: 410/410 on g++ 13.3 and on clang++ 18.1 (Ubuntu 24.04), includingdsptap_capi_smokeand thetap_dsp_analysis_typedtarget. Standalonecmake -B build_capi -S tools/capi(what the bridge runs) builds warning-free. pre-commit clang-format passes;scripts/tidy.shclean on the changed TUs.35a3150: macOS arm64 failedFloatingSpansAreBitIdenticalToThePreTemplateInstrumentby one ulp ofresidual_rmsin the tracked float fit; Windows failed to compile the multitone test (C4244 under /WX). Both fixed ina3639a5. The ulp: the first typed read multiplied every sample by an exact power-of-two step (1.0 for floats), and a product feeding a subtraction contracts into a fused multiply-subtract where a plain operand does not. Beyond that, GCC's default-ffp-contract=fastfuses across statements by inlining/unrolling context, so two textually identical functions can differ by an ulp on FMA hardware — reproduced locally withg++ 13 -O3 -mfmaon the sub-span and tracked fits (amplitude and phase each move one ulp); clang (onandfast, per-expression) and MSVC (no contraction) agree bit for bit. Hence the parity-gate pattern: the typed battery's own target with-ffp-contract=off, under which it is bit-identical by construction on every host (verifiedg++ -mfma -ffp-contract=off,clang++ -mfma -ffp-contract=fast). The header states exactly this: bit-identical under-ffp-contract=offand on per-statement-contracting compilers, ≤ 1 ulp under GCC's default on FMA hardware, measured.tests/test_analysis_typed.cpp): the float and double instantiations are bit-identical to verbatim copies of the pre-template instruments in the same binary (a same-host A/B, since a golden hash would fail across the CI hosts' libms by design, Part 13). The Q15 / Q31 instantiations equal the double instrument on the same fractions bit for bit and agree with it on the unquantised signal to the quantisation noise: measured 2026-09-23, 0.5 full-scale tone at 997 Hz / 48 kHz, 16384 samples: Q15 residual 0.2886 LSB rms (1/√12 = 0.2887), SNR 92.07 dB (theory 92.06), amplitude / DC within 1.69e-3 / 2.60e-3 LSB of the exact-signal fit; Q31 0.2873 LSB rms, 188.44 dB (theory 188.39), 2.04e-4 / 2.58e-3 LSB; program-weighted SNR on the quantised pink comb Q15 83.86 dB, Q31 180.15 dB. Pinned at 2× / −0.5 dB / −1 dB with the date and host. The exponent pin:fit_sine(q, nu, e)andfit_sine_tracked(q, nu, e)equal their exponent-0 fits with the magnitude fields × 2^e, and equal the fit of the pre-scaled fractions in every field, bit for bit. Two things the battery does not prove are stated in it: the "no multiply by 1.0" rule is enforced by the A/B only under the target's flags, and the multitone integer-read equality is vacuous (the metric is exactly scale-invariant; the sine tests pin the fraction read).[ floor ]linestests/test_fft_fixed.cppprints underctest -V, recorded 2026-09-18 in the fixed-point design record indocs/fft-design.md, §5; what the battery pins is the maximum measured/model ratio per configuration and the output fingerprints). Same generators, same inputs, through the ABI's raw path:Largest measured/model ratio (noise, tone) vs the pin: q15 1.055 / 0.022 (pins 2.11 / 0.044), q31 1.744 / 0.383 (3.49 / 0.77), q15_bfp 1.041 / 0.535 (2.09 / 1.07), q31_bfp 2.321 / 0.644 (4.65 / 1.29) — exactly half the pins, i.e. the battery's own values. No disagreement. All sixteen pinned output fingerprints (
OutputFingerprintIsPinned) reproduce through the ABI (§4.5).fft/fixed_point.h: the bias is held, not outgrown. §4.3: on synthesized speech-like material the BFP exponent is 0 up to a block peak of −24.8 dBFS for Q15 BFP (first shift at −31.6) and −35.7 dBFS for Q31 BFP (first shift at −42.2), 3 – 5 / 2 – 4 bits under the constant on the loud blocks; on the 14 quiet-syllable blocks (−50 … −30 dBFS) block-floating Q15 holds 76.9 dB median per-bin SNR where fixed Q15 holds 24.3 dB (the 30 pauses at the −60 dBFS floor: 54.8 vs 1.5 dB).a3639a5):761afe3(concept without<ranges>, sample concept restricted to the four types, bit-identity wording with its flags, tracked-fit exponent pin, honest comments on what the A/B and the multitone pin cannot prove),772e69f(capi size bound, legacy raw pair back on 0 / −1,@param/@return, smoke-test checks),080862f(bridge alignment check and bound message), and the notebook commit (three overprinted stamps fixed, citations moved todocs/fft-design.md's fixed-point design record, §4.2 / §4.3 / §4.4 / Summary restated in both units and per profile, bridge guards smoked in §4.0). Mutation proofs on the typed TU (rebuilt against a mutatedinclude/with CI's flags): dropping the exponent forwarding infit_sine_trackedpassed all four tests before and now fails both sine tests; ignoring the exponent infit_sinefails the same two; a raw-integer read in the multitone prologue and a* 1.0in the floating read still pass, and the test file says why. The notebook was executed against080862ffrom a clean kernel with the pinnedrequirements.txt; every §1–3 number is unchanged, and the only §4 outputs that changed are the added columns and rows.Notes for the reviewer
docs/fft-fixed-point.mdand folds it intodocs/fft-design.mdas The fixed-point profiles: design record; nothing in this PR references the old file. The Stage 2b: route the real FFT to the split-radix port; README and design note rewritten #31 fix pass aligns the design record's DC-bias sentence with §4.2's units; this PR touches no docs.forward_inplace_raw/inverse_inplace_rawnow return e instead of the buffer (documented; no committed notebook used the return value).fft.ipynb(§4 filled, §1–3 re-run with the stamp; numbers unchanged).pitchshift.ipynbuntouched (no FFT profile change).notebooks/fft.ipynbalso measures the four fixed-point configurations ("q15","q31","q15_bfp","q31_bfp"indsptap_py.RealFFT, the exponent returned with every transform): the noise-floor table of the fixed-point design record indocs/fft-design.mdre-measured through the ABI beside the battery's pins, the DC-path bias to N = 65536 in both units, the block-floating exponent on speech-like material, and the battery's output fingerprints reproduced through the ABI;sine_analysis.h/multitone_analysis.hnow score Q15 / Q31 spans directly."void*handles, un-annotated older entry points and the unconditionaldllexporton Windows (Stage 6); the backend comparison (§5, Stage 4).🤖 Generated with Claude Code
https://claude.ai/code/session_019ZPTzNxo5Fe4EtpXXKf7Sy