Include xombe source directly in repository instead of submodule

This commit is contained in:
root
2026-11-28 12:55:14 +01:00
parent d84d82617e
commit 3461bec633
303 changed files with 29260 additions and 4 deletions
File diff suppressed because it is too large Load Diff
+48
View File
@@ -0,0 +1,48 @@
#!/bin/sh
# fetch_librispeech.sh [OUT]: four LibriSpeech dev-clean-2 utterances as 8 kHz raw at -26 dBov
# (OUT defaults to build/librispeech in the source tree), needs curl, sox, and a Python with numpy and scipy
set -eu
ROOT=$(cd "$(dirname "$0")/.." && pwd)
OUT=${1:-$ROOT/build/librispeech}
PY=${PYTHON:-python3}
URL=https://www.openslr.org/resources/31/dev-clean-2.tar.gz
SHA256=176ec501490eced2d6c1f89f4f0ddc7dfe799e649e5322f8ba49fe3ff50c8012
for t in curl sox; do
command -v $t > /dev/null || { echo "$t not found" >&2; exit 1; }
done
if command -v sha256sum > /dev/null; then
sha() { sha256sum "$1"; }
elif command -v shasum > /dev/null; then
sha() { shasum -a 256 "$1"; }
else
echo "sha256sum or shasum not found" >&2; exit 1
fi
"$PY" -c 'import numpy, scipy' 2> /dev/null || { echo "$PY has no numpy or scipy (set PYTHON)" >&2; exit 1; }
mkdir -p "$OUT"
cd "$OUT"
if [ ! -f dev-clean-2.tar.gz ]; then
curl -L -o dev-clean-2.tar.gz.part "$URL"
mv dev-clean-2.tar.gz.part dev-clean-2.tar.gz
fi
digest=$(sha dev-clean-2.tar.gz | cut -d' ' -f1)
[ "$digest" = "$SHA256" ] || { echo "unexpected SHA-256 $digest for dev-clean-2.tar.gz" >&2; exit 1; }
for spec in lsf1:2035-147960-0000 lsm1:6295-244435-0010 lsm2:1272-135031-0010 lsf2:84-121550-0001; do
name=${spec%%:*}
utt=${spec#*:}
spk=$(echo "$utt" | cut -d- -f1)
chap=$(echo "$utt" | cut -d- -f2)
member=LibriSpeech/dev-clean-2/$spk/$chap/$utt.flac
tar -xzf dev-clean-2.tar.gz "$member"
sox "$member" -r 8000 -b 16 -e signed-integer -c 1 -t raw "$name.raw" rate -v
"$PY" - "$ROOT/tools" "$name.raw" <<'PYEOF'
import sys
sys.path.insert(0, sys.argv[1])
import numpy as np
from common import p56
x = np.fromfile(sys.argv[2], '<i2').astype(float)
y = np.clip(np.round(x * 10 ** ((-26.0 - p56(x)) / 20)), -32768, 32767).astype('<i2')
y.tofile(sys.argv[2])
print('%s: %.1f dBov' % (sys.argv[2], p56(y)))
PYEOF
done
echo "wrote lsf1.raw lsm1.raw lsm2.raw lsf2.raw to $OUT"
+142
View File
@@ -0,0 +1,142 @@
#!/usr/bin/env python3
"""writes src/tables/cq_q15_tables.c, the q15 closed-loop quantizer's int16 images of the PRBA codebooks"""
import os
import re
import struct
ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
OUT = os.path.join(ROOT, 'src', 'tables', 'cq_q15_tables.c')
SETS = [ # name, file, prba24, prba58, ok_prba24, ok_prba58
('ambe2', 'tables.c', 'xombe__prba24', 'xombe__prba58', None, None),
('dstar', 'dstar_tables.c', 'xombe__ds_prba24', 'xombe__ds_prba58', 'xombe__ds_ok_prba24', 'xombe__ds_ok_prba58'),
]
PAIRS24 = [(0, 0), (1, 1), (2, 2), (0, 1), (0, 2), (1, 2)]
PAIRS58 = [(0, 0), (1, 1), (2, 2), (3, 3), (0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]
def fl32(x):
return struct.unpack('f', struct.pack('f', x))[0]
def f32(x):
"""x rounded to the nearest float, printed to read back exactly"""
v = fl32(x)
s = '%.9g' % v
if 'e' not in s and '.' not in s:
s += '.0'
return s + 'f'
def f32_up(x):
"""the smallest float >= x, x >= 0"""
v = fl32(x)
if v < x:
v = struct.unpack('f', struct.pack('I', struct.unpack('I', struct.pack('f', v))[0] + 1))[0]
return v
def table(src, name, cols):
body = re.search(name + r'\[\d+\]\[%d\] = \{(.*?)\};' % cols, src, re.S).group(1)
v = [fl32(float(t.rstrip('f'))) for t in re.findall(r'[-+0-9.eE]+f', body)]
return [v[i:i + cols] for i in range(0, len(v), cols)]
def mask(src, name, n):
if not name:
return [1] * n
body = re.search(name + r'\[%d\] = \{(.*?)\};' % n, src, re.S).group(1)
return [int(t) for t in body.replace(',', ' ').split()]
def rnd(v):
"""nearest integer, halves away from zero: |v - rnd(v)| <= 1/2"""
return int(v + 0.5) if v >= 0 else -int(-v + 0.5)
def scale(maxabs):
"""largest t with maxabs * 2^t <= 32767"""
t = 0
while maxabs * 2.0 ** (t + 1) <= 32767:
t += 1
while maxabs * 2.0 ** t > 32767:
t -= 1
return t
def image(rows, pairs, words):
"""monomials x_a x_b (a < b doubled) at 2^-tm, then x at 2^-tx, as int16 pairs padded to words"""
dim = len(rows[0])
mono = [[(1.0 if a == b else 2.0) * r[a] * r[b] for a, b in pairs] for r in rows] # exact in double
tm = scale(max(abs(v) for m in mono for v in m))
tx = scale(max(abs(v) for r in rows for v in r))
ints = []
for r, m in zip(rows, mono):
h = [rnd(v * 2.0 ** tm) for v in m] + [rnd(v * 2.0 ** tx) for v in r]
h += [0] * (2 * words - len(h))
ints.append(h)
mmax = [max(abs(h[k]) for h in ints) / 2.0 ** tm for k in range(len(pairs))]
xmax = [max(abs(h[len(pairs) + a]) for h in ints) / 2.0 ** tx for a in range(dim)]
return ints, tm, tx, mmax, xmax
def words_c(h):
return '{' + ', '.join('0x%08xu' % ((h[2 * k] & 0xffff) | (h[2 * k + 1] & 0xffff) << 16)
for k in range(len(h) // 2)) + '}'
def floats(v):
return '{' + ', '.join(f32(f32_up(x)) for x in v) + '}'
def emit(out, name, src, n24, n58, ok24, ok58):
p24, p58 = table(src, n24, 3), table(src, n58, 4)
u24, u58 = mask(src, ok24, len(p24)), mask(src, ok58, len(p58))
i24, tm24, tx24, m24, x24 = image(p24, PAIRS24, 5)
i58, tm58, tx58, m58, x58 = image(p58, PAIRS58, 8)
# n3, n4 as the float code forms them, rounded up past its rounding
n3 = max(sum(v * v for v in r) for r, u in zip(p24, u24) if u) * (1 + 2.0 ** -20)
n4 = max(sum(v * v for v in r) for r, u in zip(p58, u58) if u) * (1 + 2.0 ** -20)
used = [r for r, u in zip(p58, u58) if u]
sx = [sum(r[a] for r in used) for a in range(4)]
sxx = [[sum(r[a] * r[b] for r in used) for b in range(4)] for a in range(4)]
out.append('static const uint32_t r24_%s[%d][5] = {' % (name, len(i24)))
out += [' ' + words_c(h) + ',' for h in i24]
out.append('};')
out.append('static const uint32_t r58_%s[%d][8] = {' % (name, len(i58)))
out += [' ' + words_c(h) + ',' for h in i58]
out.append('};')
out.append('const xombe_cq_q15_tab xombe__cq_q15_%s = {' % name)
out.append(' r24_%s, r58_%s, %d, %d, %d, %d,' % (name, name, tm24, tx24, tm58, tx58))
tail = [floats(m24), floats(x24), floats(m58), floats(x58), f32(f32_up(n3)), f32(f32_up(n4)), str(len(used)),
'{' + ', '.join(f32(v) for v in sx) + '}',
'{' + ', '.join('{' + ', '.join(f32(v) for v in row) + '}' for row in sxx) + '}']
line = ' '
for i, t in enumerate(tail):
for tok in t.split(' '):
if len(line) + 1 + len(tok) > 116:
out.append(line)
line = ' '
line += ' ' + tok
line += ',' if i < len(tail) - 1 else '};'
out.append(line)
def main():
out = ['/* generated by scripts/gen_cq_tables.py, do not edit */', '#include "cq_q15_tables.h"', '',
'#if XOMBE_KERNELS_Q15 && (XOMBE_HAVE_ENCODER || XOMBE_HAVE_DSTAR)']
for name, fn, n24, n58, ok24, ok58 in SETS:
src = open(os.path.join(ROOT, 'src', 'tables', fn)).read()
if name == 'dstar':
out.append('#if XOMBE_HAVE_DSTAR')
emit(out, name, src, n24, n58, ok24, ok58)
if name == 'dstar':
out.append('#endif')
out.append('#else')
out.append('typedef int xombe__cq_q15_tables_unused;')
out.append('#endif')
with open(OUT, 'w') as f:
f.write('\n'.join(out) + '\n')
if __name__ == '__main__':
main()
+230
View File
@@ -0,0 +1,230 @@
#!/usr/bin/env python3
"""writes src/tables/dsp_tables.c, closed-form values computed in double and rounded to float"""
import math
import os
import re
import struct
ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
OUT = os.path.join(ROOT, 'src', 'tables', 'dsp_tables.c')
TABLES = os.path.join(ROOT, 'src', 'tables', 'tables.c')
DCT_BLK_J_MAX = 17 # XOMBE_DCT_BLK_J_MAX, largest spectral block length (xombe__blk)
DCT_BLK_ROWS = 6 # XOMBE_DCT_BLK_ROWS, one kernel row per DCT coefficient m = 0..5
GRAIN_RAMP = 16 # XOMBE_GRAIN_RAMP
HALF_MIN, HALF_MAX = 76, 84
LMAX = 56
B0_COUNT = 120
TW_N = 1024 # analysis FFT, smaller transforms take every (TW_N/n)-th twiddle
FFT = 1024 # XOMBE_FFT
BASE_WINDOW = 199
PITCH_LPF_HALF = 10
PITCH_WIN = 301
TONE_SEG = 240
TONE_FFT = 512 # XOMBE_TONE_FFT
def f32(x):
"""x rounded to the nearest float, printed to read back exactly"""
if abs(x) < 1e-12: # cos(pi/2) and similar are exactly 0
x = 0.0
v = struct.unpack('f', struct.pack('f', x))[0]
s = '%.9g' % v
if 'e' not in s and '.' not in s:
s += '.0'
return s + 'f'
def fl32(x):
"""x rounded to float, the result of a float operation whose exact value is x"""
return struct.unpack('f', struct.pack('f', x))[0]
def round_q(v):
"""(int)(v + (v < 0 ? -0.5f : 0.5f)) for float v"""
return int(fl32(v + (-0.5 if v < 0 else 0.5)))
def rows(values, per_line=6, indent=' '):
lines = []
for i in range(0, len(values), per_line):
lines.append(indent + ', '.join(values[i:i + per_line]) + ',')
return '\n'.join(lines)
def w0_table():
"""xombe__w0 as spelled in tables.c (the standard's pitch table as float)"""
src = open(TABLES).read()
body = re.search(r'xombe__w0\[XOMBE_B0_COUNT\] = \{(.*?)\};', src, re.S).group(1)
vals = [struct.unpack('f', struct.pack('f', float(v.rstrip('f'))))[0] for v in body.replace(',', ' ').split()]
assert len(vals) == B0_COUNT and all(a > b for a, b in zip(vals, vals[1:]))
return vals
def hamming(i, n):
return 0.54 - 0.46 * math.cos(2.0 * math.pi * i / (n - 1))
def dct(J, m, i):
return math.cos(math.pi * m * (i + 0.5) / J)
def main():
out = ['/* generated by scripts/gen_dsp_tables.py, do not edit */', '#include "dsp_tables.h"', '']
out.append('const float xombe__dct8[8][8] = {')
for m in range(8):
out.append(' {' + ', '.join(f32(dct(8, m, i)) for i in range(8)) + '},')
out.append('};')
out.append('')
offs, vals = [], []
for J in range(DCT_BLK_J_MAX + 1):
offs.append(str(len(vals)))
for m in range(DCT_BLK_ROWS):
vals.extend(f32(dct(J, m, i)) for i in range(J))
out.append('const unsigned short xombe__dct_blk_off[XOMBE_DCT_BLK_J_MAX + 1] = {')
out.append(rows(offs, 12))
out.append('};')
out.append('')
out.append('const float xombe__dct_blk[XOMBE_DCT_BLK_SIZE] = {')
out.append(rows(vals))
out.append('};')
out.append('')
out.append('const float xombe__ramp_cos[XOMBE_GRAIN_RAMP] = {')
out.append(rows([f32(math.cos(math.pi * j / GRAIN_RAMP)) for j in range(GRAIN_RAMP)]))
out.append('};')
out.append('')
out.append('const float xombe__ramp_sin[XOMBE_GRAIN_RAMP] = {')
out.append(rows([f32(math.sin(math.pi * j / GRAIN_RAMP)) for j in range(GRAIN_RAMP)]))
out.append('};')
out.append('')
out.append('const float xombe__sqrt_n[XOMBE_HALF_MAX + 1] = {')
out.append(rows([f32(math.sqrt(n)) for n in range(HALF_MAX + 1)]))
out.append('};')
out.append('')
out.append('const float xombe__rsqrt_half[XOMBE_HALF_MAX - XOMBE_HALF_MIN + 1] = {')
out.append(rows([f32(1.0 / math.sqrt(N)) for N in range(HALF_MIN, HALF_MAX + 1)]))
out.append('};')
out.append('')
out.append('const float xombe__half_log2[XOMBE_LMAX + 1] = {')
out.append(rows(['0.0f'] + [f32(0.5 * math.log2(L)) for L in range(1, LMAX + 1)]))
out.append('};')
out.append('')
w0 = w0_table()
out.append('const float xombe__w0_mid[XOMBE_B0_COUNT - 1] = {')
out.append(rows([f32(math.sqrt(w0[b] * w0[b + 1])) for b in range(B0_COUNT - 1)]))
out.append('};')
out.append('')
out.append('const xombe_cpx xombe__fft_tw[XOMBE_TW_N / 2] = {')
tw = []
for k in range(TW_N // 2):
ang = -2.0 * math.pi * k / TW_N
tw.append('{%s, %s}' % (f32(math.cos(ang)), f32(math.sin(ang))))
out.append(rows(tw, 3))
out.append('};')
out.append('')
out.append('#if XOMBE_HAVE_ENCODER')
out.append('const float xombe__base_win[XOMBE_BASE_WINDOW] = {')
out.append(rows([f32(hamming(i, BASE_WINDOW)) for i in range(BASE_WINDOW)]))
out.append('};')
out.append('')
h = []
for j in range(-PITCH_LPF_HALF, PITCH_LPF_HALF + 1):
x = 0.25 * j
sinc = 1.0 if j == 0 else math.sin(math.pi * x) / (math.pi * x)
h.append(0.25 * sinc * (0.54 + 0.46 * math.cos(math.pi * j / PITCH_LPF_HALF)))
s = 0.0
for v in h:
s += v
lpf = [f32(float(f32(v)[:-1]) / s) for v in h]
out.append('const float xombe__pitch_lpf[2 * XOMBE_PITCH_LPF_HALF + 1] = {')
out.append(rows(lpf))
out.append('};')
out.append('')
# q15 low-pass taps (kern_q15_pitch.c) from the float taps, in float arithmetic as C computes it
# g[m] = h[20 - m] scaled so sum |g| <= 65536 after rounding (a 32-bit SMLAD sum of int16 can't overflow),
# paired, and again shifted by one
lpf = [fl32(float(v[:-1])) for v in lpf]
total = 0.0
for v in lpf:
total = fl32(total + abs(v))
gain = fl32(65000.0 / total)
g = [round_q(fl32(lpf[2 * PITCH_LPF_HALF - m] * gain)) for m in range(2 * PITCH_LPF_HALF + 1)]
taps = 2 * PITCH_LPF_HALF + 2
ga = g + [0] * (taps - len(g))
gb = [0] + g + [0] * (taps - 1 - len(g))
def pairs(t):
return ['0x%08xu' % ((t[i] & 0xffff) | (t[i + 1] & 0xffff) << 16) for i in range(0, taps, 2)]
out.append('#if XOMBE_KERNELS_Q15')
out.append('const uint32_t xombe__pitch_lpf_q15[2][XOMBE_PITCH_LPF_PAIRS] = {')
for t in (ga, gb):
out.append(' {')
out.append(rows(pairs(t), 6, ' ' * 8))
out.append(' },')
out.append('};')
out.append('const float xombe__pitch_lpf_q15_gain = %s;' % f32(gain))
def q15(v):
return min(32767, math.floor(v * 32768.0 + 0.5)) & 0xffff
tq = []
for j in range(FFT // 4):
ang = -2.0 * math.pi * j / (FFT // 2)
tq.append('0x%08xu' % (q15(math.cos(ang)) | q15(math.sin(ang)) << 16))
out.append('const uint32_t xombe__fft_tw_q15[XOMBE_FFT / 4] = {')
out.append(rows(tq, 6))
out.append('};')
tq = []
for j in range(TONE_FFT // 4):
ang = -2.0 * math.pi * j / (TONE_FFT // 2)
tq.append('0x%08xu' % (q15(math.cos(ang)) | q15(math.sin(ang)) << 16))
out.append('const uint32_t xombe__tone_tw_q15[XOMBE_TONE_FFT / 4] = {')
out.append(rows(tq, 6))
out.append('};')
out.append('#endif')
out.append('')
w = [hamming(j, PITCH_WIN) for j in range(PITCH_WIN)]
s2 = s4 = 0.0
for v in w:
s2 += v * v
w2 = [v * v / s2 for v in w]
for v in w2:
s4 += v * v
out.append('const float xombe__pitch_w2[XOMBE_PITCH_WIN] = {')
out.append(rows([f32(v) for v in w2]))
out.append('};')
out.append('const float xombe__pitch_sum_w4 = %s;' % f32(s4))
# q15 pitch window (kern_q15_pitch.c) from the float table, scaled to peak 32767, first half (symmetric)
w2f = [fl32(float(f32(v)[:-1])) for v in w2]
w2_gain = fl32(32767.0 / max(w2f))
w2q = [round_q(fl32(v * w2_gain)) for v in w2f]
assert w2q == w2q[::-1]
w2q = w2q[:PITCH_WIN // 2 + 1]
out.append('#if XOMBE_KERNELS_Q15')
out.append('const int16_t xombe__pitch_w2_q15[XOMBE_PITCH_HALF + 1] = {')
out.append(rows([str(v) for v in w2q], 12))
out.append('};')
out.append('const float xombe__pitch_w2_q15_gain = %s;' % f32(w2_gain))
out.append('#endif')
out.append('')
out.append('const float xombe__tone_win[XOMBE_TONE_SEG] = {')
out.append(rows([f32(0.5 - 0.5 * math.cos(2.0 * math.pi * i / (TONE_SEG - 1))) for i in range(TONE_SEG)]))
out.append('};')
out.append('#endif')
assert len(vals) == DCT_BLK_ROWS * sum(range(DCT_BLK_J_MAX + 1))
with open(OUT, 'w') as f:
f.write('\n'.join(out) + '\n')
if __name__ == '__main__':
main()
+97
View File
@@ -0,0 +1,97 @@
#!/usr/bin/env python3
"""writes src/tables/dstar_enc_tables.c and dstar_enc_tables.h, the D-STAR encoder's noise reference and windows
m_noise(N, b0) in scripts/data/dstar_tables.json is the fitted encoder model's mean voicing metric over 8 seeded
numpy white-noise draws, which C cannot reproduce, so it is tabulated for the (N, b0) pairs the encoder can reach,
as round(m*65536) in 16 bits (m < 1, smallest 0.18, relative error <= 3e-5)"""
import json
import math
import os
import struct
ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
OUT_C = os.path.join(ROOT, 'src', 'tables', 'dstar_enc_tables.c')
OUT_H = os.path.join(ROOT, 'src', 'tables', 'dstar_enc_tables.h')
DATA = os.path.join(ROOT, 'scripts', 'data', 'dstar_tables.json')
N_MIN, N_MAX = 199, 321
N_COUNT = (N_MAX - N_MIN) // 2 + 1
B0_VOICE_MAX = 123
SCALE = 65536
TONE_LEN, NZ_LEN = 160, 134
def f32(x):
t = '%.9g' % struct.unpack('<f', struct.pack('<f', x))[0]
return t + ('f' if ('.' in t or 'e' in t) else '.0f')
def hann(n):
return [0.5 - 0.5 * math.cos(2.0 * math.pi * i / (n - 1)) for i in range(n)]
def main():
with open(DATA) as f:
windows = json.load(f)['m_noise']
assert [w['N'] for w in windows] == list(range(N_MIN, N_MAX + 1, 2))
lo, cnt, off, data = [], [], [], []
for w in windows:
assert 0 <= w['b0_lo'] and w['b0_lo'] + len(w['rows']) - 1 <= B0_VOICE_MAX
lo.append(w['b0_lo'])
cnt.append(len(w['rows']))
off.append(len(data))
for m in w['rows']:
q = [int(round(v * SCALE)) for v in m]
assert len(q) == 8 and all(0 < v < SCALE for v in q), (w['N'], m)
data.append(q)
rows = len(data)
h = '''#ifndef XOMBE_DSTAR_ENC_TABLES_H
#define XOMBE_DSTAR_ENC_TABLES_H
/* D-STAR encoder white-noise voicing reference m_noise(N, b0), generated by scripts/gen_dstar_enc_tables.py,
do not edit
window N = %d + 2i (i < XOMBE_DS_MN_WINDOWS) has rows for b0 lo[i]..lo[i] + cnt[i] - 1 from row off[i],
each row the 8 band values x %d */
#define XOMBE_DS_MN_N_MIN %d
#define XOMBE_DS_MN_WINDOWS %d
#define XOMBE_DS_MN_ROWS %d
#define XOMBE_DS_MN_SCALE %d.0f
extern const unsigned char xombe__ds_mn_lo[XOMBE_DS_MN_WINDOWS];
extern const unsigned char xombe__ds_mn_cnt[XOMBE_DS_MN_WINDOWS];
extern const unsigned short xombe__ds_mn_off[XOMBE_DS_MN_WINDOWS];
extern const unsigned short xombe__ds_mn[XOMBE_DS_MN_ROWS][8];
/* tone detector segment and tone-in-noise window lengths in samples, Hann windows 0.5 - 0.5*cos(2*pi*i/(n - 1)) */
#define XOMBE_DS_TONE_LEN %d
#define XOMBE_DS_NZ_LEN %d
extern const float xombe__ds_tone_win[XOMBE_DS_TONE_LEN];
extern const float xombe__ds_nz_win[XOMBE_DS_NZ_LEN];
#endif
''' % (N_MIN, SCALE, N_MIN, N_COUNT, rows, SCALE, TONE_LEN, NZ_LEN)
def vec(name, ctype, v, per=16):
lines = [' ' + ', '.join(str(x) for x in v[i:i + per]) + ',' for i in range(0, len(v), per)]
return 'const %s %s[%d] = {\n%s\n};\n' % (ctype, name, len(v), '\n'.join(lines))
c = ['/* generated by scripts/gen_dstar_enc_tables.py, do not edit */\n#include "dstar_enc_tables.h"\n']
c.append(vec('xombe__ds_mn_lo', 'unsigned char', lo))
c.append(vec('xombe__ds_mn_cnt', 'unsigned char', cnt))
c.append(vec('xombe__ds_mn_off', 'unsigned short', off))
c.append('const unsigned short xombe__ds_mn[XOMBE_DS_MN_ROWS][8] = {\n%s\n};\n' %
'\n'.join(' {%s},' % ', '.join(str(x) for x in r) for r in data))
for name, n in (('xombe__ds_tone_win', 'XOMBE_DS_TONE_LEN'), ('xombe__ds_nz_win', 'XOMBE_DS_NZ_LEN')):
w = [f32(v) for v in hann(TONE_LEN if n.endswith('TONE_LEN') else NZ_LEN)]
c.append('const float %s[%s] = {\n%s\n};\n' % (name, n, '\n'.join(
' ' + ', '.join(w[i:i + 8]) + ',' for i in range(0, len(w), 8))))
with open(OUT_C, 'w') as f:
f.write('\n'.join(c))
with open(OUT_H, 'w') as f:
f.write(h)
print('%d windows, %d rows, %d bytes' % (N_COUNT, rows, rows * 16 + N_COUNT * 4))
if __name__ == '__main__':
main()
+147
View File
@@ -0,0 +1,147 @@
#!/usr/bin/env python3
"""writes src/tables/dstar_tables.c and dstar_tables.h, the D-STAR (AMBE 2400) tables, from the fitted values
in scripts/data/dstar_tables.json"""
import json
import math
import os
import struct
ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
OUT_C = os.path.join(ROOT, 'src', 'tables', 'dstar_tables.c')
OUT_H = os.path.join(ROOT, 'src', 'tables', 'dstar_tables.h')
DATA = os.path.join(ROOT, 'scripts', 'data', 'dstar_tables.json')
B0_COUNT = 128
LMAX = 56
BANDS_PER_UNIT = 16.0 # 8000 / 500, harmonic l at f0 lies in 500 Hz band floor(l*f0*16)
TONE_NONE = 255
def fl32(x):
return struct.unpack('f', struct.pack('f', float(x)))[0]
def f32(x):
"""x rounded to the nearest float, printed to read back exactly"""
v = fl32(x)
s = '%.9g' % v
if 'e' not in s and '.' not in s:
s += '.0'
return s + 'f'
def rows(values, per_line=6, indent=' '):
return '\n'.join(indent + ', '.join(values[i:i + per_line]) + ',' for i in range(0, len(values), per_line))
def c_matrix(name, ctype, dims, data, fmt):
out = ['const %s %s%s = {' % (ctype, name, ''.join('[%s]' % d for d in dims))]
if len(dims) == 1:
out.append(rows([fmt(v) for v in data], 6 if fmt is f32 else 16))
else:
for r in data:
out.append(' {' + ', '.join(fmt(v) for v in r) + '},')
out.append('};')
return out
def main():
with open(DATA) as f:
T = json.load(f)
p0, p1, rho, grho = float(T['p0']), float(T['p1']), float(T['rho']), float(T['grho'])
w0 = [2.0 ** (p0 + p1 * (b + 0.5)) for b in range(B0_COUNT)]
lt = [int(min(max(math.floor(0.4627 / f), 9), LMAX)) for f in w0]
# decoder's per-harmonic band in float as params.c computes it, ((float)l*f0)*16 with f0 the float table
# value, must equal the double floor(l*f0*8000/500)
for b in range(B0_COUNT):
for l in range(1, lt[b] + 1):
c = int(fl32(fl32(l * fl32(w0[b])) * BANDS_PER_UNIT))
assert c == int(l * w0[b] * 8000.0 / 500.0), (b, l)
dg, p24, p58, hoc = T['DG'], T['PRBA24'], T['PRBA58'], T['HOC']
assert (len(dg), len(p24), len(p58), [len(h) for h in hoc]) == (64, 512, 128, [16, 16, 16, 8])
assert all(len(r) == 4 for h in hoc for r in h)
ok_dg, ok24, ok58, ok_hoc = T['ok_DG'], T['ok_PRBA24'], T['ok_PRBA58'], T['ok_HOC']
# b1 -> flags of 500 Hz bands 0..7 as the decoder plays them (code 4 plays as 12)
vuv = [[int(ch) for ch in s] for s in T['VUV0']]
# D-STAR tone index T -> AMBE+2 tone ID: T 0..15 DTMF (T = 4*column + row), 16..19 call progress,
# 37..154 single tones at 31.25*(T - 32) Hz, every other T invalid
tone = [TONE_NONE if t is None else t for t in T['tone_id']]
# b0 of the D-STAR voice frame carrying Knox tone ID 144 + i (observed)
knox_b0 = T['knox_b0']
assert (len(vuv), len(tone), len(knox_b0)) == (16, 256, 16)
c = ['/* generated by scripts/gen_dstar_tables.py, do not edit */',
'#include "dstar_tables.h"', '']
c += c_matrix('xombe__ds_w0', 'float', ['XOMBE_DS_B0_COUNT'], w0, f32) + ['']
c += c_matrix('xombe__ds_lt', 'unsigned char', ['XOMBE_DS_B0_COUNT'], lt, str) + ['']
c += c_matrix('xombe__ds_dg', 'float', ['64'], dg, f32) + ['']
c += c_matrix('xombe__ds_prba24', 'float', ['512', '3'], p24, f32) + ['']
c += c_matrix('xombe__ds_prba58', 'float', ['128', '4'], p58, f32) + ['']
for k, n in enumerate([16, 16, 16, 8]):
c += c_matrix('xombe__ds_hoc%d' % (k + 5), 'float', [str(n), '4'], hoc[k], f32) + ['']
c += c_matrix('xombe__ds_ok_dg', 'unsigned char', ['64'], ok_dg, str) + ['']
c += c_matrix('xombe__ds_ok_prba24', 'unsigned char', ['512'], ok24, str) + ['']
c += c_matrix('xombe__ds_ok_prba58', 'unsigned char', ['128'], ok58, str) + ['']
for k, n in enumerate([16, 16, 16, 8]):
c += c_matrix('xombe__ds_ok_hoc%d' % (k + 5), 'unsigned char', [str(n)], ok_hoc[k], str) + ['']
c += c_matrix('xombe__ds_vuv', 'unsigned char', ['16', '8'], vuv, str) + ['']
c += c_matrix('xombe__ds_tone_id', 'unsigned char', ['256'], tone, str) + ['']
c += c_matrix('xombe__ds_knox_b0', 'unsigned char', ['16'], knox_b0, str)
h = '''#ifndef XOMBE_DSTAR_TABLES_H
#define XOMBE_DSTAR_TABLES_H
/* D-STAR (AMBE 2400) tables, generated by scripts/gen_dstar_tables.py, do not edit
each value is a fitted double rounded once to float, spectral block lengths are AMBE+2's xombe__blk */
#define XOMBE_DS_B0_COUNT %(nb0)d
/* pitch grid f0 = 2^(P0 + P1*(b0 + 1/2)) cycles/sample, from doubles %(p0)r and %(p1)r */
#define XOMBE_DS_P0 %(p0f)s
#define XOMBE_DS_P1 %(p1f)s
/* amplitude prediction weight and gain recursion (0: b2 is an absolute gain index) */
#define XOMBE_DS_RHO %(rho)s
#define XOMBE_DS_GRHO %(grho)s
#define XOMBE_DS_TONE_NONE %(none)d
/* f0 in cycles/sample and L = floor(0.4627/f0) clamped to 9..56, both from the double f0 (voice b0 0..123) */
extern const float xombe__ds_w0[XOMBE_DS_B0_COUNT];
extern const unsigned char xombe__ds_lt[XOMBE_DS_B0_COUNT];
/* gain (b2), PRBA (b3, b4), and HOC (b5..b8, rows of 4, first min(J, 6) - 2 used) codebooks */
extern const float xombe__ds_dg[64];
extern const float xombe__ds_prba24[512][3];
extern const float xombe__ds_prba58[128][4];
extern const float xombe__ds_hoc5[16][4];
extern const float xombe__ds_hoc6[16][4];
extern const float xombe__ds_hoc7[16][4];
extern const float xombe__ds_hoc8[8][4];
/* 1 where the fit had data for the entry, the closed-loop quantizer skips the others */
extern const unsigned char xombe__ds_ok_dg[64];
extern const unsigned char xombe__ds_ok_prba24[512];
extern const unsigned char xombe__ds_ok_prba58[128];
extern const unsigned char xombe__ds_ok_hoc5[16];
extern const unsigned char xombe__ds_ok_hoc6[16];
extern const unsigned char xombe__ds_ok_hoc7[16];
extern const unsigned char xombe__ds_ok_hoc8[8];
/* b1 -> eight 500 Hz band flags as the decoder plays them (code 4 plays as 12) */
extern const unsigned char xombe__ds_vuv[16][8];
/* tone index T (8 bits) -> AMBE+2 tone ID, or XOMBE_DS_TONE_NONE */
extern const unsigned char xombe__ds_tone_id[256];
/* encoder sends Knox tones (AMBE+2 IDs 144..159, no D-STAR tone code) as voice frames at this b0 per ID */
extern const unsigned char xombe__ds_knox_b0[16];
#endif
''' % dict(nb0=B0_COUNT, p0=p0, p1=p1, p0f=f32(p0), p1f=f32(p1), rho=f32(rho), grho=f32(grho),
none=TONE_NONE)
with open(OUT_C, 'w') as f:
f.write('\n'.join(c) + '\n')
with open(OUT_H, 'w') as f:
f.write(h)
print('wrote', OUT_C, OUT_H)
if __name__ == '__main__':
main()
+60
View File
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
import argparse
import hashlib
import os
import struct
import sys
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'tools'))
from common import CLIPS, DITHER_DB as GAINS_DB, E3IN, E3V
def dither(samples, gain_db):
g = 10.0 ** (gain_db / 20.0)
out = []
for x in samples:
y = round(g * x)
out.append(32767 if y > 32767 else -32768 if y < -32768 else y)
return out
def main():
ap = argparse.ArgumentParser(description='Regenerate the dithered E3 inputs and check them against SHA256SUMS')
ap.add_argument('--dir', default=E3V)
ap.add_argument('--out', default=E3IN, help='output directory (default $XOMBE_BUILD/e3in)')
ap.add_argument('--write-manifest', action='store_true')
a = ap.parse_args()
out_dir = a.out
os.makedirs(out_dir, exist_ok=True)
manifest_path = os.path.join(a.dir, 'SHA256SUMS')
expected = {}
if not a.write_manifest and not os.path.exists(manifest_path):
print('%s is missing; regenerate it with --write-manifest' % manifest_path, file=sys.stderr)
return 1
if not a.write_manifest:
for line in open(manifest_path):
digest, name = line.split()
expected[name] = digest
lines, bad = [], 0
for clip in CLIPS:
raw = open(os.path.join(a.dir, clip + '_orig.raw'), 'rb').read()
x = struct.unpack('<%dh' % (len(raw) // 2), raw)
for k, g in enumerate(GAINS_DB):
data = struct.pack('<%dh' % len(x), *dither(x, g))
name = '%s.d%d.raw' % (clip, k)
open(os.path.join(out_dir, name), 'wb').write(data)
digest = hashlib.sha256(data).hexdigest()
lines.append('%s %s' % (digest, name))
if not a.write_manifest and expected.get(name) != digest:
print('MISMATCH %s' % name)
bad += 1
if a.write_manifest:
open(manifest_path, 'w').write('\n'.join(lines) + '\n')
print('wrote %s' % manifest_path)
else:
print('%d inputs regenerated, %d mismatches against SHA256SUMS' % (len(lines), bad))
return 1 if bad else 0
if __name__ == '__main__':
sys.exit(main())
+9
View File
@@ -0,0 +1,9 @@
#!/bin/sh
# release_buildinfo.sh: the tools behind a release tarball and, on Debian, every installed package
set -eu
git --version
xz --version | head -n 1
if command -v dpkg-query > /dev/null; then
dpkg-query -W -f='${db:Status-Abbrev} ${Package}:${Architecture} ${Version}\n' |
awk '$1 == "ii" { print $2, $3 }' | LC_ALL=C sort
fi
+13
View File
@@ -0,0 +1,13 @@
#!/bin/sh
# release_deps.sh: installs release_packages.lock into the release container (release_lock.sh's base), from
# deb.debian.org or else the snapshot
set -eu
here=$(cd "$(dirname "$0")" && pwd)
rm -f /etc/apt/sources.list.d/*
printf '%s\n' 'deb http://deb.debian.org/debian trixie main' \
'deb [check-valid-until=no] http://snapshot.debian.org/archive/debian/20261111T000000Z trixie main' \
> /etc/apt/sources.list
apt-get -o Acquire::Retries=5 update || true
# shellcheck disable=SC2046
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $(cat "$here/release_packages.lock")
rm -rf /var/lib/apt/lists/*
+18
View File
@@ -0,0 +1,18 @@
#!/bin/sh
# release_lock.sh: prints the packages (name=version) that release_deps.sh's snapshot adds to the base image, the
# contents of release_packages.lock. CONTAINER picks the engine (podman)
set -eu
base=docker.io/library/debian@sha256:2dc419c6d7fe3dad0a2f9fd469c34cc90b0f9ba642d8fde837fe3d7d34a0e7f1
here=$(cd "$(dirname "$0")" && pwd)
engine=${CONTAINER:-podman}
snap=$(grep -o 'http://snapshot\.debian\.org/archive/debian/[0-9TZ]*' "$here/release_deps.sh")
"$engine" run --rm "$base" sh -euc '
export DEBIAN_FRONTEND=noninteractive
q() { dpkg-query -W -f="\${Package}=\${Version}\n" | LC_ALL=C sort; }
q > /tmp/base
rm -f /etc/apt/sources.list.d/*
echo "deb [check-valid-until=no] $1 trixie main" > /etc/apt/sources.list
apt-get -qq -o Acquire::Retries=5 update
apt-get -qq install -y --no-install-recommends ca-certificates git xz-utils > /dev/null
q | LC_ALL=C comm -13 /tmp/base -
' _ "$snap"
+36
View File
@@ -0,0 +1,36 @@
ca-certificates=20250419
git-man=1:2.47.3-0+deb13u1
git=1:2.47.3-0+deb13u1
libbrotli1=1.1.0-2+b7
libcom-err2=1.47.2-3+b12
libcurl3t64-gnutls=8.14.1-2+deb13u5
liberror-perl=0.17030-1
libexpat1=2.8.3-1~deb13u1
libffi8=3.4.8-2
libgdbm-compat4t64=1.24-2
libgdbm6t64=1.24-2
libgnutls30t64=3.8.9-3+deb13u4
libgssapi-krb5-2=1.21.3-5+deb13u1
libidn2-0=2.3.8-2
libk5crypto3=1.21.3-5+deb13u1
libkeyutils1=1.6.3-6
libkrb5-3=1.21.3-5+deb13u1
libkrb5support0=1.21.3-5+deb13u1
libldap2=2.6.10+dfsg-1
libnghttp2-14=1.64.0-1.1+deb13u1
libnghttp3-9=1.8.0-1
libngtcp2-16=1.11.0-1+deb13u1
libngtcp2-crypto-gnutls8=1.11.0-1+deb13u1
libp11-kit0=0.25.5-3
libperl5.40=5.40.1-6+deb13u1
libpsl5t64=0.21.2-1.1+b1
librtmp1=2.4+20151223.gitfa8646d.1-2+b5
libsasl2-2=2.1.28+dfsg1-9
libsasl2-modules-db=2.1.28+dfsg1-9
libssh2-1t64=1.11.1-1+deb13u2
libtasn1-6=4.20.0-2+deb13u1
libunistring5=1.3-2
openssl=3.5.7-1~deb13u2
perl-modules-5.40=5.40.1-6+deb13u1
perl=5.40.1-6+deb13u1
xz-utils=5.8.1-1+deb13u1
+17
View File
@@ -0,0 +1,17 @@
#!/bin/sh
# release_tarball.sh [REF [OUT]]: writes xombe-X.Y.Z.tar.xz (git archive of REF, default HEAD) and
# xombe-X.Y.Z.buildinfo to OUT (default dist). byte-identical across hosts in the release container
# (release_deps.sh), the version is REF's include/xombe.h
set -eu
ref=${1:-HEAD}
root=$(cd "$(dirname "$0")/.." && pwd)
out=${2:-$root/dist}
part() { git -C "$root" show "$ref:include/xombe.h" | sed -n "s/^#define XOMBE_VERSION_$1 \([0-9][0-9]*\)\$/\1/p"; }
ver=$(part MAJOR).$(part MINOR).$(part PATCH)
case $ver in
*[!0-9.]* | .* | *..* | *.) echo "no XOMBE_VERSION_MAJOR/MINOR/PATCH in $ref:include/xombe.h" >&2; exit 1 ;;
esac
name=xombe-$ver
mkdir -p "$out"
git -C "$root" archive --format=tar --prefix="$name/" "$ref" -- . ':!.gitignore' | xz -9 -T1 > "$out/$name.tar.xz"
"$root/scripts/release_buildinfo.sh" > "$out/$name.buildinfo"
+188
View File
@@ -0,0 +1,188 @@
#!/bin/sh
# size_table.sh [WORKDIR]: state sizes (test/sizes.c) and worst-case stack per public call for the four builds
# (float and q15 kernels, XOMBE_DSTAR off and on), as Markdown tables. stack is from -fcallgraph-info=su
# (GCC 10 or later) walked over the library's call graph, on the host and, when arm-none-eabi-gcc is installed,
# on a Cortex-M33 build. WORKDIR (default: a temporary directory, removed at the end) holds the builds.
# needs cmake and python3, CC picks the host compiler, ARM_CC the cross compiler
set -eu
ROOT=$(cd "$(dirname "$0")/.." && pwd)
PY=${PYTHON:-python3}
ARM_CC=${ARM_CC:-arm-none-eabi-gcc}
JOBS=${JOBS:-4}
if [ $# -gt 0 ]; then
W=$1
mkdir -p "$W"
else
W=$(mktemp -d)
trap 'rm -rf "$W"' EXIT
fi
CI="-fstack-usage -fcallgraph-info=su"
ARM_FLAGS="-mcpu=cortex-m33 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16"
CONFIGS="float:OFF float:ON q15:OFF q15:ON"
command -v "$ARM_CC" > /dev/null && arm=1 || arm=0
build() { # build DIR KERNELS DSTAR [cmake options]
d=$1 k=$2 ds=$3
shift 3
cmake -S "$ROOT" -B "$d" -DCMAKE_BUILD_TYPE=Release -DXOMBE_KERNELS=$k -DXOMBE_DSTAR=$ds -DXOMBE_BUILD_TOOLS=OFF \
-DXOMBE_INSTALL=OFF "$@" > "$d.log" 2>&1 && cmake --build "$d" -j "$JOBS" >> "$d.log" 2>&1 ||
{ cat "$d.log" >&2; exit 1; }
}
for c in $CONFIGS; do
k=${c%:*} ds=${c#*:}
build "$W/host-$k-$ds" $k $ds -DXOMBE_BUILD_TESTS=ON "-DCMAKE_C_FLAGS=$CI"
if [ $arm = 1 ]; then
build "$W/m33-$k-$ds" $k $ds -DXOMBE_BUILD_TESTS=OFF -DCMAKE_SYSTEM_NAME=Generic -DCMAKE_C_COMPILER="$ARM_CC" \
-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY "-DCMAKE_C_FLAGS_RELEASE=-O2 -DNDEBUG" "-DCMAKE_C_FLAGS=$ARM_FLAGS $CI"
fi
done
echo "### State (bytes) and encoder delay (frames), $(uname -m)"
echo
"$W/host-float-OFF/sizes" --header
for c in $CONFIGS; do
"$W/host-${c%:*}-${c#*:}/sizes"
done
echo
targets="x86-64"
[ $arm = 1 ] && targets="$targets M33"
echo "### Worst-case stack per public call (bytes)"
echo
"$PY" - "$ROOT" "$W" "$targets" $CONFIGS << 'EOF'
import glob, os, re, sys
root, work, targets, configs = sys.argv[1], sys.argv[2], sys.argv[3].split(), sys.argv[4:]
node_re = re.compile(r'node: \{ title: "([^"]*)" label: "([^"]*)"')
edge_re = re.compile(r'edge: \{ sourcename: "([^"]*)" targetname: "([^"]*)"(?: label: "([^"]*)")?')
comment_re = re.compile(r'/\*.*?\*/|//[^\n]*', re.S)
def short(title):
return title.rsplit(':', 1)[-1]
def address_taken(stack):
"""functions named in the library sources other than in a call or declaration: the targets an indirect call
may reach, for a static function only in its own file"""
text = {}
for f in glob.glob(os.path.join(root, 'src', '**', '*.[ch]'), recursive=True):
text[os.path.realpath(f)] = comment_re.sub(' ', open(f).read())
out = set()
for t in stack:
name = short(t)
files = [os.path.realpath(t.rsplit(':', 1)[0])] if ':' in t else list(text)
pat = re.compile(r'(?<![.>\w])%s\b(?!\s*\()' % re.escape(name))
if any(pat.search(text.get(f, '')) for f in files):
out.add(t)
return out
def load(build):
"""call graph of the library's objects: {fn: bytes}, {fn: [callees]}, flags, unresolved indirect calls"""
stack, calls, flag, src_lines, where_def = {}, {}, {}, {}, {}
for ci in glob.glob(os.path.join(build, 'CMakeFiles', '*', 'src', '**', '*.ci'), recursive=True):
for line in open(ci):
m = node_re.match(line)
if m:
parts = m.group(2).split('\\n')
if len(parts) > 2:
n, kind = re.match(r'(\d+) bytes \((.*)\)', parts[2]).groups()
t = m.group(1)
stack[t] = max(stack.get(t, 0), int(n))
where_def[t] = parts[1].rsplit(':', 2)[0]
if kind == 'dynamic':
flag[t] = 'unbounded'
calls.setdefault(t, set())
continue
m = edge_re.match(line)
if m:
src, dst, where = m.groups()
if dst == '__indirect_call':
dst = 'indirect@' + (where or '?')
calls.setdefault(src, set()).add(dst)
by_short = {}
for t in stack:
by_short.setdefault(short(t), []).append(t)
taken = address_taken(stack)
unresolved = set()
for src in list(calls):
out = set()
for dst in calls[src]:
if dst.startswith('indirect@'):
f, l = dst[len('indirect@'):].rsplit(':', 2)[:2]
text = src_lines.setdefault(f, open(f).read().split('\n') if os.path.exists(f) else [])
text = text[int(l) - 1] if int(l) <= len(text) else ''
if 'XOMBE_TAP' in text:
continue # test tap callback, runs on the caller's own stack
if taken:
out.update(taken)
else:
unresolved.add('%s:%s' % (os.path.relpath(f, root), l))
elif dst in stack:
out.add(dst)
elif dst in by_short and len(by_short[dst]) == 1:
out.add(by_short[dst][0])
# otherwise a library outside xombe (libc, libm), not counted
calls[src] = out
return stack, calls, flag, unresolved, taken, where_def
def worst(fn, stack, calls, memo, path):
if fn in path:
return None # recursion
if fn in memo:
return memo[fn]
path.add(fn)
best = 0
for c in calls.get(fn, ()):
w = worst(c, stack, calls, memo, path)
if w is None:
path.discard(fn)
return None
best = max(best, w)
path.discard(fn)
memo[fn] = stack.get(fn, 0) + best
return memo[fn]
cols, notes = [], []
for t in targets:
for c in configs:
k, ds = c.split(':')
b = os.path.join(work, '%s-%s-%s' % ('host' if t == 'x86-64' else 'm33', k, ds))
stack, calls, flag, unresolved, taken, where_def = load(b)
memo, res = {}, {}
for fn in stack:
if fn.startswith('xombe_') and not fn.startswith('xombe__') and ':' not in fn:
w = worst(fn, stack, calls, memo, set())
res[fn] = 'recursive' if w is None else str(w)
if ds == 'ON':
# the DMR-only encoder never enters src/dstar: the same walk without those functions
dsdir = os.path.join(os.path.realpath(root), 'src', 'dstar') + os.sep
amb = {f: {c for c in cs if not os.path.realpath(where_def.get(c, '')).startswith(dsdir)}
for f, cs in calls.items()}
for fn in ('xombe_enc_frame', 'xombe_enc_frame_bits'):
if fn in stack:
w = worst(fn, stack, amb, {}, set())
res[fn + ', DMR output only'] = 'recursive' if w is None else str(w)
cols.append(('%s %s D-STAR %s' % (t, k, ds.lower()), res))
if unresolved:
notes.append('%s %s D-STAR %s: unresolved indirect calls at %s' % (t, k, ds.lower(),
', '.join(sorted(unresolved))))
notes.append('%s %s D-STAR %s: indirect calls bounded by %s' % (t, k, ds.lower(),
', '.join(sorted(map(short, taken)))))
if flag:
notes.append('%s %s D-STAR %s: unbounded dynamic stack in %s' % (t, k, ds.lower(),
', '.join(sorted(flag))))
names = sorted(set().union(*[set(r) for _, r in cols]))
print('| call | ' + ' | '.join(c for c, _ in cols) + ' |')
print('|---|' + '---|' * len(cols))
for n in names:
fn, _, what = n.partition(', ')
print('| `%s`%s | ' % (fn, ' (%s)' % what if what else '') + ' | '.join(r.get(n, '-') for _, r in cols) + ' |')
print()
print('stack of libc and libm callees not included, test tap callbacks not included')
for n in notes:
print(n)
EOF