Skip to content

Commit

Permalink
Stereo merge + test
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrmorrison committed Jul 15, 2024
1 parent f1f0462 commit d37da20
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion penn/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def audio(file):
"""Load audio from disk"""
audio, sample_rate = torchaudio.load(file)

# if audio is stereo convert to mono
# If audio is stereo, convert to mono
if audio.size(0) == 2:
warnings.warn(f'Converting stereo audio to mono: {file}')
audio = audio.mean(dim=0, keepdim=True)
Expand Down
3 changes: 2 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def audio():
"""Retrieve the test audio"""
return penn.load.audio(Path(__file__).parent / 'assets' / 'gershwin.wav')


@pytest.fixture(scope='session')
def audio_stereo():
"""Retrieve the test audio"""
return penn.load.audio(Path(__file__).parent / 'assets' / '500Hz_stereo.wav')
return penn.load.audio(Path(__file__).parent / 'assets' / '500Hz_stereo.wav')
3 changes: 2 additions & 1 deletion test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ def test_infer(audio):
shape = (1, audio.shape[1] // penn.HOPSIZE)
assert pitch.shape == periodicity.shape == shape


def test_infer_stereo(audio_stereo):
"""Test that inference on stereo audio produces the correct shape"""
pitch, periodicity = penn.from_audio(
audio_stereo,
penn.SAMPLE_RATE,
center='half-hop')
shape = (1, audio_stereo.shape[1] // penn.HOPSIZE)
assert pitch.shape == periodicity.shape == shape
assert pitch.shape == periodicity.shape == shape

0 comments on commit d37da20

Please sign in to comment.