shithub: aubio

Download patch

ref: a0e0f562e6c6b84585c4a2684ce4ce2566fd3b6e
parent: b3f79ca1e452373b919aa9c0fa1e2c66a4ee70a8
author: Paul Brossier <piem@piem.org>
date: Tue Sep 20 21:32:57 EDT 2016

python/tests/test_pitchshift.py: run in a few modes

--- a/python/tests/test_pitchshift.py
+++ b/python/tests/test_pitchshift.py
@@ -1,6 +1,8 @@
 #! /usr/bin/env python
 
 from numpy.testing import TestCase
+from nose2.tools import params
+import numpy as np
 import aubio
 
 class aubio_pitchshift(TestCase):
@@ -7,7 +9,7 @@
 
     def setUp(self):
         try:
-            self.o = aubio.pitchshift()
+            self.o = aubio.pitchshift(hop_size = 128)
         except RuntimeError as e:
             self.skipTest("creating aubio.pitchshift failed (recompile with rubberband?)")
 
@@ -16,10 +18,10 @@
         self.assertEqual(self.o.get_transpose(), 0)
 
     def test_on_zeros(self):
-        test_length = 20000
+        test_length = self.o.hop_size * 100
         read = 0
         # test on zeros
-        vec = aubio.fvec(512)
+        vec = aubio.fvec(self.o.hop_size)
         transpose_range = 24
         while read < test_length:
             # transpose the samples
@@ -33,6 +35,23 @@
             self.o.set_transpose(transpose)
             read += len(vec)
 
+    def test_on_ones(self):
+        test_length = self.o.hop_size * 100
+        read = 0
+        # test on zeros
+        vec = aubio.fvec(self.o.hop_size) + 1
+        transpose_range = 1.24
+        while read < test_length:
+            # transpose the samples
+            out = self.o(vec)
+            # position in the file (between 0. and 1.)
+            percent_read = read / float(test_length)
+            # variable transpose rate (in semitones)
+            transpose = 2 * transpose_range * percent_read - transpose_range
+            # set transpose rate
+            self.o.set_transpose(transpose)
+            read += len(vec)
+
     def test_transpose_too_high(self):
         with self.assertRaises(ValueError):
             self.o.set_transpose(24.3)
@@ -40,6 +59,34 @@
     def test_transpose_too_low(self):
         with self.assertRaises(ValueError):
             self.o.set_transpose(-24.3)
+
+
+class aubio_pitchshift_testruns(TestCase):
+
+    @params(
+            ("default",     1.2,  128,  44100),
+            ("crispness:0", 0.43,  64,   8000),
+            ("crispness:3", 0.53, 256,   8000),
+            ("crispness:3", 1.53, 512,   8000),
+            ("crispness:6", 2.3, 4096, 192000),
+            )
+    def test_run_with_params(self, mode, pitchscale, hop_size, samplerate):
+        self.o = aubio.pitchshift(mode, pitchscale, hop_size, samplerate)
+        test_length = self.o.hop_size * 50
+        read = 0
+        # test on random
+        vec = np.random.rand(self.o.hop_size).astype(aubio.float_type)
+        transpose_range = self.o.get_transpose()
+        while read < test_length:
+            # transpose the samples
+            out = self.o(vec)
+            # position in the file (between 0. and 1.)
+            percent_read = read / float(test_length)
+            # variable transpose rate (in semitones)
+            transpose =  transpose_range - 2 * transpose_range * percent_read
+            # set transpose rate
+            self.o.set_transpose(transpose)
+            read += len(vec)
 
 if __name__ == '__main__':
     from nose2 import main
--