Changeset 7a02ce9 for python


Ignore:
Timestamp:
Apr 1, 2019, 1:30:22 AM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/timestretch, fix/ffmpeg5, master
Children:
65f7886
Parents:
1301f66 (diff), 439ba7b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'feature/pitchshift' into feature/timestretch

Location:
python
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_wav2midi.py

    r1301f66 r7a02ce9  
    6464        if new_note[2] > 0:
    6565            track.append(Message('note_off', note=int(new_note[2]),
    66                 velocity=127, time=0)
     66                velocity=127, time=delta)
    6767                )
    6868        track.append(Message('note_on',
  • python/ext/py-filter.c

    r1301f66 r7a02ce9  
    110110{
    111111  Py_XDECREF(self->out);
    112   del_aubio_filter (self->o);
     112  if (self->o)
     113    del_aubio_filter (self->o);
    113114  Py_TYPE(self)->tp_free ((PyObject *) self);
    114115}
  • python/ext/py-sink.c

    r1301f66 r7a02ce9  
    151151Py_sink_del (Py_sink *self, PyObject *unused)
    152152{
    153   del_aubio_sink(self->o);
    154   free(self->mwrite_data.data);
     153  if (self->o) {
     154    del_aubio_sink(self->o);
     155    free(self->mwrite_data.data);
     156  }
    155157  if (self->uri) {
    156158    free(self->uri);
  • python/ext/py-source.c

    r1301f66 r7a02ce9  
    437437  aubio_source_do (self->o, &(self->c_read_to), &read);
    438438
     439  if (PyErr_Occurred() != NULL) {
     440    return NULL;
     441  }
     442
    439443  outputs = PyTuple_New(2);
    440444  PyTuple_SetItem( outputs, 0, self->read_to );
     
    457461  /* compute _do function */
    458462  aubio_source_do_multi (self->o, &(self->c_mread_to), &read);
     463
     464  if (PyErr_Occurred() != NULL) {
     465    return NULL;
     466  }
    459467
    460468  outputs = PyTuple_New(2);
     
    574582    } else if (PyLong_AsLong(size) > 0) {
    575583      // short read, return a shorter array
    576       PyArrayObject *shortread = (PyArrayObject*)PyTuple_GetItem(done, 0);
     584      PyObject *vec = PyTuple_GetItem(done, 0);
     585      // take a copy to prevent resizing internal arrays
     586      PyArrayObject *shortread = (PyArrayObject*)PyArray_FROM_OTF(vec,
     587          NPY_NOTYPE, NPY_ARRAY_ENSURECOPY);
    577588      PyArray_Dims newdims;
    578589      PyObject *reshaped;
     
    587598      reshaped = PyArray_Newshape(shortread, &newdims, NPY_CORDER);
    588599      Py_DECREF(shortread);
     600      Py_DECREF(vec);
    589601      return reshaped;
    590602    } else {
  • python/lib/moresetuptools.py

    r1301f66 r7a02ce9  
    6969    for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H',
    7070                         'HAVE_MATH_H', 'HAVE_STRING_H',
    71                          'HAVE_C99_VARARGS_MACROS',
     71                         'HAVE_ERRNO_H', 'HAVE_C99_VARARGS_MACROS',
    7272                         'HAVE_LIMITS_H', 'HAVE_STDARG_H',
    7373                         'HAVE_MEMCPY_HACKS']:
  • python/tests/test_sink.py

    r1301f66 r7a02ce9  
    44from aubio import fvec, source, sink
    55from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
    6 from _tools import parametrize, skipTest, assert_raises
     6from utils import parse_file_samplerate
     7from _tools import parametrize, skipTest, assert_raises, assert_warns
    78
    89list_of_sounds = list_all_sounds('sounds')
     
    6162    @parametrize('hop_size, samplerate, path', all_params)
    6263    def test_read_and_write(self, hop_size, samplerate, path):
     64        orig_samplerate = parse_file_samplerate(soundfile)
    6365        try:
    64             f = source(path, samplerate, hop_size)
     66            if orig_samplerate is not None and orig_samplerate < samplerate:
     67                # upsampling should emit a warning
     68                with assert_warns(UserWarning):
     69                    f = source(soundfile, samplerate, hop_size)
     70            else:
     71                f = source(soundfile, samplerate, hop_size)
    6572        except RuntimeError as e:
    6673            err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
     
    7986    @parametrize('hop_size, samplerate, path', all_params)
    8087    def test_read_and_write_multi(self, hop_size, samplerate, path):
     88        orig_samplerate = parse_file_samplerate(soundfile)
    8189        try:
    82             f = source(path, samplerate, hop_size)
     90            if orig_samplerate is not None and orig_samplerate < samplerate:
     91                # upsampling should emit a warning
     92                with assert_warns(UserWarning):
     93                    f = source(soundfile, samplerate, hop_size)
     94            else:
     95                f = source(soundfile, samplerate, hop_size)
    8396        except RuntimeError as e:
    8497            err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
  • python/tests/test_source.py

    r1301f66 r7a02ce9  
    44from numpy.testing import TestCase, assert_equal
    55from aubio import source
    6 from utils import list_all_sounds
     6from utils import list_all_sounds, parse_file_samplerate
    77import unittest
    8 from _tools import parametrize, assert_raises, assert_equal, skipTest
     8from _tools import assert_raises, assert_equal, assert_warns
     9from _tools import parametrize, skipTest
    910
    1011list_of_sounds = list_all_sounds('sounds')
     
    2425_debug = False
    2526
    26 class Test_aubio_source_test_case(object):
    27 
    28     @parametrize('filename', list_of_sounds)
    29     def test_close_file(self, filename):
     27
     28class Test_aubio_source_test_case(TestCase):
     29
     30    def setUp(self):
     31        if not default_test_sound:
     32            skipTest(no_sounds_msg)
     33
     34    def test_close_file(self):
    3035        samplerate = 0 # use native samplerate
    3136        hop_size = 256
    32         f = source(filename, samplerate, hop_size)
    33         f.close()
    34 
    35     @parametrize('filename', list_of_sounds)
    36     def test_close_file_twice(self, filename):
     37        f = source(default_test_sound, samplerate, hop_size)
     38        f.close()
     39
     40    def test_close_file_twice(self):
    3741        samplerate = 0 # use native samplerate
    3842        hop_size = 256
    39         f = source(filename, samplerate, hop_size)
    40         f.close()
    41         f.close()
     43        f = source(default_test_sound, samplerate, hop_size)
     44        f.close()
     45        f.close()
     46
     47    def test_read_after_close(self):
     48        samplerate = 0 # use native samplerate
     49        hop_size = 256
     50        f = source(default_test_sound, samplerate, hop_size)
     51        read, frames = f()
     52        f.close()
     53        with assert_raises(RuntimeError):
     54            read, frames = f()
     55        with assert_raises(RuntimeError):
     56            read, frames = f.do_multi()
     57
    4258
    4359class Test_aubio_source_read(object):
     
    6177    @parametrize('hop_size, samplerate, soundfile', all_params)
    6278    def test_samplerate_hopsize(self, hop_size, samplerate, soundfile):
     79        orig_samplerate = parse_file_samplerate(soundfile)
    6380        try:
    64             f = source(soundfile, samplerate, hop_size)
     81            if orig_samplerate is not None and orig_samplerate < samplerate:
     82                # upsampling should emit a warning
     83                with assert_warns(UserWarning):
     84                    f = source(soundfile, samplerate, hop_size)
     85            else:
     86                f = source(soundfile, samplerate, hop_size)
    6587        except RuntimeError as e:
    6688            err_msg = 'failed opening with hop_s={:d}, samplerate={:d} ({:s})'
  • python/tests/utils.py

    r1301f66 r7a02ce9  
    22
    33import os
     4import re
    45import glob
    56import numpy as np
     
    7879                    total_files += 1
    7980    return total_files
     81
     82def parse_file_samplerate(soundfile):
     83    samplerate = None
     84    # parse samplerate
     85    re_sr = re.compile(r'/([0-9]{4,})Hz_.*')
     86    match_samplerate = re_sr.findall(soundfile)
     87    if match_samplerate:
     88        samplerate = int(match_samplerate[0])
     89    else:
     90        import warnings
     91        warnings.warn(UserWarning("could not parse samplerate for {:s}"
     92            .format(soundfile)))
     93    return samplerate
Note: See TracChangeset for help on using the changeset viewer.