示例#1
0
def test_track():
    # test data home None
    track_default = medleydb_melody.Track('MusicDelta_Beethoven')
    assert track_default._data_home == os.path.join(DEFAULT_DATA_HOME,
                                                    'MedleyDB-Melody')

    data_home = 'tests/resources/mir_datasets/MedleyDB-Melody'

    with pytest.raises(ValueError):
        medleydb_melody.Track('asdfasdf', data_home=data_home)

    track = medleydb_melody.Track('MusicDelta_Beethoven', data_home=data_home)

    # test attributes
    assert track.track_id == 'MusicDelta_Beethoven'
    assert track._data_home == data_home
    assert track._track_paths == {
        'audio': [
            'audio/MusicDelta_Beethoven_MIX.wav',
            '4c6081420a506b438a851c2807fc28ea',
        ],
        'melody1': [
            'melody1/MusicDelta_Beethoven_MELODY1.csv',
            '67dca3f4a9bf0517dd8a1287d091791e',
        ],
        'melody2': [
            'melody2/MusicDelta_Beethoven_MELODY2.csv',
            '67dca3f4a9bf0517dd8a1287d091791e',
        ],
        'melody3': [
            'melody3/MusicDelta_Beethoven_MELODY3.csv',
            '340f647c4f12d7e1ecf2421d0dfd509f',
        ],
    }
    assert (track.audio_path == 'tests/resources/mir_datasets/' +
            'MedleyDB-Melody/audio/MusicDelta_Beethoven_MIX.wav')
    assert track.artist == 'MusicDelta'
    assert track.title == 'Beethoven'
    assert track.genre == 'Classical'
    assert track.is_excerpt is True
    assert track.is_instrumental is True
    assert track.n_sources == 18

    assert type(track.melody1) is utils.F0Data
    assert type(track.melody2) is utils.F0Data
    assert type(track.melody3) is utils.F0Data

    y, sr = track.audio
    assert sr == 44100
    assert y.shape == (44100 * 2, )

    repr_string = (
        "MedleyDb-Melody Track(track_id=MusicDelta_Beethoven, " +
        "audio_path=tests/resources/mir_datasets/MedleyDB-Melody/audio/" +
        "MusicDelta_Beethoven_MIX.wav, artist=MusicDelta, title=Beethoven," +
        " genre=Classical, is_excerpt=True, is_instrumental=True, " +
        "n_sources=18, melody1=F0Data('times', 'frequencies', confidence')," +
        " melody2=F0Data('times', 'frequencies', confidence'), " +
        "melody3=F0Data('times', 'frequencies', confidence'))")
    assert track.__repr__() == repr_string
示例#2
0
def test_track():
    default_trackid = 'MusicDelta_Beethoven'
    data_home = 'tests/resources/mir_datasets/MedleyDB-Melody'
    track = medleydb_melody.Track(default_trackid, data_home=data_home)

    expected_attributes = {
        'track_id': 'MusicDelta_Beethoven',
        'audio_path': 'tests/resources/mir_datasets/' +
        'MedleyDB-Melody/audio/MusicDelta_Beethoven_MIX.wav',
        'melody1_path': 'tests/resources/mir_datasets/' +
        'MedleyDB-Melody/melody1/MusicDelta_Beethoven_MELODY1.csv',
        'melody2_path': 'tests/resources/mir_datasets/' +
        'MedleyDB-Melody/melody2/MusicDelta_Beethoven_MELODY2.csv',
        'melody3_path': 'tests/resources/mir_datasets/' +
        'MedleyDB-Melody/melody3/MusicDelta_Beethoven_MELODY3.csv',
        'artist': 'MusicDelta',
        'title': 'Beethoven',
        'genre': 'Classical',
        'is_excerpt': True,
        'is_instrumental': True,
        'n_sources': 18,
    }

    expected_property_types = {
        'melody1': utils.F0Data,
        'melody2': utils.F0Data,
        'melody3': utils.MultipitchData,
    }

    run_track_tests(track, expected_attributes, expected_property_types)

    y, sr = track.audio
    assert sr == 44100
    assert y.shape == (44100 * 2, )
示例#3
0
def test_to_jams():

    data_home = 'tests/resources/mir_datasets/MedleyDB-Melody'
    track = medleydb_melody.Track('MusicDelta_Beethoven', data_home=data_home)
    jam = track.to_jams()

    f0s = jam.search(namespace='pitch_contour')[1]['data']
    assert [f0.time
            for f0 in f0s] == [0.046439909297052155, 0.052244897959183675]
    assert [f0.duration for f0 in f0s] == [0.0, 0.0]
    assert [f0.value for f0 in f0s] == [
        {
            'frequency': 0.0,
            'index': 0,
            'voiced': False
        },
        {
            'frequency': 965.992,
            'index': 0,
            'voiced': True
        },
    ]
    assert [f0.confidence for f0 in f0s] == [0.0, 1.0]

    assert jam['file_metadata']['title'] == 'Beethoven'
    assert jam['file_metadata']['artist'] == 'MusicDelta'