Repository navigation
Render pipeline chunk 5: sample-rate conversion in the daemon, and afconvert retires - #57
Merged
Merged
Conversation
Decisions 9 and 10 recorded with the evidence behind both. The resampler is a fixed-ratio polyphase FIR with a Kaiser-windowed sinc prototype whose stopband edge sits at the lower of the two Nyquist frequencies, which is what makes one routine correct in both directions. Measured: passband flat to ±0.0000 dB from 100 Hz to 19 kHz and −0.009 dB at 20 kHz; downsampling 96k to 44.1k rejects a 23 kHz tone by 103 dB and everything above it by 113 to 119; lengths exact; a 1:1 ratio returns the input bit-for-bit rather than filtering it. JUCE's WindowedSinc was rejected on evidence rather than preference. interpolateImpl advances pos by speedRatio against a kernel whose width never depends on speedRatio, so downsampling filters at the input Nyquist and folds everything above the output Nyquist back into the band. The §3 table said "probably usable"; it is not usable for half our conversions, and now says so. Dither is 1-LSB TPDF from a written-out splitmix64, not <random>, because mt19937 paired with uniform_real_distribution is not specified to give the same sequence on libstdc++ and libc++ — which would make every rendered artifact platform-dependent. Nothing calls this yet; the normalize op and the generators follow.
say.ts held the second afconvert call — the AIFF that macOS say emits, converted to a WAV at the project rate. Chunk 5 can delete the first one by putting a resampler in the daemon, but not this one: our WAV reader does not read AIFF, so keeping the rule meant teaching the daemon a second container format for one macOS-only rule, or keeping afconvert for that rule alone. Either way the macOS dependency the chunk exists to remove survives. So the rule goes. That retires all nine platform-guarded tests rather than the three a resampler alone would free, and it removes the last macOS-only rule from the graph. This overturns voice-generation.md decision 1, which had say staying as the hermetic in-graph recipe opposite the generated tier, so §5 there records what changed rather than diverging quietly — including the cost, which is real: that plan is deferred and not started, so bloom's creek loses the source for its lead-vocal clips and its vocal-96k normalize until something replaces it. An imported recording is the stopgap, which is what a scratch vocal is anyway. Docs split by kind: build-graph.md and project-model.md describe current design and are corrected; the plans get dated amendments. build-graph.md keeps a short tombstone because say was its illustration of the hermetic side of the determinism boundary — and a slightly false one, since voice: Siri followed a Settings toggle the action key could not see.
The op takes rate and depth and nothing else: resample in full precision, then quantize once at the end. Quantizing first would put the dither through the resampler's filter, colouring it and defeating the point. RENDER_PLAN_VERSION goes to 3, writeWavInt handles the 16- and 24-bit targets, and the bit-depth set is generated from zod alongside the rate set rather than copied — a partial copy of a schema is schema drift (#54). normalize's rule_version goes to 2 and its artifacts re-render once. This is the only rule in the migration whose output is not byte-identical to what it replaced, and the reason is structural: every other chunk transliterated a TypeScript reference and could prove equality against it, while this one displaced a macOS binary there was never any way to diff against. With no oracle, the properties are the entire specification, so they were mutation-tested before being trusted. Filtering at the input Nyquist rather than the lower of the two — the JUCE failure mode from decision 9 — folds a 30 kHz tone into a 44.1 kHz file at 14.1 kHz and 0 dB; the aliasing property catches it and nothing else does. Removing the dither leaves a sub-LSB signal quantizing to digital black; one property catches that and nothing else does. The other five stayed green both times. The three afconvert guards are gone and src/testing/platform.ts with them: with say already removed, both probes had no callers, and a file of nothing but tombstones is worse than none. Nothing in the build shells out to a macOS binary any more. Also fixes the pre-existing -Wfloat-equal in validateSampleRate rather than adding a second instance of it: checkObject has already proved the value is an integer, so set membership is an integer question.
ninjudd
commented
Aug 8, 2026
ninjudd
commented
Aug 8, 2026
ninjudd
commented
Aug 8, 2026
ninjudd
commented
Aug 8, 2026
ninjudd
commented
Aug 8, 2026
ninjudd
commented
Aug 8, 2026
ninjudd
commented
Aug 8, 2026
#57 review, seven findings, all correct. P1: bit_depth: 32 had regressed from integer PCM to IEEE float. afconvert was asked for LEI32 and linux-portability decision 1 says that float-to-integer conversion stands, so writing format tag 3 changed the meaning of an existing schema value under a version bump that only claims to change bytes. writeWavInt handles 32 now, undithered — its step is about 186 dB down, finer than the float32 input can resolve. The reason it slipped is the more useful half: the grid test cannot see which writer ran, because a decoded sample sits on the same grid either way. Routing 16-bit through the float writer left all six properties green. The properties now read the format tag and width directly. Three more coverage holes, each reproduced before fixing and each now failing exactly one property: taps 128 to 32 dropped 19 kHz by 16 dB with only a 1 kHz probe watching; replacing the input sample with the dither alone passed a test that only asserted nonzero samples existed; flooring outN turned a two-frame 96 kHz source into an empty 44.1 kHz file, where afconvert produced one frame. Odd data chunks are now word-aligned. Only reachable at 24-bit mono with an odd frame count, so the stereo golden could not exercise it — and our own reader already advanced by size + (size % 2), so the writer was out of step with its own reader. Docs: the plan's open questions are closed rather than left contradicting its Shipped status, and stem.ts no longer tells users to fix a rate mismatch with afconvert — a tool this PR deletes and that Linux never had. The golden is unchanged, which is the expected result rather than a lucky one: it is 24-bit stereo at an integral length, so it touches none of the three paths that moved.
ninjudd
commented
Aug 8, 2026
ninjudd
commented
Aug 8, 2026
ninjudd
commented
Aug 8, 2026
…acts that hid the P1 #57 second review, three findings, all correct. P2: readWavHeader copied the outer fmt tag, so every WAVE_FORMAT_EXTENSIBLE file reported 65534 while readWav decoded the same bytes as PCM — two readers in one module disagreeing about one file, and wrong for a format this module explicitly supports. It now resolves the SubFormat tag at body + 24 as readWav does. The existing extensible fixture covers the header path too, and reverting the resolution fails it with the reviewer's exact 65534. The metadata was new in this PR, which is what made it wrong rather than merely absent: `format` is documented as the actual encoding, so resolving extensible is part of that contract and not an extra. P3: the DSP contracts still described the float path. resample.h said 32 was a no-op because output is float; wavfile.h and wavfile.cpp said the writer handled 16 and 24 and that every input arrived pre-quantized. All three now say what is true: integer PCM at all three depths, quantized in ditherTo at 16 and 24 where the dither is, and in the writer at 32 where it is deliberately undithered. Worth doing carefully — this is the exact contract area whose vagueness let the P1 through. P3: "all answered" was false. The --no-native subset question is still open, so §7 says so and the status line says so, the way linux-portability's does.
ninjudd
added a commit
that referenced
this pull request
Aug 11, 2026
…urce, the converter's lifecycle minjudd measured the claim the plan led with and it was false: no cross-rate session has ever compiled, clean or dirty — the all-tracks rate check refuses the song before the freeze could serve the cached conversion — so §1 now says what actually exists (the graph routing) and counts three gaps, cheapest first. The refusal count is three, not two: the engine's own constructor guard joins the list and decision 1 names its replacement. The output-length rule gains its empty-source branch (zero in, zero out — the #57 lesson the floor-at-one exists for). The delivery converter gets a specified lifecycle across locate, stop, swap, and natural end, plus a recorded heard-position bound. And realtime.md decision 7 gains the amendment reconciling its delay-compensation clause with the aligned materialized edge.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Chunk 5, and the last of this plan. Sample-rate conversion moves into the daemon's built-in tier,
normalizerenders through it,sayis deleted, and nothing in the build shells out to a macOS binary any more.The resampler
Fixed-ratio polyphase FIR, Kaiser-windowed sinc prototype, 128 taps per phase. The six project rates are pairwise rational with small denominators — 44.1→48k is exactly 160/147 — so every conversion field supports has precomputable per-phase coefficient rows. The stopband edge sits at the lower of the two Nyquist frequencies, which is the one detail that makes a single routine correct in both directions.
Measured on the built binary:
JUCE's
WindowedSincwas rejected on evidence, not preference.interpolateImpladvancespos += speedRatioagainst a kernel whose width never depends onspeedRatio. Downsampling therefore filters at the input Nyquist and folds everything above the output Nyquist back into the band — not a quality difference but aliasing, and disqualifying for half the conversions the schema permits. The §3 table said "probably usable"; it now says why it is not.The one rule that is not byte-identical
Every prior chunk transliterated a TypeScript reference and could prove equality against it, so all of them landed with no
rule_versionbump and no re-render. This one displaced a macOS binary there was never any way to diff against, sonormalizegoes toversion: 2and its artifacts re-render once. That is the cost chunks 2 and 3 priced and did not incur, arriving here instead.With no oracle, the properties are the specification
So they were mutation-tested before being believed. Six properties, measured through the build rules:
resample.cpptpdf = 0.0(no dither)Each mutation is caught by exactly one property, which is what says they carry distinct weight rather than overlapping.
The normalize golden downsamples 96k→44.1k at 24-bit deliberately: that is the direction with the anti-alias filter engaged, and it puts the dither sequence in the hashed bytes. Designing the prototype calls libm
sinseveral thousand times, so the digest is also the check that Apple's libm and glibc still agree.sayis deletedsay.tsheld the secondafconvertcall — the AIFF macOSsayemits, converted to a WAV at the project rate. Our reader does not read AIFF, so keeping the rule meant teaching the daemon a second container format for one macOS-only rule, or keepingafconvertfor that rule alone. Either way the dependency survives.This overturns
voice-generation.mddecision 1, which hadsaystaying as the hermetic in-graph recipe opposite the generated tier, so §5 there records what changed rather than diverging quietly — including the cost, which is real: that plan is deferred and not started, so bloom's creek loses the source for its twolead-vocalclips and itsvocal-96knormalize until something replaces it. An imported recording is the stopgap, which is what a scratch vocal is anyway.Deleting it means all nine platform-guarded tests retire rather than the three a resampler alone would have freed.
src/testing/platform.tsgoes with them: both probes had no callers left, and a file of nothing but tombstones is worse than none.Also
The bit-depth set is generated from zod alongside the rate set rather than copied, following #54's rule that a partial copy of a schema is itself schema drift. And the pre-existing
-Wfloat-equalinvalidateSampleRateis fixed rather than duplicated —checkObjecthas already proved the value is an integer, so set membership is an integer question. The native build is warning-free in our own sources again.Review round (7 findings, all correct)
P1 —
bit_depth: 32had regressed from integer PCM to IEEE float.afconvertwas asked forLEI32, and linux-portability decision 1 says that float-to-integer conversion stands, so writing format tag 3 changed the meaning of an existing schema value under a version bump that only claims to change bytes.writeWavInthandles 32 now, undithered — its step is ~186 dB down, finer than the float32 input can resolve.It slipped because a decoded sample sits on the same grid whichever writer ran, so the grid test could not see the writer selection at all.
WavHeadernow exposesformatandbitsPerSampleand the properties assert both.Four coverage holes, each reproduced before fixing, each now failing exactly one property while the other eight stay green:
tapsPerPhase128 → 32outNflooredTwo more in the code. A two-frame 96 kHz source floored to an empty 44.1 kHz file — a one-shot vanishing under a successful action key, where afconvert produced one frame; the rule is now round-half-up with a one-frame floor for any non-empty source. And odd
datachunks went unpadded, which only 24-bit mono with an odd frame count can reach — our own reader already advanced bysize + (size % 2), so the writer was out of step with its own reader.Two doc findings, both stale in opposite directions: the plan's open questions contradicted its own Shipped status, and
stem.tstold users to fix a rate mismatch withafconvert— a tool this PR deletes and Linux never had.The golden is unchanged, which is expected rather than lucky: it is 24-bit stereo at an integral length, so it touches none of the three paths that moved.
Verification
346 tests pass,
pnpm typecheckclean, native build clean and warning-free in our own sources.RENDER_PLAN_VERSIONis 3.