def test(): p = wave.record("-", stdout=wave.sp.PIPE) f = stream.Reader(p.stdout) result = zip(range(10), f) p.stop() j = 0 for i, buf in result: assert i == j assert len(buf) == f.SAMPLES j += 1 try: for buf in f: pass except IOError as e: assert str(e) == "timeout"
def recv(): out = wave.record('-', stdout=wave.sp.PIPE).stdout while True: data = out.read(len(sig_dump)) if len(data) < len(sig_dump): return try: x = common.loads(data) except common.SaturationError as e: print('saturation: {}'.format(e)) continue x = x - np.mean(x) c = np.abs(np.dot(x, sig)) / (np.sqrt(0.5 * len(x)) * sigproc.norm(x)) z = np.dot(x, sig.conj()) / (0.5 * len(x)) amp = np.abs(z) phase = np.angle(z) peak = np.max(np.abs(x)) print('coherence={:.3f} amp={:.3f} phase={:.1f} peak={:.3f}'.format( c, amp, phase * 180 / np.pi, peak))