merge from main branch
authorPaul Brossier <piem@piem.org>
Tue, 30 Oct 2007 02:33:19 +0000 (03:33 +0100)
committerPaul Brossier <piem@piem.org>
Tue, 30 Oct 2007 02:33:19 +0000 (03:33 +0100)
1  2 
tests/python/pitchdetection.py
tests/python/run_all_tests

index 0000000,0000000..c2114fb
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,106 @@@
++import unittest
++
++from aubio.aubiowrapper import *
++
++buf_size = 4096
++hop_size = 512
++channels = 1
++samplerate = 44100.
++
++class pitchdetection_test_case(unittest.TestCase):
++
++  def setUp(self, type = aubio_pitch_yinfft, mode = aubio_pitchm_freq):
++    self.create(type=type)
++  
++  def create(self, type = aubio_pitch_yinfft,
++      mode = aubio_pitchm_freq):
++    self.type = type
++    self.o = new_aubio_pitchdetection(buf_size, hop_size,
++        channels, int(samplerate), type, mode)
++
++  def tearDown(self):
++    del_aubio_pitchdetection(self.o)
++
++  def test_pitchdetection(self):
++    """ create and delete pitchdetection """
++    pass
++
++  def test_pitchdetection_run_zeroes(self):
++    """ run pitchdetection on an empty buffer """
++    vec = new_fvec(buf_size, channels)
++    for i in range(100):
++      self.assertEqual(aubio_pitchdetection(self.o,vec),0.)
++    del vec
++
++  def test_pitchdetection_run_4_impulses(self):
++    """ run pitchdetection on a train of 4 impulses """
++    vec = new_fvec(buf_size, channels)
++    fvec_write_sample(vec,-1.,0,  0)
++    fvec_write_sample(vec, 1.,0,  buf_size/4)
++    fvec_write_sample(vec,-1.,0,  buf_size/2)
++    fvec_write_sample(vec, 1.,0,3*buf_size/4)
++    frequency = samplerate/2*4/buf_size
++    for i in range(100):
++      self.assertEqual(aubio_pitchdetection(self.o,vec),frequency)
++    del vec
++
++  def test_pitchdetection_run_4_positive_impulses(self):
++    """ run pitchdetection on a train of 4 positive impulses of arbitrary size """
++    vec = new_fvec(buf_size, channels)
++    frequency = samplerate/2*8/buf_size
++    for i in range(100):
++      fvec_write_sample(vec, 2.-.01*i,0,  0)
++      fvec_write_sample(vec, 2.-.01*i,0,  buf_size/4)
++      fvec_write_sample(vec, 2.-.01*i,0,  buf_size/2)
++      fvec_write_sample(vec, 2.-.01*i,0,3*buf_size/4)
++      self.assertAlmostEqual(aubio_pitchdetection(self.o,vec),frequency,1)
++    del vec
++
++  def test_pitchdetection_run_4_negative_impulses(self):
++    """ run pitchdetection on a train of 4 negative impulses of arbitrary size """
++    vec = new_fvec(buf_size, channels)
++    frequency = samplerate/2*8/buf_size
++    for i in range(1,100):
++      fvec_write_sample(vec,-.01*i,0,  0)
++      fvec_write_sample(vec,-.01*i,0,  buf_size/4)
++      fvec_write_sample(vec,-.01*i,0,  buf_size/2)
++      fvec_write_sample(vec,-.01*i,0,3*buf_size/4)
++      self.assertAlmostEqual(aubio_pitchdetection(self.o,vec),frequency,1)
++    del vec
++
++  def test_pitchdetection_run_8_impulses(self):
++    """ run pitchdetection on a train of 8 impulses """
++    vec = new_fvec(buf_size, channels)
++    fvec_write_sample(vec, 1.,0,  0)
++    fvec_write_sample(vec,-1.,0,  buf_size/8)
++    fvec_write_sample(vec, 1.,0,  buf_size/4)
++    fvec_write_sample(vec,-1.,0,3*buf_size/8)
++    fvec_write_sample(vec, 1.,0,  buf_size/2)
++    fvec_write_sample(vec,-1.,0,5*buf_size/8)
++    fvec_write_sample(vec, 1.,0,3*buf_size/4)
++    fvec_write_sample(vec,-1.,0,7*buf_size/8)
++    for i in range(100):
++      self.assertAlmostEqual(aubio_pitchdetection(self.o,vec),
++        samplerate/2/buf_size*8, 1) 
++    del vec
++
++"""
++class pitchdetection_yin_test_case(pitchdetection_test_case):
++  def setUp(self, type = aubio_pitch_yin):
++    self.create(type=type)
++
++class pitchdetection_fcomb_test_case(pitchdetection_test_case):
++  def setUp(self, type = aubio_pitch_fcomb):
++    self.create(type=type)
++
++class pitchdetection_mcomb_test_case(pitchdetection_test_case):
++  def setUp(self, type = aubio_pitch_mcomb):
++    self.create(type=type)
++
++class pitchdetection_schmitt_test_case(pitchdetection_test_case):
++  def setUp(self, type = aubio_pitch_schmitt):
++    self.create(type=type)
++"""
++
++if __name__ == '__main__':
++  unittest.main()
index 0000000,f09eaec..bcb4afe
mode 000000,100755..100755
--- /dev/null
@@@ -1,0 -1,17 +1,20 @@@
 -modules_to_test = ['aubiomodule', 'fvec', 'cvec']
+ #! /usr/bin/python
+ # add ${src}/python and ${src}/python/aubio/.libs to python path
+ # so the script is runnable from a compiled source tree.
+ import sys, os
+ cur_dir = os.path.dirname(sys.argv[0])
+ sys.path.append(os.path.join(cur_dir,'..','..','python'))
+ sys.path.append(os.path.join(cur_dir,'..','..','python','aubio','.libs'))
+ import unittest
 -  for module in modules_to_test: exec('from %s import *' % module)
++from glob import glob
++modules_to_test = [i.split('.')[0] for i in glob('*.py')]
+ if __name__ == '__main__':
++  for module in modules_to_test: 
++    if module != 'all_tests': # (not actually needed)
++      exec('from %s import *' % module)
+   unittest.main()