#!/usr/bin/env python3 """Generate a reference stimulus for the mic test: silence, 1 kHz tone, log sweep 100 Hz -> 8 kHz, then a 1 kHz tone again.""" import sys import wave from pathlib import Path import numpy as np SR = 48000 OUT = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("captures/stimulus.wav") def tone(f, dur, amp): t = np.arange(int(SR * dur)) / SR return amp * np.sin(2 * np.pi * f * t) def sweep(f0, f1, dur, amp): n = int(SR * dur) t = np.arange(n) / SR k = (f1 / f0) ** (1 / dur) phase = 2 * np.pi * f0 * (k ** t - 1) / np.log(k) return amp * np.sin(phase) amp = 0.25 # ~-12 dBFS parts = [ np.zeros(int(SR * 0.5)), tone(1000, 1.0, amp), np.zeros(int(SR * 0.2)), sweep(100, 8000, 3.0, amp), np.zeros(int(SR * 0.2)), tone(1000, 1.0, amp), np.zeros(int(SR * 0.5)), ] x = np.concatenate(parts) pcm = (np.clip(x, -1, 1) * 32767).astype("