shithub: aubio

Download patch

ref: cc4f3f755c33fffae98865bf2b45da3a1261f928
parent: 0cbfa4a443ef40e57d20352a475afaa658673a09
author: Paul Brossier <piem@piem.org>
date: Sat Nov 3 12:49:38 EDT 2007

phasevoc test: add ones

--- a/tests/python/phasevoc.py
+++ b/tests/python/phasevoc.py
@@ -2,11 +2,12 @@
 
 from aubio.aubiowrapper import *
 
-
 buf_size = 1024
 hop_size = 256
 channels = 2
 
+precision = 6
+
 class aubio_phasevoc_test(unittest.TestCase):
 
   def setUp(self):
@@ -16,15 +17,46 @@
     del_aubio_pvoc(self.o)
 
   def test_create(self):
-    """ test creation and deletion of phasevoc object """
+    """ create and delete phasevoc object """
     pass
 
   def test_zeroes(self):
-    """ test phasevoc object on zeroes """
-    input = new_fvec(hop_size, channels)
+    """ run phasevoc object on zeroes """
+    input    = new_fvec(hop_size, channels)
     fftgrain = new_cvec(buf_size, channels)
-    aubio_pvoc_do (self.o, input, fftgrain)
-    aubio_pvoc_rdo(self.o, fftgrain, input)
-    for index in range(buf_size):
+    output   = new_fvec(hop_size, channels)
+    for index in range(hop_size):
       for channel in range(channels):
         self.assertEqual(0., fvec_read_sample(input, channel, index))
+    aubio_pvoc_do (self.o, input, fftgrain)
+    aubio_pvoc_rdo(self.o, fftgrain, output)
+    for index in range(hop_size):
+      for channel in range(channels):
+        self.assertEqual(0., fvec_read_sample(output, channel, index))
+    del input
+    del fftgrain
+
+  def test_ones(self):
+    """ run phasevoc object on ones """
+    input    = new_fvec(hop_size, channels)
+    fftgrain = new_cvec(buf_size, channels)
+    output   = new_fvec(hop_size, channels)
+    for index in range(hop_size):
+      for channel in range(channels):
+        fvec_write_sample(input, 1., channel, index)
+        self.assertEqual(1., fvec_read_sample(input, channel, index))
+    # make sure the first buf_size-hop_size samples are zeroes
+    for i in range(buf_size/hop_size - 1):
+      aubio_pvoc_do (self.o, input, fftgrain)
+      aubio_pvoc_rdo(self.o, fftgrain, output)
+      for index in range(hop_size):
+        for channel in range(channels):
+          self.assertAlmostEqual(0., fvec_read_sample(output, channel, index), precision)
+    # make sure the first non zero input is correctly resynthesised
+    aubio_pvoc_do (self.o, input, fftgrain)
+    aubio_pvoc_rdo(self.o, fftgrain, output)
+    for index in range(hop_size):
+      for channel in range(channels):
+        self.assertAlmostEqual(1., fvec_read_sample(output, channel, index), precision)
+    del input
+    del fftgrain