# Is a music bank's wave 1 the SAME instruments filtered, or DIFFERENT parts?
# BGM_103 (the menu's music) -- 2026-08-30
#
# 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 correctly notes
# that runtime simultaneity cannot separate them, because both predict it.
# This is a static attempt at a discriminator.
#
# METHOD: magnitude-squared coherence, Welch, NFFT 8192 @ 48 kHz, 60 s window
# (702 segments, so the bias floor is ~1/702 = 0.0014). Coherence is ~1 wherever
# one signal is a LINEAR FILTER of the other and ~0 for independent signals.
# tools/re-capture/bgm_stem_coherence.py
#
# WAVES: slb_extract_wave.py BGM_103.slb 14336 1893 2 48000   (wave 0)
#        slb_extract_wave.py BGM_103.slb 3903488 1919 2 48000 (wave 1)
#        then ffmpeg -i x.riff x.wav. Both decode to 87.744 s, 4 211 729 frames.
# CONTROL BANK: BGM_104.slb 14336 1305 (a different piece, same codec).
#
CONTROLS
  POS w0 vs linear-filter(w0)        0-0.2k 0.929  0.2-1k 0.938  1-4k 0.936  4-12k 0.938  12-16k 0.938  16-24k 0.937
  NEG w0 vs a different bank         0-0.2k 0.001  0.2-1k 0.001  1-4k 0.001  4-12k 0.001  12-16k 0.001  16-24k 0.002
  NEG w0 vs w0 shifted 1 s           0-0.2k 0.057  0.2-1k 0.048  1-4k 0.007  4-12k 0.019  12-16k 0.015  16-24k 0.004
  REF w0 L vs R (one perf.)          0-0.2k 0.321  0.2-1k 0.221  1-4k 0.363  4-12k 0.445  12-16k 0.497  16-24k 0.450
  REF w1 L vs R (one perf.)          0-0.2k 0.078  0.2-1k 0.051  1-4k 0.089  4-12k 0.411  12-16k 0.453  16-24k 0.455

MEASUREMENT
  w0 vs w1                           0-0.2k 0.169  0.2-1k 0.184  1-4k 0.027  4-12k 0.635  12-16k 0.768  16-24k 0.827

ENERGY SHARE
  w0                                 0-0.2k  71.4%  0.2-1k  24.8%  1-4k   2.4%  4-12k   1.0%  12-16k   0.1%  16-24k   0.2%
  w1                                 0-0.2k  53.8%  0.2-1k  40.9%  1-4k   2.3%  4-12k   2.1%  12-16k   0.3%  16-24k   0.6%

# ------------------------------------------------------------------------------
# READING IT
#
# ✅ THE INSTRUMENT IS CALIBRATED. A real linear filter of w0 reads 0.93-0.94 in
# every band; a different bank reads 0.001-0.002; w0 against itself misaligned by
# 1 s reads 0.004-0.057. So the estimator detects filtering and is not fooled by
# two pieces of music in the same codec.
#
# ❌ REFUTED: "wave 1 is wave 0 put through a filter." The positive control says
# a filter reads 0.936 at 1-4 kHz. The measurement reads 0.027 there. No linear
# filter produces that in a band where both waves carry energy.
#
# 📌 THE FREQUENCY STRUCTURE IS INVERTED relative to any mic-pair or reverb
# model. Coherence RISES with frequency -- 0.169, 0.184, 0.027, 0.635, 0.768,
# 0.827 -- while energy FALLS -- 71.4 %, 24.8 %, 2.4 %, 1.0 %, 0.1 %, 0.2 %.
# A rear pair or a reverb return decorrelates FASTEST at high frequency, which
# is the opposite. What is coherent lives in bands holding ~1.3 % of the energy;
# the bands holding 96 % of it read 0.169 and 0.184.
#
# 📌 AND IN THE MUSICAL MIDRANGE THE TWO WAVES ARE FURTHER APART THAN THE TWO
# CHANNELS OF ONE WAVE: 1-4 kHz gives 0.027 between waves against 0.363 for w0's
# own L vs R -- a factor of 13. Two channels of one performance agree far more
# than the two waves do.
#
# 🔴 BUT THE L-R CONTROL IS ALSO WHAT LIMITS THIS TOOL, AND IT KILLS THE CLEAN
# ANSWER. L vs R within a single wave is genuinely "one performance, two
# channels", and it reads only 0.221-0.497 -- nowhere near the 0.94 a filter
# gives. So in THIS material "same performance" does not imply high coherence,
# which means my positive control was the wrong model of the rear-pair reading:
# a real 4-channel mix's rear pair is not a linear filter of its front pair.
#
# => The filter model is dead. The two named readings are NOT separated. This
#    tool cannot separate them, and the reason is stated rather than discovered
#    later: it tests for linear filtering, and neither reading requires it.
#
# ⚠️ REACH: one bank (BGM_103), one 60 s window, mono-summed for the coherence
# rows. Not run over the other 31 banks. The 16-24 kHz reading of 0.827 sits in
# 0.2-0.6 % of the energy and is unexplained -- it is NOT generic codec
# behaviour, since the different-bank control reads 0.002 in the same band.
