Version 3.2.2: in-memory replacements fill their slots exactly (padded ones played as silence)

This commit is contained in:
2026-10-11 00:10:44 +02:00
parent cac52e7597
commit b6b96307ca
16 changed files with 223 additions and 52 deletions

View File

@@ -25,6 +25,16 @@ def wem(seconds, freq, rate=24000, ch=1):
return encoder.encode(x, sr, rate, ch)[0]
def fitting_wem(ws, s, seconds, freq):
"""A tone WEM that `ws` accepts for `s` (Workspace.fits: in-memory slots are filled exactly, which needs
an even number of spare bytes): the tone is shortened a little until the size allows it."""
for k in range(40):
w = wem(seconds * (1 - 0.01 * k), freq)
if ws.fits(s, w):
return w
raise AssertionError("no fitting WEM for %s" % s.key)
def _a(x, n):
return (x + n - 1) // n * n