annotate test/test_collect.py @ 94:c3318a95625b

Return step as well
author Chris Cannam
date Mon, 02 Feb 2015 16:32:44 +0000
parents 4bed6bf67243
children f0e005248b9a
rev   line source
Chris@71 1
Chris@71 2 import vamp
Chris@71 3 import numpy as np
Chris@71 4
Chris@82 5 plugin_key = "vamp-test-plugin:vamp-test-plugin"
Chris@82 6 plugin_key_freq = "vamp-test-plugin:vamp-test-plugin-freq"
Chris@71 7
Chris@71 8 rate = 44100
Chris@71 9
Chris@71 10 # Throughout this file we have the assumption that the plugin gets run with a
Chris@71 11 # blocksize of 1024, and with a step of 1024 for the time-domain version or 512
Chris@71 12 # for the frequency-domain one. That is certainly expected to be the norm for a
Chris@71 13 # plugin like this that declares no preference, and the Python Vamp module is
Chris@71 14 # expected to follow the norm
Chris@71 15
Chris@71 16 blocksize = 1024
Chris@92 17 eps = 1e-6
Chris@71 18
Chris@71 19 def input_data(n):
Chris@71 20 # start at 1, not 0 so that all elts are non-zero
Chris@71 21 return np.arange(n) + 1
Chris@71 22
Chris@71 23 def test_collect_runs_at_all():
Chris@88 24 buf = input_data(blocksize * 10)
Chris@94 25 step, results = vamp.collect(buf, rate, plugin_key, "input-timestamp")
Chris@88 26 assert results != []
Chris@88 27
Chris@88 28 def test_collect_one_sample_per_step():
Chris@88 29 buf = input_data(blocksize * 10)
Chris@94 30 step, results = vamp.collect(buf, rate, plugin_key, "input-timestamp")
Chris@94 31 assert abs(float(step) - (1024.0 / rate)) < eps
Chris@88 32 assert len(results) == 10
Chris@93 33 for i in range(len(results)):
Chris@93 34 # The timestamp should be the frame number of the first frame in the
Chris@93 35 # input buffer
Chris@93 36 expected = i * blocksize
Chris@93 37 actual = results[i]
Chris@93 38 assert actual == expected
Chris@88 39
Chris@92 40 def test_collect_fixed_sample_rate():
Chris@92 41 buf = input_data(blocksize * 10)
Chris@94 42 step, results = vamp.collect(buf, rate, plugin_key, "curve-fsr")
Chris@94 43 assert abs(float(step) - 0.4) < eps
Chris@92 44 assert len(results) == 10
Chris@93 45 for i in range(len(results)):
Chris@93 46 assert abs(results[i] - i * 0.1) < eps
Chris@92 47
Chris@92 48 def test_collect_fixed_sample_rate_2():
Chris@92 49 buf = input_data(blocksize * 10)
Chris@94 50 step, results = vamp.collect(buf, rate, plugin_key, "curve-fsr-timed")
Chris@94 51 assert abs(float(step) - 0.4) < eps
Chris@92 52 assert len(results) == 10
Chris@93 53 for i in range(len(results)):
Chris@93 54 assert abs(results[i] - i * 0.1) < eps
Chris@92 55
Chris@92 56 def test_collect_variable_sample_rate():
Chris@92 57 buf = input_data(blocksize * 10)
Chris@94 58 results = vamp.collect(buf, rate, plugin_key, "curve-vsr")
Chris@92 59 assert len(results) == 10
Chris@92 60 i = 0
Chris@92 61 for r in results:
Chris@92 62 assert r["timestamp"] == vamp.vampyhost.RealTime('seconds', i * 0.75)
Chris@92 63 assert abs(r["values"][0] - i * 0.1) < eps
Chris@92 64 i = i + 1