thebeat
thebeat copied to clipboard
Add REPP-like phase/alignment calculations?
See:
- https://computational-audition.gitlab.io/repp/signal_processing/onset_alignment.html
- https://gitlab.com/computational-audition/repp/-/blob/master/repp/analysis.py?ref_type=heads
Proof of concept with some NumPy broadcasting magic:
import numpy as np
ref_onsets = np.array([500, 1500, 2000, 3000])
ref_iois = np.diff(ref_onsets)
test_onsets = np.array([-100, 100, 500, 600, 1000, 1400, 1500, 1600, 2000, 2500, 3000, 3500, 4000])
onset_offsets = test_onsets[:, None] - ref_onsets[None, :]
prev_ref_iois = np.concatenate([[ref_iois[0]], ref_iois])
next_ref_iois = np.concatenate([ref_iois, [ref_iois[-1]]])
matching_iois = np.where(onset_offsets < 0, prev_ref_iois, next_ref_iois)
phase_offsets = onset_offsets / matching_iois
print([phase for (distance, phase) in zip(np.abs(onset_offsets).ravel(), phase_offsets.ravel()) if -0.4 < phase < 0.4 and distance < 1999])