예제 #1
0
def test_process_output_1ch():
    plug = vh.load_plugin(plugin_key, rate, vh.ADAPT_NONE)
    plug.initialise(1, 2, 2)
    try:
        # Too many channels
        result = plug.process_block([[3, 4], [5, 6]], vh.RealTime(0, 0))
        assert False
    except TypeError:
        pass
    result = plug.process_block([[3, 3]], vh.RealTime(0, 0))
    assert result[9] == [{"label": "", "values": np.array([5.0])}]
    result = plug.process_block([[3, 0]], vh.RealTime(0, 0))
    assert result[9] == [{"label": "", "values": np.array([4.0])}]
예제 #2
0
def get_feature_step_time(sample_rate, step_size, output_desc):
    if output_desc["sampleType"] == vampyhost.ONE_SAMPLE_PER_STEP:
        return vampyhost.frame_to_realtime(step_size, sample_rate)
    elif output_desc["sampleType"] == vampyhost.FIXED_SAMPLE_RATE:
        return vampyhost.RealTime('seconds', 1.0 / output_desc["sampleRate"])
    else:
        return 1
예제 #3
0
def test_process_without_initialise():
    plug = vh.load_plugin(plugin_key, rate, vh.ADAPT_NONE)
    try:
        plug.process_block([[1, 2, 3, 4]], vh.RealTime(0, 0))
        assert False
    except Exception:
        pass
예제 #4
0
def test_process_output_2ch():
    plug = vh.load_plugin(plugin_key, rate, vh.ADAPT_NONE)
    plug.initialise(2, 2, 2)
    try:
        # Too few channels
        result = plug.process_block([[3, 4]], vh.RealTime(0, 0))
        assert False
    except TypeError:
        pass
    try:
        # Too many channels
        result = plug.process_block([[3, 4], [5, 6], [7, 8]],
                                    vh.RealTime(0, 0))
        assert False
    except TypeError:
        pass
    result = plug.process_block([[3, 3], [4, 4]], vh.RealTime(0, 0))
    assert (result[9][0]["values"] == np.array([5.0, 6.0])).all()
    result = plug.process_block([[3, 0], [4, 0]], vh.RealTime(0, 0))
    assert (result[9][0]["values"] == np.array([4.0, 5.0])).all()
예제 #5
0
def test_process_input_format():
    plug = vh.load_plugin(plugin_key, rate, vh.ADAPT_NONE)
    plug.initialise(2, 4, 4)  # channels, stepsize, blocksize
    result = plug.process_block([[1, 2, 3, 4], [5, 6, 7, 8]],
                                vh.RealTime(0, 0))
    result = plug.process_block(
        [np.array([1, 2, 3, 4]),
         np.array([5, 6, 7, 8])], vh.RealTime(0, 0))
    result = plug.process_block(np.array([[1, 2, 3, 4], [5, 6, 7, 8]]),
                                vh.RealTime(0, 0))
    try:
        # Wrong number of channels
        result = plug.process_block(np.array([[1, 2, 3, 4]]),
                                    vh.RealTime(0, 0))
        assert False
    except TypeError:
        pass
    try:
        # Wrong number of samples per channel
        result = plug.process_block(np.array([[1, 2, 3], [4, 5, 6]]),
                                    vh.RealTime(0, 0))
        assert False
    except TypeError:
        pass
    try:
        # Differing numbers of samples per channel
        result = plug.process_block(np.array([[1, 2, 3, 4], [5, 6, 7]]),
                                    vh.RealTime(0, 0))
        assert False
    except TypeError:
        pass
예제 #6
0
def vampy_decoder(dct):
    if '__realtime__' in dct:
            x = dct['__realtime__'][0]
            y = dct['__realtime__'][1]
            return vampyhost.RealTime(x, y)
    if '__float32__' in dct:
            # print('__float32__')
            # print(type(dct['__float32__']))
            return numpy.float32(dct['__float32__'])
    if '__ndarray__' in dct:
            # print('__ndarray__')
            # print(dct['__ndarray__'])
            x = numpy.array(dct['__ndarray__'])
            return x

    print(type(dct))
    print(dct)
    return dct
예제 #7
0
def timestamp_features(sample_rate, step_size, output_desc, features):
    n = -1
    if output_desc["sampleType"] == vampyhost.ONE_SAMPLE_PER_STEP:
        for f in features:
            n = n + 1
            t = vampyhost.frame_to_realtime(n * step_size, sample_rate)
            f["timestamp"] = t
            yield f
    elif output_desc["sampleType"] == vampyhost.FIXED_SAMPLE_RATE:
        output_rate = output_desc["sampleRate"]
        for f in features:
            if "has_timestamp" in f:
                n = int(f["timestamp"].to_float() * output_rate + 0.5)
            else:
                n = n + 1
            f["timestamp"] = vampyhost.RealTime('seconds',
                                                float(n) / output_rate)
            yield f
    else:
        for f in features:
            yield f