# -*- coding: utf-8 -*- """Measures in REW the same reference signals caa-validate measures in CAA. Both tools are handed identical impulse-response WAV files whose answer is known from theory, so the comparison is three-way: theory / CAA / REW. Needs REW 5.40 running with its REST API (roomeqwizard.exe -api). python rew_compare.py # import, measure, print and save the table """ import base64, json, os, struct, time, urllib.error, urllib.request import numpy as np import scipy.signal as ss API = "http://127.0.0.1:4735" HERE = os.path.dirname(os.path.abspath(__file__)) OUT = os.path.join(HERE, "refwav") SR = 48000.0 os.makedirs(OUT, exist_ok=True) def req(method, path, body=None, timeout=120): data = json.dumps(body).encode() if body is not None else None r = urllib.request.Request(API + path, data=data, method=method, headers={"Content-Type": "application/json"}) try: with urllib.request.urlopen(r, timeout=timeout) as f: raw = f.read().decode("utf-8", "replace") except urllib.error.HTTPError as e: raise RuntimeError("%s %s -> %d %s" % (method, path, e.code, e.read().decode("utf-8", "replace")[:200])) try: return json.loads(raw) except ValueError: return raw def write_wav(path, x): """32-bit float WAV -- keeps the 90 dB of range these references need.""" x = np.asarray(x, dtype=np.float32) with open(path, "wb") as f: n = len(x) * 4 f.write(b"RIFF" + struct.pack("