Mercurial > hg > libxtract
view swig/python/test.py @ 214:f28f66faa016
Add "stateful" feature type with initial feature "last n"
Stateful feature extraction functions are functions that require state to be maintained between successive calls. This is necessary, for example when an accumulation of values is required, or changes need to be measured over time.
The initial xtract_last_n() function accumulates the last N (single) values from *data and writes them to *result
author | Jamie Bullock <jamie@jamiebullock.com> |
---|---|
date | Tue, 03 Jun 2014 21:17:07 +0100 |
parents | 826eb46b2f91 |
children |
line wrap: on
line source
#!/usr/bin/python try: import libxtract.xtract as 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'