mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-06 04:44:33 +01:00
The 0.8.7 field test (FM-1, CORES 2, LOAD FULL, a heavy 160 BPM song, USB CONSOLE captured at 48 kHz): USB audio on raised CPU 65.5 -> 77 %, late halves 15 -> 50 /s, ~230 underruns /s, captures 10-20 % short. - Root cause (audio.c): the ALNK0 ISR acknowledged a half after rendering it, so a render that ran past its half cleared the next half's pending flip and that half was never rendered (the DAC replayed 2.9 ms of old audio; USB got 128 frames fewer). Every "late" half lost the next: ~14 % of the audio with USB on, the ring always dry (adj_down saturated, ~230 underruns /s). Now the half is acked first: a late render is followed at once by the next, which catches up glitch-free (the DMA reads the half behind the render); a half is lost only past ~1.7 halves, counted in the console's new audio_lost. - usb.c, the packets: every packet still carries n +- 1 frames (an underrun repeats the last frame, never drops or shortens it); the repeated frames are now owed and made up (one ring frame skipped a packet while the ring is healthy, uac_repeats_made_up), so a capture keeps the music's length and timing. Bands 0.7 ms higher for renders that now start up to ~1 ms late (44.1: 112..160, 48: 128..176). - usb.c, the resampler: uac_rs_run, in RAM (.c1_text) calling nothing, its 160 phases in a RAM table (pool, 15 KiB) built from the flash's, four taps a pass: bit for bit 0.8.8's. With CORES 2 each half goes to core 1 at the render's end (uac_render_end) and enters the ring when the next half starts (uac_collect; mix_block's first job queues behind it, so its wait covers it); one core: per block in the ISR as before. Core 0's share at 48 kHz: ~21 instructions an input frame (the 16-bit store) against ~270 (resampling) before: ~11 CPU points -> ~1 (estimate, to confirm on the device); CORES 1 ~20 % fewer instructions and no flash table reads. - uac_fir.h (tools/gen_uac_fir.py): the 80 phases stored as each tap's third differences (int16), summed back exactly (UAC_FIR_CHK): 7680 -> 3984 B. - voice.c / console: voices_given_up counts each voice once (one already fading not again) and splits into voices_trimmed (load-budget tails under -50 dB: inaudible, most of the field test's 670 /s), voices_stolen and voices_shed. - Tests: tests/uac_sched_test.c (new; one core and CORES 2): 3 min against a simulated 48 kHz host at +-500 ppm, renders as the heavy song's (~17 late /s, up to 131 %): every IN token finds a packet, sizes 47..49, no underrun / overrun / jump, frames sent = frames resampled exactly, no latency drift; starvation bursts (renders 150..190 %, halves lost): underruns repeated and all made up; IRQs off 4 ms: ~3 empty frames each, recovered. LEGACY=1 shows the 0.8.8 order: ~245 underruns /s, 12.4 % of the music missing at ~43 late /s (the field test's figures). uac_test: the RAM table exactly the generator's, bit for bit 0.8.8's resampler (10 s at +-2x full scale), THD / aliasing spurs < -98.9 dB (1 k .. 22 kHz). audio_test: the ack before the render, audio_lost. - Image 568320 -> 565384 B (-2936 B); RAM code +328 B (22440 of 24576), pool +16 KiB (36 KiB spare). Goldens, CPU baselines unchanged; target budget: uac_tap48 -> uac_rs_run (static 558: the unrolled body). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh