Ejemplo n.º 1
0
def build_rir_wrap(time, alpha, visibility, fs, fdl):

    # fractional delay length
    fdl = pra.constants.get("frac_delay_length")
    fdl2 = (fdl - 1) // 2

    # the number of samples needed
    N = int(np.ceil(time.max() * fs) + fdl)

    ir_ref = np.zeros(N)
    ir_cython = np.zeros(N)

    # Try to use the Cython extension
    build_rir.fast_rir_builder(ir_cython, time, alpha, visibility, fs, fdl)

    # fallback to pure Python implemenation
    for i in range(time.shape[0]):
        if visibility[i] == 1:
            time_ip = int(np.round(fs * time[i]))
            time_fp = (fs * time[i]) - time_ip
            ir_ref[time_ip - fdl2 : time_ip + fdl2 + 1] += alpha[
                i
            ] * pra.fractional_delay(time_fp)

    return ir_ref, ir_cython
Ejemplo n.º 2
0
def test_short():
    ''' Tests that an error is raised if a provided time goes below the zero index '''

    if not build_rir_available:
        return

    N = 100
    fs = 16000
    fdl = 81
    rir = np.zeros(N)

    time = np.array([0.])
    alpha = np.array([1.])
    visibility = np.array([1], dtype=np.int32)

    try:
        build_rir.fast_rir_builder(rir, time, alpha, visibility, fs, fdl)
        assert False
    except AssertionError:
        print('Ok, short times are caught')
Ejemplo n.º 3
0
def test_long():
    ''' Tests that an error is raised if a time falls outside the rir array '''

    if not build_rir_available:
        return

    N = 100
    fs = 16000
    fdl = 81
    rir = np.zeros(N)

    time = np.array([(N-1) / fs])
    alpha = np.array([1.])
    visibility = np.array([1], dtype=np.int32)

    try:
        build_rir.fast_rir_builder(rir, time, alpha, visibility, fs, fdl)
        assert False
    except AssertionError:
        print('Ok, long times are caught')
Ejemplo n.º 4
0
def test_errors():
    ''' Tests that errors are raised when array lengths differ '''

    if not build_rir_available:
        return

    N = 300
    fs = 16000
    fdl = 81
    rir = np.zeros(N)

    time = np.array([100 / fs, 200 / fs])
    alpha = np.array([1., 1.])
    visibility = np.array([1, 1], dtype=np.int32)

    try:
        build_rir.fast_rir_builder(rir, time, alpha[:1], visibility, fs, fdl)
        assert False
    except:
        print('Ok, alpha error occured')
        pass

    try:
        build_rir.fast_rir_builder(rir, time, alpha, visibility[:1], fs, fdl)
        assert False
    except:
        print('Ok, visibility error occured')
        pass

    try:
        build_rir.fast_rir_builder(rir, time, alpha, visibility, fs, 80)
        assert False
    except:
        print('Ok, fdl error occured')
        pass