#!/usr/bin/env python3 """Are a music bank's two waves the SAME instruments filtered, or DIFFERENT parts? `structures/bgm-two-stems.md` leaves two readings alive for wave 1 -- the rear pair of a 4-channel mix, or a second intensity layer -- and notes that runtime simultaneity cannot separate them, since both predict it. This tries a static discriminator. Magnitude-squared coherence is ~1 wherever one signal is a LINEAR FILTER of the other, and ~0 for independent signals, so a rear pair modelled as "front pair, filtered" should read high and a different arrangement layer should read low. ⚠️ READ THE CONTROLS BEFORE THE MEASUREMENT. The L-vs-R control below is the one that matters and it is the one that limits this tool: see the docs page. bgm_stem_coherence.py Waves come from slb_extract_wave.py + ffmpeg; see the docs page for the exact offsets and packet counts. """ import sys, wave, numpy as np NFFT, HOP, FS = 8192, 4096, 48000 BANDS = [(0,200),(200,1000),(1000,4000),(4000,12000),(12000,16000),(16000,24000)] def load(p, nmax, stereo=False): w = wave.open(p); n = min(nmax, w.getnframes()) a = np.frombuffer(w.readframes(n), dtype="=lo)&(f=lo)&(f