History

Merge branch 'master' into pitchshift

Paul Brossier committed 10 years ago

Commit ad653462 parents 3ffedf2 bd8a92d20 files · +375 −53Browse files

Showing the changes to python (9 of 20 files). Show all

Unified · Split

9 files
  1. python/demos/demo_mfcc.py +25 −8
  2. python/ext/aubiomodule.c +18 −0
  3. python/ext/py-fft.c +2 −5
  4. python/ext/py-phasevoc.c +2 −3
  5. python/ext/py-source.c +2 −2
  6. python/lib/moresetuptools.py +2 −1
  7. python/tests/test_fvec.py +1 −1
  8. python/tests/test_source.py +5 −1
  9. python/tests/test_specdesc.py +1 −3
python/demos/demo_mfcc.py+25−8
@@ -2,20 +2,27 @@ · 1 unmodified line
2 2
3import sys3import sys
4from aubio import source, pvoc, mfcc4from aubio import source, pvoc, mfcc
5from numpy import vstack, zeros5from numpy import vstack, zeros, diff
6 6
7win_s = 512 # fft size
8hop_s = win_s // 4 # hop size
9n_filters = 40 # must be 40 for mfcc7n_filters = 40 # must be 40 for mfcc
10n_coeffs = 138n_coeffs = 13
11samplerate = 44100
12 9
13if len(sys.argv) < 2:10if len(sys.argv) < 2:
14 print("Usage: %s <source_filename>" % sys.argv[0])11 print("Usage: %s <source_filename> [samplerate] [win_s] [hop_s] [mode]" % sys.argv[0])
12 print(" where [mode] can be 'delta' or 'ddelta' for first and second derivatives")
15 sys.exit(1)13 sys.exit(1)
16 14
17source_filename = sys.argv[1]15source_filename = sys.argv[1]
18 16
17if len(sys.argv) > 2: samplerate = int(sys.argv[2])
18else: samplerate = 0
19if len(sys.argv) > 3: win_s = int(sys.argv[3])
20else: win_s = 512
21if len(sys.argv) > 4: hop_s = int(sys.argv[4])
22else: hop_s = win_s // 4
23if len(sys.argv) > 5: mode = sys.argv[5]
24else: mode = "default"
25
19samplerate = 026samplerate = 0
20if len( sys.argv ) > 2: samplerate = int(sys.argv[2])27if len( sys.argv ) > 2: samplerate = int(sys.argv[2])
21 28
@@ -48,18 +55,28 @@ get_waveform_plot( source_filename, samplerate, block_size = hop_s, ax = wave) · 26 unmodified lines
48wave.xaxis.set_visible(False)55wave.xaxis.set_visible(False)
49wave.yaxis.set_visible(False)56wave.yaxis.set_visible(False)
50 57
58# compute first and second derivatives
59if mode in ["delta", "ddelta"]:
60 mfccs = diff(mfccs, axis = 0)
61if mode == "ddelta":
62 mfccs = diff(mfccs, axis = 0)
63
51all_times = arange(mfccs.shape[0]) * hop_s64all_times = arange(mfccs.shape[0]) * hop_s
52n_coeffs = mfccs.shape[1]65n_coeffs = mfccs.shape[1]
53for i in range(n_coeffs):66for i in range(n_coeffs):
54 ax = plt.axes ( [0.1, 0.75 - ((i+1) * 0.65 / n_coeffs), 0.8, 0.65 / n_coeffs], sharex = wave )67 ax = plt.axes ( [0.1, 0.75 - ((i+1) * 0.65 / n_coeffs), 0.8, 0.65 / n_coeffs], sharex = wave )
55 ax.xaxis.set_visible(False)68 ax.xaxis.set_visible(False)
56 ax.yaxis.set_visible(False)69 ax.set_yticks([])
70 ax.set_ylabel('%d' % i)
57 ax.plot(all_times, mfccs.T[i])71 ax.plot(all_times, mfccs.T[i])
58 72
59# add time to the last axis73# add time to the last axis
60set_xlabels_sample2time( ax, frames_read, samplerate) 74set_xlabels_sample2time( ax, frames_read, samplerate)
61 75
62#plt.ylabel('spectral descriptor value')76#plt.ylabel('spectral descriptor value')
63ax.xaxis.set_visible(True)77ax.xaxis.set_visible(True)
64wave.set_title('MFCC for %s' % source_filename)78title = 'MFCC for %s' % source_filename
79if mode == "delta": title = mode + " " + title
80elif mode == "ddelta": title = "double-delta" + " " + title
81wave.set_title(title)
65plt.show()82plt.show()
python/ext/aubiomodule.c+18−0
@@ -256,6 +256,22 @@ static struct PyModuleDef moduledef = { · 255 unmodified lines
256};256};
257#endif257#endif
258 258
259void
260aubio_log_function(int level, const char *message, void *data)
261{
262 // remove trailing \n
263 char *pos;
264 if ((pos=strchr(message, '\n')) != NULL) {
265 *pos = '\0';
266 }
267 // warning or error
268 if (level == AUBIO_LOG_ERR) {
269 PyErr_Format(PyExc_RuntimeError, "%s", message);
270 } else {
271 PyErr_WarnEx(PyExc_UserWarning, message, 1);
272 }
273}
274
259static PyObject *275static PyObject *
260initaubio (void)276initaubio (void)
261{277{
@@ -315,6 +331,8 @@ initaubio (void) · 53 unmodified lines
315 // add ufunc331 // add ufunc
316 add_ufuncs(m);332 add_ufuncs(m);
317 333
334 aubio_log_set_level_function(AUBIO_LOG_ERR, aubio_log_function, NULL);
335 aubio_log_set_level_function(AUBIO_LOG_WRN, aubio_log_function, NULL);
318 return m;336 return m;
319}337}
320 338
python/ext/py-fft.c+2−5
@@ -51,11 +51,8 @@ Py_fft_init (Py_fft * self, PyObject * args, PyObject * kwds) · 50 unmodified lines
51{51{
52 self->o = new_aubio_fft (self->win_s);52 self->o = new_aubio_fft (self->win_s);
53 if (self->o == NULL) {53 if (self->o == NULL) {
54 PyErr_Format(PyExc_RuntimeError,54 // PyErr_Format(PyExc_RuntimeError, ...) was set above by new_ which called
55 "error creating fft with win_s=%d "55 // AUBIO_ERR when failing
56 "(should be a power of 2 greater than 1; "
57 "try recompiling aubio with --enable-fftw3)",
58 self->win_s);
59 return -1;56 return -1;
60 }57 }
61 58
python/ext/py-phasevoc.c+2−3
@@ -66,9 +66,8 @@ Py_pvoc_init (Py_pvoc * self, PyObject * args, PyObject * kwds) · 65 unmodified lines
66{66{
67 self->o = new_aubio_pvoc ( self->win_s, self->hop_s);67 self->o = new_aubio_pvoc ( self->win_s, self->hop_s);
68 if (self->o == NULL) {68 if (self->o == NULL) {
69 PyErr_Format(PyExc_RuntimeError,69 // PyErr_Format(PyExc_RuntimeError, ...) was set above by new_ which called
70 "failed creating pvoc with win_s=%d, hop_s=%d",70 // AUBIO_ERR when failing
71 self->win_s, self->hop_s);
72 return -1;71 return -1;
73 }72 }
74 73
python/ext/py-source.c+2−2
@@ -140,8 +140,8 @@ Py_source_init (Py_source * self, PyObject * args, PyObject * kwds) · 139 unmodified lines
140{140{
141 self->o = new_aubio_source ( self->uri, self->samplerate, self->hop_size );141 self->o = new_aubio_source ( self->uri, self->samplerate, self->hop_size );
142 if (self->o == NULL) {142 if (self->o == NULL) {
143 PyErr_Format (PyExc_RuntimeError, "error creating source with \"%s\"",143 // PyErr_Format(PyExc_RuntimeError, ...) was set above by new_ which called
144 self->uri);144 // AUBIO_ERR when failing
145 return -1;145 return -1;
146 }146 }
147 self->samplerate = aubio_source_get_samplerate ( self->o );147 self->samplerate = aubio_source_get_samplerate ( self->o );
python/lib/moresetuptools.py+2−1
@@ -65,7 +65,8 @@ def add_local_aubio_sources(ext): · 64 unmodified lines
65 for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H',65 for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H',
66 'HAVE_MATH_H', 'HAVE_STRING_H',66 'HAVE_MATH_H', 'HAVE_STRING_H',
67 'HAVE_C99_VARARGS_MACROS',67 'HAVE_C99_VARARGS_MACROS',
68 'HAVE_LIMITS_H', 'HAVE_MEMCPY_HACKS']:68 'HAVE_LIMITS_H', 'HAVE_STDARG_H',
69 'HAVE_MEMCPY_HACKS']:
69 ext.define_macros += [(define_macro, 1)]70 ext.define_macros += [(define_macro, 1)]
70 71
71 # loof for additional packages72 # loof for additional packages
python/tests/test_fvec.py+1−1
@@ -98,7 +98,7 @@ class aubio_alpha_norm(TestCase): · 97 unmodified lines
98 x = np.random.rand(1024).astype(float_type)98 x = np.random.rand(1024).astype(float_type)
99 alpha = np.random.rand() * 5.99 alpha = np.random.rand() * 5.
100 x_alpha_norm = (np.sum(np.abs(x)**alpha)/len(x))**(1/alpha)100 x_alpha_norm = (np.sum(np.abs(x)**alpha)/len(x))**(1/alpha)
101 assert_almost_equal(alpha_norm(x, alpha), x_alpha_norm, decimal = 5)101 assert_almost_equal(alpha_norm(x, alpha), x_alpha_norm, decimal = 4)
102 102
103class aubio_zero_crossing_rate_test(TestCase):103class aubio_zero_crossing_rate_test(TestCase):
104 104
python/tests/test_source.py+5−1
@@ -6,6 +6,9 @@ from numpy.testing import TestCase · 5 unmodified lines
6from aubio import source6from aubio import source
7from utils import list_all_sounds7from utils import list_all_sounds
8 8
9import warnings
10warnings.filterwarnings('ignore', category=UserWarning, append=True)
11
9list_of_sounds = list_all_sounds('sounds')12list_of_sounds = list_all_sounds('sounds')
10samplerates = [0, 44100, 8000, 32000]13samplerates = [0, 44100, 8000, 32000]
11hop_sizes = [512, 1024, 64]14hop_sizes = [512, 1024, 64]
@@ -22,7 +25,8 @@ for soundfile in list_of_sounds: · 10 unmodified lines
22class aubio_source_test_case_base(TestCase):25class aubio_source_test_case_base(TestCase):
23 26
24 def setUp(self):27 def setUp(self):
25 if not len(list_of_sounds): self.skipTest('add some sound files in \'python/tests/sounds\'')28 if not len(list_of_sounds):
29 self.skipTest('add some sound files in \'python/tests/sounds\'')
26 self.default_test_sound = list_of_sounds[0]30 self.default_test_sound = list_of_sounds[0]
27 31
28class aubio_source_test_case(aubio_source_test_case_base):32class aubio_source_test_case(aubio_source_test_case_base):
python/tests/test_specdesc.py+1−3
@@ -225,10 +225,8 @@ class aubio_specdesc_wrong(TestCase): · 224 unmodified lines
225 specdesc("default", -10)225 specdesc("default", -10)
226 226
227 def test_unknown(self):227 def test_unknown(self):
228 # FIXME should fail?228 with self.assertRaises(RuntimeError):
229 with self.assertRaises(ValueError):
230 specdesc("unknown", 512)229 specdesc("unknown", 512)
231 self.skipTest('todo: new_specdesc should fail on wrong method')
232 230
233if __name__ == '__main__':231if __name__ == '__main__':
234 main()232 main()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t