From 6b82ddef3675ba7613aa454f74bc182ee3ade4a3 Mon Sep 17 00:00:00 2001 From: Brian McFee Date: Thu, 4 Apr 2024 17:34:25 -0400 Subject: [PATCH] fixed #332, pitch contour sonification supports nans (#379) --- mir_eval/sonify.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mir_eval/sonify.py b/mir_eval/sonify.py index 45d059f6..e05be5e5 100644 --- a/mir_eval/sonify.py +++ b/mir_eval/sonify.py @@ -224,7 +224,7 @@ def pitch_contour( time indices for each frequency measurement, in seconds frequencies : np.ndarray frequency measurements, in Hz. - Non-positive measurements will be interpreted as un-voiced samples. + Non-positive measurements or NaNs will be interpreted as un-voiced samples. fs : int desired sampling rate of the output signal amplitudes : np.ndarray @@ -252,6 +252,8 @@ def pitch_contour( # Squash the negative frequencies. # wave(0) = 0, so clipping here will un-voice the corresponding instants frequencies = np.maximum(frequencies, 0.0) + # Convert nans to zeros to unvoice + frequencies = np.nan_to_num(frequencies, copy=False) # Build a frequency interpolator f_interp = interp1d(