Beispiel #1
0
def test_get_relative_speaker_positions_spherical():

    # Path does not exist
    sofa_reverb_name = 'fake_reverb.sofa'
    sofa_reverb = SOFAReverb()
    pytest.raises(AmbiScaperError,
                  sofa_reverb.get_relative_speaker_positions_spherical,
                  sofa_reverb_name)

    # In sala1.sofa there is only one emitter, located at [1,0,0] cartesian
    # EmitterPosition has dimensions (E,C,I)

    sofa_path = os.path.abspath('./SOFA')
    # sofa_path = os.path.abspath('/Volumes/Dinge/SOFA/pinakothek/')

    sofa_reverb.set_sofa_reverb_folder_path(sofa_path)

    sofa_reverb_name = 'sala1.sofa'
    # sofa_reverb_name = 'room7_eigenmike.sofa'
    # 8 speakers distributed in azimuth, elevation 8, distance 1
    # Since Listener view is +90, everything will be shifted...
    groundtruth = [
        [0, 0., 1.],
        [0, 0., 2.],
        [0, 0., 3.],
        [0, 0., 4.],
        [-np.pi / 2, 0., 1.],
        [-np.pi / 2, 0., 2.],
    ]

    assert np.allclose(
        groundtruth,
        sofa_reverb.get_relative_speaker_positions_spherical(sofa_reverb_name))
Beispiel #2
0
def test_retrieve_available_sofa_reverb_files():

    # Error if path not specified
    sofa_reverb = SOFAReverb()
    pytest.raises(AmbiScaperError,
                  sofa_reverb.retrieve_available_sofa_reverb_files)

    sofa_path = os.path.abspath('./SOFA')
    sofa_reverb.set_sofa_reverb_folder_path(sofa_path)

    # At the moment we have only one
    groundtruth = ['sala1.sofa']

    # Check with unordered lists
    assert set(
        sofa_reverb.retrieve_available_sofa_reverb_files()) == set(groundtruth)
Beispiel #3
0
def test_set_sofa_reverb_folder_path():

    # Path does not exist
    sofa_path = os.path.abspath('./fake_path')
    sofa_reverb = SOFAReverb()
    pytest.raises(AmbiScaperError, sofa_reverb.set_sofa_reverb_folder_path,
                  sofa_path)

    # Path not a folder
    sofa_path = os.path.abspath('./SOFA/sala1.sofa')
    pytest.raises(AmbiScaperError, sofa_reverb.set_sofa_reverb_folder_path,
                  sofa_path)

    # Test correct
    sofa_path = os.path.abspath('./SOFA')
    sofa_reverb.set_sofa_reverb_folder_path(sofa_path)
    assert sofa_reverb.get_sofa_reverb_folder_path() == sofa_path
Beispiel #4
0
def test_generate_sofa_file_full_path():

    # SOFA path not specified
    sofa_reverb = SOFAReverb()
    pytest.raises(AmbiScaperError, sofa_reverb.generate_sofa_file_full_path,
                  'sala1.sofa')

    # Not valid arg
    sofa_path = os.path.abspath('./SOFA')
    sofa_reverb.set_sofa_reverb_folder_path(sofa_path)

    pytest.raises(AmbiScaperError, sofa_reverb.generate_sofa_file_full_path,
                  123)
    pytest.raises(AmbiScaperError, sofa_reverb.generate_sofa_file_full_path,
                  'FakeReverb')

    # test valid
    rootpath = os.path.abspath('./SOFA')
    path = os.path.join(rootpath, 'sala1.sofa')
    assert path == sofa_reverb.generate_sofa_file_full_path('sala1.sofa')
Beispiel #5
0
 def __assert_correct_tuple(tuple):
     sofa_path = os.path.abspath('./SOFA')
     sofa_reverb = SOFAReverb()
     sofa_reverb.set_sofa_reverb_folder_path(sofa_path)
     try:
         sofa_reverb._validate_reverb_name(tuple)
     except AmbiScaperError:
         raise AmbiScaperError
Beispiel #6
0
def test_get_sofa_reverb_folder_path():

    # Path not defined
    sofa_reverb = SOFAReverb()
    assert sofa_reverb.get_sofa_reverb_folder_path() == None

    # Test correct
    sofa_path = os.path.abspath('./SOFA')
    sofa_reverb.set_sofa_reverb_folder_path(sofa_path)
    assert sofa_reverb.get_sofa_reverb_folder_path() == sofa_path
Beispiel #7
0
def test_validate_SOFA_reverb_spec():

    sofa_path = os.path.abspath('./SOFA')
    sofa_reverb = SOFAReverb()
    sofa_reverb.set_sofa_reverb_folder_path(sofa_path)

    # bad name
    pytest.raises(AmbiScaperError, sofa_reverb._validate_reverb_spec,
                  *[('const', 'fakeReverb'), ('const', 'wrap_azimuth')])
    # bad wrap
    pytest.raises(AmbiScaperError, sofa_reverb._validate_reverb_spec,
                  *[('const', 'sala1.sofa'), ('const', 'fakeWrap')])
    # correct values
    try:
        sofa_reverb._validate_reverb_spec(('const', 'sala1.sofa'),
                                          ('const', 'wrap_azimuth'))
    except AmbiScaperError:
        raise AmbiScaperError
Beispiel #8
0
 def __test_correct_values(arg, groundtruth):
     sofa_path = os.path.abspath('./SOFA')
     sofa_reverb = SOFAReverb()
     sofa_reverb.set_sofa_reverb_folder_path(sofa_path)
     assert groundtruth == sofa_reverb.get_maximum_ambisonics_order_from_spec(
         arg)
Beispiel #9
0
 def __test_not_valid(arg):
     sofa_path = os.path.abspath('./SOFA')
     sofa_reverb = SOFAReverb()
     sofa_reverb.set_sofa_reverb_folder_path(sofa_path)
     pytest.raises(AmbiScaperError,
                   sofa_reverb.get_maximum_ambisonics_order_from_spec, arg)
Beispiel #10
0
 def __test_bad_tuple(tuple):
     sofa_path = os.path.abspath('./SOFA')
     sofa_reverb = SOFAReverb()
     sofa_reverb.set_sofa_reverb_folder_path(sofa_path)
     pytest.raises(AmbiScaperError, sofa_reverb._validate_reverb_name,
                   tuple)
Beispiel #11
0
 def __assert_correct_tuple(tuple):
     try:
         SOFAReverb()._validate_reverb_wrap(tuple)
     except AmbiScaperError:
         raise AmbiScaperError
Beispiel #12
0
 def __test_bad_tuple(tuple):
     pytest.raises(AmbiScaperError,
                   SOFAReverb()._validate_reverb_wrap, tuple)