#!/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('