annotate swig/python/test.py @ 103:1cbbe5b5e461

- Added some previously uncommitted Pd testing examples - Improved python bindings. Now we can do vector features as well as scalar from Python
author Jamie Bullock <jamie@postlude.co.uk>
date Fri, 21 Dec 2007 11:05:20 +0000
parents 35a3bb5c3ffd
children 9518ae6afff4
rev   line source
jamie@88 1 #!/usr/bin/python
jamie@88 2
jamie@92 3 try:
jamie@92 4 import xtract
jamie@92 5 except ImportError:
jamie@103 6 print 'Failed to load the library "xtract"'
jamie@92 7
jamie@92 8 print '\nRunning libxtract Python bindings test...\n'
jamie@88 9
jamie@103 10 len = 8
jamie@88 11
jamie@88 12 a = xtract.floatArray(len)
jamie@92 13 temp = []
jamie@88 14
jamie@88 15 for i in range(0, len):
jamie@88 16 a[i] = 2 * i
jamie@92 17 temp.append(str(a[i]))
jamie@88 18
jamie@92 19 print 'The mean of ' + ', '.join(temp) + ' is: %.2f' % \
jamie@92 20 xtract.xtract_mean(a,len,None)[1]
jamie@88 21
jamie@103 22 print 'Computing spectrum...'
jamie@103 23
jamie@103 24 argv = xtract.floatArray(1)
jamie@103 25 argv[0] = 44100.0 / len # Fake sample rate
jamie@103 26
jamie@103 27 xtract.xtract_init_fft(len, xtract.XTRACT_SPECTRUM);
jamie@103 28
jamie@103 29 result = xtract.floatArray(len)
jamie@103 30
jamie@103 31 xtract.xtract_spectrum(a,len,argv, result)
jamie@103 32
jamie@103 33
jamie@103 34 for i in range(len):
jamie@103 35 print result[i]
jamie@103 36
jamie@92 37 print '\nFinished!\n'