# The deterministic integer test signal shared by tools/fixtures/m4a.py, tools/fixtures/caf.py and the Luau side # (tests/audio/_signal.luau computes the same numbers): triangle + square + MINSTD noise (exact in doubles) + clicks, per channel. import struct def signal(frames, channels, bits, seed): s = seed peak = 2 ** (bits - 1) - 1 out = [] for i in range(frames): for c in range(channels): s = (s * 48271) % 2147483647 p1 = 97 + 31 * c tri = abs((i % p1) * 2 - p1) * 2 - p1 v = tri * (peak // (4 * p1)) p2 = 1500 + 200 * c v += (peak // 6) if (i // p2) % 2 == 0 else -(peak // 6) v += ((s // 65536) % 4096 - 2048) * (peak // 65536 + 1) if i % 7001 < 3: v += peak // 2 out.append(max(-peak - 1, min(peak, v))) return out def pack(samples, bits, big=False): e = ">" if big else "<" if bits == 16: return struct.pack(e + "%dh" % len(samples), *samples) if bits == 24: b = bytearray() for v in samples: x = struct.pack("