Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions services/analysis-engine/tests/test_pitch_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,30 @@ def test_pitch_tracker_confidence_returns_low() -> None:

result = tracker._compute_confidence(voiced_probs, voiced_flag, y)
assert result == "low"


def test_pitch_tracker_nan_f0() -> None:
"""Test when pyin returns NaN for voiced f0 values."""
tracker = PitchTracker()
y = np.random.randn(22050)

with patch(
"librosa.pyin",
return_value=(np.array([np.nan, np.nan]), np.array([True, True]), np.array([1.0, 1.0])),
):
result = tracker.track(y, sr=22050)
assert result["lowest_note"] is None
assert result["highest_note"] is None
assert result["confidence"] == "low"


def test_pitch_tracker_low_avg_prob() -> None:
"""Test when average voicing probability is less than 0.2."""
tracker = PitchTracker()
y = np.random.randn(22050)

with patch("librosa.pyin", return_value=(np.array([440.0]), np.array([True]), np.array([0.1]))):
result = tracker.track(y, sr=22050)
assert result["lowest_note"] is None
assert result["highest_note"] is None
assert result["confidence"] == "low"