[913a7f1] | 1 | #! /usr/bin/env python |
---|
| 2 | |
---|
| 3 | from numpy.testing import TestCase |
---|
[5a7e2c3] | 4 | from numpy.testing.utils import assert_equal, assert_almost_equal |
---|
| 5 | from numpy import cos, arange |
---|
| 6 | from math import pi |
---|
| 7 | |
---|
[9c8c8a6] | 8 | from aubio import window, level_lin, db_spl, silence_detection, level_detection |
---|
[5a7e2c3] | 9 | |
---|
| 10 | from aubio import fvec |
---|
[913a7f1] | 11 | |
---|
| 12 | class aubio_window(TestCase): |
---|
| 13 | |
---|
| 14 | def test_accept_name_and_size(self): |
---|
| 15 | window("default", 1024) |
---|
| 16 | |
---|
[5e394ecc] | 17 | def test_fail_name_not_string(self): |
---|
| 18 | try: |
---|
| 19 | window(10, 1024) |
---|
| 20 | except ValueError, e: |
---|
| 21 | pass |
---|
| 22 | else: |
---|
| 23 | self.fail('non-string window type does not raise a ValueError') |
---|
| 24 | |
---|
| 25 | def test_fail_size_not_int(self): |
---|
| 26 | try: |
---|
| 27 | window("default", "default") |
---|
| 28 | except ValueError, e: |
---|
| 29 | pass |
---|
| 30 | else: |
---|
| 31 | self.fail('non-integer window length does not raise a ValueError') |
---|
| 32 | |
---|
[efa62ce] | 33 | def test_compute_hanning_1024(self): |
---|
| 34 | size = 1024 |
---|
| 35 | aubio_window = window("hanning", size) |
---|
| 36 | numpy_window = .5 - .5 * cos(2. * pi * arange(size) / size) |
---|
| 37 | assert_almost_equal(aubio_window, numpy_window) |
---|
| 38 | |
---|
[5a7e2c3] | 39 | class aubio_level_lin(TestCase): |
---|
| 40 | def test_accept_fvec(self): |
---|
| 41 | level_lin(fvec(1024)) |
---|
| 42 | |
---|
| 43 | def test_fail_not_fvec(self): |
---|
| 44 | try: |
---|
| 45 | level_lin("default") |
---|
| 46 | except ValueError, e: |
---|
| 47 | pass |
---|
| 48 | else: |
---|
| 49 | self.fail('non-number input phase does not raise a TypeError') |
---|
| 50 | |
---|
| 51 | def test_zeros_is_zeros(self): |
---|
| 52 | assert_equal(level_lin(fvec(1024)), 0.) |
---|
| 53 | |
---|
| 54 | def test_minus_ones_is_one(self): |
---|
| 55 | from numpy import ones |
---|
| 56 | assert_equal(level_lin(-ones(1024, dtype="float32")), 1.) |
---|
| 57 | |
---|
[4615886a] | 58 | class aubio_db_spl(TestCase): |
---|
| 59 | def test_accept_fvec(self): |
---|
| 60 | db_spl(fvec(1024)) |
---|
| 61 | |
---|
| 62 | def test_fail_not_fvec(self): |
---|
| 63 | try: |
---|
| 64 | db_spl("default") |
---|
| 65 | except ValueError, e: |
---|
| 66 | pass |
---|
| 67 | else: |
---|
| 68 | self.fail('non-number input phase does not raise a TypeError') |
---|
| 69 | |
---|
| 70 | def test_zeros_is_inf(self): |
---|
| 71 | from math import isinf |
---|
| 72 | assert isinf(db_spl(fvec(1024))) |
---|
| 73 | |
---|
| 74 | def test_minus_ones_is_zero(self): |
---|
| 75 | from numpy import ones |
---|
| 76 | assert_equal(db_spl(-ones(1024, dtype="float32")), 0.) |
---|
| 77 | |
---|
[31a09d2] | 78 | class aubio_silence_detection(TestCase): |
---|
| 79 | def test_accept_fvec(self): |
---|
| 80 | silence_detection(fvec(1024), -70.) |
---|
| 81 | |
---|
| 82 | def test_fail_not_fvec(self): |
---|
| 83 | try: |
---|
| 84 | silence_detection("default", -70) |
---|
| 85 | except ValueError, e: |
---|
| 86 | pass |
---|
| 87 | else: |
---|
| 88 | self.fail('non-number input phase does not raise a TypeError') |
---|
| 89 | |
---|
| 90 | def test_zeros_is_one(self): |
---|
| 91 | from math import isinf |
---|
| 92 | assert silence_detection(fvec(1024), -70) == 1 |
---|
| 93 | |
---|
| 94 | def test_minus_ones_is_zero(self): |
---|
| 95 | from numpy import ones |
---|
| 96 | assert silence_detection(ones(1024, dtype="float32"), -70) == 0 |
---|
| 97 | |
---|
[9c8c8a6] | 98 | class aubio_level_detection(TestCase): |
---|
| 99 | def test_accept_fvec(self): |
---|
| 100 | level_detection(fvec(1024), -70.) |
---|
| 101 | |
---|
| 102 | def test_fail_not_fvec(self): |
---|
| 103 | try: |
---|
| 104 | level_detection("default", -70) |
---|
| 105 | except ValueError, e: |
---|
| 106 | pass |
---|
| 107 | else: |
---|
| 108 | self.fail('non-number input phase does not raise a TypeError') |
---|
| 109 | |
---|
| 110 | def test_zeros_is_one(self): |
---|
| 111 | from math import isinf |
---|
| 112 | assert level_detection(fvec(1024), -70) == 1 |
---|
| 113 | |
---|
| 114 | def test_minus_ones_is_zero(self): |
---|
| 115 | from numpy import ones |
---|
| 116 | assert level_detection(ones(1024, dtype="float32"), -70) == 0 |
---|
| 117 | |
---|
[913a7f1] | 118 | if __name__ == '__main__': |
---|
| 119 | from unittest import main |
---|
| 120 | main() |
---|