Exemplo n.º 1
0
def test_to_jams():

    data_home = 'tests/resources/mir_datasets/Orchset'
    track = orchset.Track('Beethoven-S3-I-ex1', data_home=data_home)
    jam = track.to_jams()

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

    assert jam['sandbox']['alternating_melody'] == True
Exemplo n.º 2
0
def test_track():
    default_trackid = 'Beethoven-S3-I-ex1'
    data_home = 'tests/resources/mir_datasets/Orchset'
    track = orchset.Track(default_trackid, data_home=data_home)

    expected_attributes = {
        'track_id': 'Beethoven-S3-I-ex1',
        'audio_path_mono': 'tests/resources/mir_datasets/Orchset/' +
        'audio/mono/Beethoven-S3-I-ex1.wav',
        'audio_path_stereo': 'tests/resources/mir_datasets/Orchset/' +
        'audio/stereo/Beethoven-S3-I-ex1.wav',
        'melody_path':
        'tests/resources/mir_datasets/Orchset/' + 'GT/Beethoven-S3-I-ex1.mel',
        'composer': 'Beethoven',
        'work': 'S3-I',
        'excerpt': '1',
        'predominant_melodic_instruments': ['strings', 'winds'],
        'alternating_melody': True,
        'contains_winds': True,
        'contains_strings': True,
        'contains_brass': False,
        'only_strings': False,
        'only_winds': False,
        'only_brass': False,
    }

    expected_property_types = {'melody': utils.F0Data}

    run_track_tests(track, expected_attributes, expected_property_types)

    y_mono, sr_mono = track.audio_mono
    assert sr_mono == 44100
    assert y_mono.shape == (44100 * 2, )

    y_stereo, sr_stereo = track.audio_stereo
    assert sr_stereo == 44100
    assert y_stereo.shape == (2, 44100 * 2)
Exemplo n.º 3
0
def test_track():
    # test data home None
    track_default = orchset.Track('Beethoven-S3-I-ex1')
    assert track_default._data_home == os.path.join(DEFAULT_DATA_HOME,
                                                    'Orchset')

    data_home = 'tests/resources/mir_datasets/Orchset'

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

    track = orchset.Track('Beethoven-S3-I-ex1', data_home=data_home)

    # test attributes
    assert track.track_id == 'Beethoven-S3-I-ex1'
    assert track._data_home == data_home
    assert track._track_paths == {
        "audio_stereo": [
            "audio/stereo/Beethoven-S3-I-ex1.wav",
            "f819c86bba06120a19bd495f819cd0ef",
        ],
        "audio_mono": [
            "audio/mono/Beethoven-S3-I-ex1.wav",
            "7bb7a2492dcf9e1eaad9e82f8550219a",
        ],
        "melody":
        ["GT/Beethoven-S3-I-ex1.mel", "8bbf6716337a2b5f7afcc611ad66e91a"],
    }
    assert (track.audio_path_mono == 'tests/resources/mir_datasets/' +
            'Orchset/audio/mono/Beethoven-S3-I-ex1.wav')
    assert (track.audio_path_stereo == 'tests/resources/mir_datasets/' +
            'Orchset/audio/stereo/Beethoven-S3-I-ex1.wav')
    assert track.composer == 'Beethoven'
    assert track.work == 'S3-I'
    assert track.excerpt == '1'
    assert track.predominant_melodic_instruments == ['strings', 'winds']
    assert track.alternating_melody is True
    assert track.contains_winds is True
    assert track.contains_strings is True
    assert track.contains_brass is False
    assert track.only_strings is False
    assert track.only_winds is False
    assert track.only_brass is False

    assert type(track.melody) is utils.F0Data

    y_mono, sr_mono = track.audio_mono
    assert sr_mono == 44100
    assert y_mono.shape == (44100 * 2, )

    y_stereo, sr_stereo = track.audio_stereo
    assert sr_stereo == 44100
    assert y_stereo.shape == (2, 44100 * 2)

    repr_string = (
        "Orchset Track(track_id=Beethoven-S3-I-ex1, " +
        "audio_path_stereo=tests/resources/mir_datasets/Orchset/audio/" +
        "stereo/Beethoven-S3-I-ex1.wav, " +
        "audio_path_mono=tests/resources/mir_datasets/Orchset/audio/" +
        "mono/Beethoven-S3-I-ex1.wav, composer=Beethoven, work=S3-I, " +
        "excerpt=1, predominant_melodic_instruments=['strings', 'winds'], " +
        "alternating_melody=True, contains_winds=True, contains_strings=True, "
        + "contains_brass=False, only_strings=False, only_winds=False, " +
        "only_brass=False, melody=F0Data('times', 'frequencies', 'confidence'))"
    )
    assert track.__repr__() == repr_string