From 89a9ec7a352dc35141b8f9a87c202fdd448e9a6f Mon Sep 17 00:00:00 2001 From: Jamie Bullock Date: Sat, 8 Nov 2014 00:06:06 +0000 Subject: Add Python bindings to build system --- swig/test.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 swig/test.py (limited to 'swig/test.py') diff --git a/swig/test.py b/swig/test.py new file mode 100644 index 0000000..4d14171 --- /dev/null +++ b/swig/test.py @@ -0,0 +1,57 @@ +#!/usr/bin/python + +try: + import xtract +except ImportError: + print 'Failed to load the library "xtract"' + +print '\nRunning libxtract Python bindings test...\n' + +len = 8 + +a = xtract.doubleArray(len) +temp = [] + +for i in range(0, len): + a[i] = 2 * i + temp.append(str(a[i])) + +mean = xtract.xtract_mean(a,len,None)[1] + +print 'The mean of ' + ', '.join(temp) + ' is: %.2f' % mean + +argv = xtract.doubleArray(1) +argv[0] = mean + +variance = xtract.xtract_variance(a, len, argv)[1] + +print 'The variance is %.2f' % variance + +print 'Computing spectrum...' + +argv = xtract.doubleArray(1) +argv[0] = 44100.0 / len # Fake sample rate + +xtract.xtract_init_fft(len, xtract.XTRACT_SPECTRUM); + +result = xtract.doubleArray(len) + +xtract.xtract_spectrum(a,len,argv, result) + + +for i in range(len): + print result[i] + + +print 'Computing windowed subframes...' + +for i in range(0, len): + a[i] = 1.0 + +window = xtract.xtract_init_window(len / 2, xtract.XTRACT_HANN) +xtract.xtract_features_from_subframes(a, len, xtract.XTRACT_WINDOWED, window, result) + +for i in range(len): + print result[i] + +print '\nFinished!\n' -- cgit v1.2.3