Code
import matplotlib.pyplot as plt
import sonore as so
plt.rcParams.update({"font.size": 9, "axes.titlesize": 10, "figure.dpi": 100})
FS = 44100
def finish(snd):
"""How every sound in the gallery is played: 5 ms ramps, RMS 0.1, peak at most 0.95."""
snd = snd.ramp(5e-3).normalize(rms=0.1)
return snd.normalize(peak=0.95) if snd.peak > 0.95 else snd
def show(snd):
"""Waveforms, ITD and ILD, and interaural correlation, all on one time axis.
Returns the figure and the panels the playhead follows."""
fig, axes = plt.subplots(3, 1, figsize=(10, 6.6), sharex=True, layout="constrained")
snd.plot(axes[0], lw=0.4)
axes[0].set_title("Waveform, left and right")
cues = so.interaural_cues(snd, win_dur=10e-3)
cues.plot(axes[1])
axes[1].set_xlabel("")
axes[2].plot(cues.t, cues.corr0, color="tab:orange", lw=1, label="correlation at zero lag")
axes[2].plot(cues.t, cues.iac, color="k", alpha=0.6, lw=1, label="coherence (peak over lags)")
axes[2].axhline(0, color="k", alpha=0.25, lw=0.8)
axes[2].set(ylim=(-1.05, 1.05), ylabel="Interaural corr.", xlabel="Time [s]", xlim=(0, snd.duration))
axes[2].legend(loc="lower right", fontsize=8)
axes[2].grid(ls=":")
return fig, list(axes)