-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from thunn/thunn/add_convert_for_frequency_to_…
…midi Thunn/add convert for frequency to midi
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: run | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.8", "3.10"] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install base dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -e . | ||
pip install soundfile pytest | ||
- name: Run core tests | ||
run: | | ||
python -m pytest --ignore test/test_convert.py | ||
- name: Install additional test dependencies | ||
run: | | ||
pip install -e '.[test]' | ||
- name: Run all tests | ||
run: | | ||
python -m pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import penn | ||
|
||
import librosa | ||
import torch | ||
|
||
|
||
############################################################################### | ||
# Test convert.py | ||
############################################################################### | ||
|
||
|
||
def test_convert_frequency_to_midi(): | ||
"""Test that conversion from Hz to MIDI matches librosa implementation""" | ||
|
||
sample_data = torch.tensor([110.0, 220.0, 440.0, 500.0, 880.0]) | ||
|
||
penn_midi = penn.convert.frequency_to_midi(sample_data) | ||
|
||
librosa_midi = librosa.hz_to_midi(sample_data.numpy()) | ||
|
||
assert torch.allclose(penn_midi, torch.tensor(librosa_midi, dtype=torch.float32)) | ||
|
||
def test_convert_midi_to_frequency(): | ||
"""Test that conversion from MIDI to Hz matches librosa implementation""" | ||
|
||
sample_data = torch.tensor([45.0, 57.0, 69.0, 71.2131, 81.0]) | ||
|
||
penn_frequency = penn.convert.midi_to_frequency(sample_data) | ||
|
||
librosa_frequency = librosa.midi_to_hz(sample_data.numpy()) | ||
|
||
assert torch.allclose(penn_frequency, torch.tensor(librosa_frequency, dtype=torch.float32)) |