view swig/python/test.py @ 110:c8502708853b

- Improvements to SWIG bindings generation script - Fixed omission in xtract_bark_coefficients that was causing the output to be complete b/s! This fixed bark_coeffs and loudness feature which depends on it - Changes to descriptor API: added is_delta and id. id corresponds to value in xtract_features_ enum and is useful for programmatic conversions between id and name string.
author Jamie Bullock <jamie@postlude.co.uk>
date Tue, 01 Jan 2008 16:17:44 +0000
parents 9518ae6afff4
children aadc06a1b317
line wrap: on
line source
#!/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.floatArray(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.floatArray(1)
argv[0] = mean

variance = xtract.xtract_variance(a, len, argv)[1]

print 'The variance is %.2f' % variance

print 'Computing spectrum...'

argv = xtract.floatArray(1)
argv[0] = 44100.0 / len  # Fake sample rate

xtract.xtract_init_fft(len, xtract.XTRACT_SPECTRUM);

result = xtract.floatArray(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'