Files
ClaudeandКирилл Сапфиров c8d571bd22 Felucca 1.6.1
MENU > LARGE keeps one size per knob (#251): each knob shows all its
values in the size its longest value fits, so a value no longer jumps
between sizes while it is turned. No new fonts.

Updates check the package's size on the device: the update entry and the
update loader take only a package whose firmware area is exactly the
FM-1's. Another device's package is refused before anything is erased
(the update screen shows FAILED -15; the loader answers -14).

Second core (beta, PR #247): MENU > SYSTEM > 2ND CORE, OFF by default.
ON (BETA) applies from the next power-on: the second core renders some
of the four parts of each block, bit for bit the one-core sound. A unit
whose second core misreads goes on with one core and sets it back to
OFF. FELUCCA_CPU2=0 builds none of it. Start, mailbox and guards from
X0X (with Melodee's dual-core findings), the split and hardening after
Jangada.

Felucca-Engines: ANALOG, LOFI, TRIO, WHEEL and NOISE, the engine
interface, the shared DSP helpers and their table generator move to
https://github.com/hugelton/Felucca-Engines under the MIT licence,
included as the git submodule firmware/engines. The firmware stays
GPL-3.0-only; clone with --recurse-submodules. The sound is unchanged
(the same golden renders); the engines' own tests run with Felucca's.

Co-authored-by: Кирилл Сапфиров <gospodindilly@gmail.com>
2026-10-17 19:04:28 -03:00

73 lines
3.3 KiB
Python

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments
"""The polyphase FIR of the USB audio input's 44.1 -> 48 kHz resampler (src/usb.c, FELUCCA_UAC_48K).
48000 / 44100 = 160 / 147: up by L = 160, low-pass, down by M = 147. Output frame k sits at input time
k * 147 / 160: phase p = (k * 147) % 160, newest input frame floor(k * 147 / 160). Each phase is N taps of
the prototype (a Kaiser-windowed sinc of 160 * N taps at 7.056 MHz, cut-off FC):
y[k] = sum_j PROTO[p + 160 j] * x[base - j], j = 0 .. N-1
The table holds the taps oldest input first (UAC_FIR[p][i] = L * PROTO[p + 160 (N-1-i)]), Q30, and only the
phases 0 .. 79: the prototype is symmetric, so phase 159 - p is phase p read backwards. Each phase's taps sum
to exactly 1 << 30 (unity gain at DC, the rounding left on its largest tap).
Why these numbers (tests/uac_test.c measures them on the C code):
N = 24, FC = 22 kHz, beta 9: images that would fold below 20 kHz (input above 28.1 kHz at 7.056 MHz) are
down 90 dB, the passband is flat within 0.06 dB to 18 kHz (-1.2 dB at 20 kHz); with Q30 taps the 1 kHz SNR
sits at the 16-bit floor (~94 dB at -1 dBFS); Q15 taps would cap it near 87 dB.
tools/gen_uac_fir.py [OUT] (default firmware/src/uac_fir.h); numpy only."""
import sys
from pathlib import Path
import numpy as np
L, M, N = 160, 147, 24
FC, BETA, QB = 22000.0, 9.0, 30
FS = 44100.0
def prototype():
n = L * N
t = np.arange(n) - (n - 1) / 2.0
fc = FC / (FS * L) # cycles per sample at the up-sampled rate
h = 2 * fc * np.sinc(2 * fc * t) * np.kaiser(n, BETA)
return h / h.sum() * L # DC gain L: unity after the zero stuffing
def table():
h = prototype()
tab = np.zeros((L, N), dtype=np.int64)
for p in range(L):
c = h[p::L][::-1] # oldest input first
q = np.round(c * (1 << QB)).astype(np.int64)
q[np.argmax(np.abs(c))] += (1 << QB) - q.sum()
tab[p] = q
for p in range(L // 2): # the symmetry the C code relies on
assert (tab[L - 1 - p] == tab[p][::-1]).all() or np.abs(tab[L - 1 - p] - tab[p][::-1]).max() <= 1
return tab
def main():
out = Path(sys.argv[1] if len(sys.argv) > 1 else Path(__file__).resolve().parents[1] / "src" / "uac_fir.h")
tab = table()
lines = [
"/* SPDX-License-Identifier: GPL-3.0-only",
" * Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */",
"/* generated by tools/gen_uac_fir.py: do not edit. The 44.1 -> 48 kHz polyphase FIR of the USB",
f" * audio input (usb.c): L {L}, M {M}, {N} taps per phase, Kaiser beta {BETA:g}, cut-off {FC:g} Hz, Q{QB};",
f" * phases 0..{L // 2 - 1} (phase {L - 1} - p = phase p backwards), taps oldest input first. */",
f"#define UAC_FIR_L {L}u",
f"#define UAC_FIR_M {M}u",
f"#define UAC_FIR_N {N}u",
f"#define UAC_FIR_Q {QB}",
f"static const int32_t UAC_FIR[{L // 2}][{N}] = {{",
]
for p in range(L // 2):
lines.append(" {" + ", ".join(str(int(v)) for v in tab[p]) + "},")
lines.append("};")
out.write_text("\n".join(lines) + "\n")
print(f"wrote {out}: {L // 2} x {N} taps, {L // 2 * N * 4} B")
if __name__ == "__main__":
main()