Changeset ad65346


Ignore:
Timestamp:
Sep 23, 2016, 6:57:20 AM (7 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch
Children:
7d01fdf
Parents:
3ffedf22 (diff), bd8a92d (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 'master' into pitchshift

Files:
3 added
17 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_mfcc.py

    r3ffedf22 rad65346  
    33import sys
    44from aubio import source, pvoc, mfcc
    5 from numpy import vstack, zeros
     5from numpy import vstack, zeros, diff
    66
    7 win_s = 512                 # fft size
    8 hop_s = win_s // 4          # hop size
    97n_filters = 40              # must be 40 for mfcc
    108n_coeffs = 13
    11 samplerate = 44100
    129
    1310if 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")
    1513    sys.exit(1)
    1614
    1715source_filename = sys.argv[1]
     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"
    1825
    1926samplerate = 0
     
    4956wave.yaxis.set_visible(False)
    5057
     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
    5164all_times = arange(mfccs.shape[0]) * hop_s
    5265n_coeffs = mfccs.shape[1]
     
    5467    ax = plt.axes ( [0.1, 0.75 - ((i+1) * 0.65 / n_coeffs),  0.8, 0.65 / n_coeffs], sharex = wave )
    5568    ax.xaxis.set_visible(False)
    56     ax.yaxis.set_visible(False)
     69    ax.set_yticks([])
     70    ax.set_ylabel('%d' % i)
    5771    ax.plot(all_times, mfccs.T[i])
    5872
    5973# add time to the last axis
    60 set_xlabels_sample2time( ax, frames_read, samplerate) 
     74set_xlabels_sample2time( ax, frames_read, samplerate)
    6175
    6276#plt.ylabel('spectral descriptor value')
    6377ax.xaxis.set_visible(True)
    64 wave.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)
    6582plt.show()
  • python/ext/aubiomodule.c

    r3ffedf22 rad65346  
    257257#endif
    258258
     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
    259275static PyObject *
    260276initaubio (void)
     
    316332  add_ufuncs(m);
    317333
     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);
    318336  return m;
    319337}
  • python/ext/py-fft.c

    r3ffedf22 rad65346  
    5252  self->o = new_aubio_fft (self->win_s);
    5353  if (self->o == NULL) {
    54     PyErr_Format(PyExc_RuntimeError,
    55         "error creating fft with win_s=%d "
    56         "(should be a power of 2 greater than 1; "
    57         "try recompiling aubio with --enable-fftw3)",
    58         self->win_s);
     54    // PyErr_Format(PyExc_RuntimeError, ...) was set above by new_ which called
     55    // AUBIO_ERR when failing
    5956    return -1;
    6057  }
  • python/ext/py-phasevoc.c

    r3ffedf22 rad65346  
    6767  self->o = new_aubio_pvoc ( self->win_s, self->hop_s);
    6868  if (self->o == NULL) {
    69     PyErr_Format(PyExc_RuntimeError,
    70         "failed creating pvoc with win_s=%d, hop_s=%d",
    71         self->win_s, self->hop_s);
     69    // PyErr_Format(PyExc_RuntimeError, ...) was set above by new_ which called
     70    // AUBIO_ERR when failing
    7271    return -1;
    7372  }
  • python/ext/py-source.c

    r3ffedf22 rad65346  
    141141  self->o = new_aubio_source ( self->uri, self->samplerate, self->hop_size );
    142142  if (self->o == NULL) {
    143     PyErr_Format (PyExc_RuntimeError, "error creating source with \"%s\"",
    144         self->uri);
     143    // PyErr_Format(PyExc_RuntimeError, ...) was set above by new_ which called
     144    // AUBIO_ERR when failing
    145145    return -1;
    146146  }
  • python/lib/moresetuptools.py

    r3ffedf22 rad65346  
    6666                         'HAVE_MATH_H', 'HAVE_STRING_H',
    6767                         'HAVE_C99_VARARGS_MACROS',
    68                          'HAVE_LIMITS_H', 'HAVE_MEMCPY_HACKS']:
     68                         'HAVE_LIMITS_H', 'HAVE_STDARG_H',
     69                         'HAVE_MEMCPY_HACKS']:
    6970        ext.define_macros += [(define_macro, 1)]
    7071
  • python/tests/test_fvec.py

    r3ffedf22 rad65346  
    9999        alpha = np.random.rand() * 5.
    100100        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)
    102102
    103103class aubio_zero_crossing_rate_test(TestCase):
  • python/tests/test_source.py

    r3ffedf22 rad65346  
    66from aubio import source
    77from utils import list_all_sounds
     8
     9import warnings
     10warnings.filterwarnings('ignore', category=UserWarning, append=True)
    811
    912list_of_sounds = list_all_sounds('sounds')
     
    2326
    2427    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\'')
    2630        self.default_test_sound = list_of_sounds[0]
    2731
  • python/tests/test_specdesc.py

    r3ffedf22 rad65346  
    226226
    227227    def test_unknown(self):
    228         # FIXME should fail?
    229         with self.assertRaises(ValueError):
     228        with self.assertRaises(RuntimeError):
    230229            specdesc("unknown", 512)
    231             self.skipTest('todo: new_specdesc should fail on wrong method')
    232230
    233231if __name__ == '__main__':
  • src/aubio.h

    r3ffedf22 rad65346  
    110110
    111111  Several examples of C programs are available in the \p examples/ and \p tests/src
    112   directories of the source tree.
     112  directories of the source tree. See more examples:
     113  @ref spectral/test-fft.c
     114  @ref spectral/test-phasevoc.c
     115  @ref onset/test-onset.c
     116  @ref pitch/test-pitch.c
     117  @ref tempo/test-tempo.c
     118  @ref test-fvec.c
     119  @ref test-cvec.c
    113120
    114121  \subsection unstable_api Unstable API
     
    189196#include "synth/wavetable.h"
    190197#include "utils/parameter.h"
     198#include "utils/log.h"
    191199
    192200#if AUBIO_UNSTABLE
  • src/aubio_priv.h

    r3ffedf22 rad65346  
    6363#ifdef HAVE_LIMITS_H
    6464#include <limits.h> // for CHAR_BIT, in C99 standard
     65#endif
     66
     67#ifdef HAVE_STDARG_H
     68#include <stdarg.h>
    6569#endif
    6670
     
    169173} aubio_status;
    170174
     175/* Logging */
     176
     177#include "utils/log.h"
     178
     179/** internal logging function, defined in utils/log.c */
     180uint_t aubio_log(sint_t level, const char_t *fmt, ...);
     181
    171182#ifdef HAVE_C99_VARARGS_MACROS
    172 #define AUBIO_ERR(...)               fprintf(stderr, "AUBIO ERROR: " __VA_ARGS__)
    173 #define AUBIO_MSG(...)               fprintf(stdout, __VA_ARGS__)
    174 #define AUBIO_DBG(...)               fprintf(stderr, __VA_ARGS__)
    175 #define AUBIO_WRN(...)               fprintf(stderr, "AUBIO WARNING: " __VA_ARGS__)
    176 #else
    177 #define AUBIO_ERR(format, args...)   fprintf(stderr, "AUBIO ERROR: " format , ##args)
    178 #define AUBIO_MSG(format, args...)   fprintf(stdout, format , ##args)
    179 #define AUBIO_DBG(format, args...)   fprintf(stderr, format , ##args)
    180 #define AUBIO_WRN(format, args...)   fprintf(stderr, "AUBIO WARNING: " format, ##args)
     183#define AUBIO_ERR(...)               aubio_log(AUBIO_LOG_ERR, "AUBIO ERROR: " __VA_ARGS__)
     184#define AUBIO_MSG(...)               aubio_log(AUBIO_LOG_MSG, __VA_ARGS__)
     185#define AUBIO_DBG(...)               aubio_log(AUBIO_LOG_DBG, __VA_ARGS__)
     186#define AUBIO_WRN(...)               aubio_log(AUBIO_LOG_WRN, "AUBIO WARNING: " __VA_ARGS__)
     187#else
     188#define AUBIO_ERR(format, args...)   aubio_log(stderr, "AUBIO ERROR: " format , ##args)
     189#define AUBIO_MSG(format, args...)   aubio_log(stdout, format , ##args)
     190#define AUBIO_DBG(format, args...)   aubio_log(stderr, format , ##args)
     191#define AUBIO_WRN(format, args...)   aubio_log(stderr, "AUBIO WARNING: " format, ##args)
    181192#endif
    182193
  • src/io/source_sndfile.c

    r3ffedf22 rad65346  
    6060  uint_t input_hop_size;
    6161#ifdef HAVE_SAMPLERATE
    62   aubio_resampler_t *resampler;
     62  aubio_resampler_t **resamplers;
    6363  fvec_t *input_data;
     64  fmat_t *input_mat;
    6465#endif /* HAVE_SAMPLERATE */
    6566
     
    127128
    128129#ifdef HAVE_SAMPLERATE
    129   s->resampler = NULL;
    130130  s->input_data = NULL;
     131  s->input_mat = NULL;
     132  s->resamplers = NULL;
    131133  if (s->ratio != 1) {
     134    uint_t i;
     135    s->resamplers = AUBIO_ARRAY(aubio_resampler_t*, s->input_channels);
    132136    s->input_data = new_fvec(s->input_hop_size);
    133     s->resampler = new_aubio_resampler(s->ratio, 4);
     137    s->input_mat = new_fmat(s->input_channels, s->input_hop_size);
     138    for (i = 0; i < (uint_t)s->input_channels; i++) {
     139      s->resamplers[i] = new_aubio_resampler(s->ratio, 4);
     140    }
    134141    if (s->ratio > 1) {
    135142      // we would need to add a ring buffer for these
     
    190197
    191198#ifdef HAVE_SAMPLERATE
    192   if (s->resampler) {
    193     aubio_resampler_do(s->resampler, s->input_data, read_data);
     199  if (s->resamplers) {
     200    aubio_resampler_do(s->resamplers[0], s->input_data, read_data);
    194201  }
    195202#endif /* HAVE_SAMPLERATE */
     
    214221#ifdef HAVE_SAMPLERATE
    215222  if (s->ratio != 1) {
    216     AUBIO_ERR("source_sndfile: no multi channel resampling yet\n");
    217     return;
    218     //ptr_data = s->input_data->data;
     223    ptr_data = s->input_mat->data;
    219224  } else
    220225#endif /* HAVE_SAMPLERATE */
     
    252257
    253258#ifdef HAVE_SAMPLERATE
    254   if (s->resampler) {
    255     //aubio_resampler_do(s->resampler, s->input_data, read_data);
     259  if (s->resamplers) {
     260    for (i = 0; i < input_channels; i++) {
     261      fvec_t input_chan, read_chan;
     262      input_chan.data = s->input_mat->data[i];
     263      input_chan.length = s->input_mat->length;
     264      read_chan.data = read_data->data[i];
     265      read_chan.length = read_data->length;
     266      aubio_resampler_do(s->resamplers[i], &input_chan, &read_chan);
     267    }
    256268  }
    257269#endif /* HAVE_SAMPLERATE */
     
    314326  aubio_source_sndfile_close(s);
    315327#ifdef HAVE_SAMPLERATE
    316   if (s->resampler != NULL) {
    317     del_aubio_resampler(s->resampler);
     328  if (s->resamplers != NULL) {
     329    uint_t i = 0, input_channels = s->input_channels;
     330    for (i = 0; i < input_channels; i ++) {
     331      if (s->resamplers[i] != NULL) {
     332        del_aubio_resampler(s->resamplers[i]);
     333      }
     334    }
     335    AUBIO_FREE(s->resamplers);
    318336  }
    319337  if (s->input_data) {
    320338    del_fvec(s->input_data);
     339  }
     340  if (s->input_mat) {
     341    del_fmat(s->input_mat);
    321342  }
    322343#endif /* HAVE_SAMPLERATE */
  • src/notes/notes.c

    r3ffedf22 rad65346  
    8282
    8383  if (strcmp(method, "default") != 0) {
    84     AUBIO_ERR("unknown notes detection method %s, using default.\n",
    85        method);
     84    AUBIO_ERR("notes: unknown notes detection method \"%s\"\n", method);
    8685    goto fail;
    8786  }
  • src/spectral/fft.h

    r3ffedf22 rad65346  
    2828    - [vDSP](https://developer.apple.com/library/mac/#documentation/Accelerate/Reference/vDSPRef/Reference/reference.html)
    2929
    30   \example src/spectral/test-fft.c
     30  \example spectral/test-fft.c
    3131
    3232*/
  • src/spectral/specdesc.c

    r3ffedf22 rad65346  
    274274      onset_type = aubio_onset_default;
    275275  else {
    276       AUBIO_ERR("unknown spectral descriptor type %s, using default.\n", onset_mode);
    277       onset_type = aubio_onset_default;
     276      AUBIO_ERR("unknown spectral descriptor type %s\n", onset_mode);
     277      AUBIO_FREE(o);
     278      return NULL;
    278279  }
    279280  switch(onset_type) {
    280281    /* for both energy and hfc, only fftgrain->norm is required */
    281     case aubio_onset_energy: 
     282    case aubio_onset_energy:
    282283      break;
    283284    case aubio_onset_hfc:
     
    367368void del_aubio_specdesc (aubio_specdesc_t *o){
    368369  switch(o->onset_type) {
    369     case aubio_onset_energy: 
     370    case aubio_onset_energy:
    370371      break;
    371372    case aubio_onset_hfc:
  • tests/src/spectral/test-fft.c

    r3ffedf22 rad65346  
    55  int return_code = 0;
    66  uint_t i, n_iters = 100; // number of iterations
    7   uint_t win_s = 500; // window size
     7  uint_t win_s = 512; // window size
    88  fvec_t * in = new_fvec (win_s); // input buffer
    99  cvec_t * fftgrain = new_cvec (win_s); // fft norm and phase
  • wscript

    r3ffedf22 rad65346  
    114114    ctx.check(header_name='string.h')
    115115    ctx.check(header_name='limits.h')
     116    ctx.check(header_name='stdarg.h')
    116117    ctx.check(header_name='getopt.h', mandatory = False)
    117118    ctx.check(header_name='unistd.h', mandatory = False)
Note: See TracChangeset for help on using the changeset viewer.