Changes in / [a95b386:75f9fff]


Ignore:
Files:
3 deleted
21 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified Makefile

    ra95b386 r75f9fff  
    232232        uninstall_python \
    233233        check_clean_python
    234 
    235 coverage_cycle: coverage_zero_counters coverage_report
    236 
    237 coverage_zero_counters:
    238         lcov --zerocounters --directory .
    239234
    240235coverage: export CFLAGS=--coverage
     
    250245        lcov -a build/coverage_python.info -a build/coverage_lib.info -o build/coverage.info
    251246
    252 # make sure we don't build the doc, which builds a temporary python module
    253 coverage_report: export WAFOPTS += --disable-docs
    254247coverage_report: coverage
    255248        genhtml build/coverage.info --output-directory lcov_html
  • TabularUnified doc/py_utils.rst

    ra95b386 r75f9fff  
    2828
    2929.. autofunction:: miditofreq
    30 
    31 .. python/ext/py-musicutils.h
    32 
    33 .. autofunction:: meltohz
    34 
    35 .. autofunction:: hztomel
    3630
    3731.. python/ext/aubiomodule.c
  • TabularUnified python/ext/aubiomodule.c

    ra95b386 r75f9fff  
    373373  {"shift", Py_aubio_shift, METH_VARARGS, Py_aubio_shift_doc},
    374374  {"ishift", Py_aubio_ishift, METH_VARARGS, Py_aubio_ishift_doc},
    375   {"hztomel", Py_aubio_hztomel, METH_VARARGS|METH_KEYWORDS, Py_aubio_hztomel_doc},
    376   {"meltohz", Py_aubio_meltohz, METH_VARARGS|METH_KEYWORDS, Py_aubio_meltohz_doc},
    377   {"hztomel_htk", Py_aubio_hztomel_htk, METH_VARARGS, Py_aubio_hztomel_htk_doc},
    378   {"meltohz_htk", Py_aubio_meltohz_htk, METH_VARARGS, Py_aubio_meltohz_htk_doc},
    379375  {NULL, NULL, 0, NULL} /* Sentinel */
    380376};
  • TabularUnified python/ext/py-filterbank.c

    ra95b386 r75f9fff  
    139139      &(self->freqs), samplerate);
    140140  if (err > 0) {
    141     if (PyErr_Occurred() == NULL) {
    142       PyErr_SetString (PyExc_ValueError, "error running set_triangle_bands");
    143     } else {
    144       // change the RuntimeError into ValueError
    145       PyObject *type, *value, *traceback;
    146       PyErr_Fetch(&type, &value, &traceback);
    147       PyErr_Restore(PyExc_ValueError, value, traceback);
    148     }
     141    PyErr_SetString (PyExc_ValueError,
     142        "error when running set_triangle_bands");
    149143    return NULL;
    150144  }
     
    157151  uint_t err = 0;
    158152
    159   smpl_t samplerate;
    160   if (!PyArg_ParseTuple (args, AUBIO_NPY_SMPL_CHR, &samplerate)) {
     153  uint_t samplerate;
     154  if (!PyArg_ParseTuple (args, "I", &samplerate)) {
    161155    return NULL;
    162156  }
     
    164158  err = aubio_filterbank_set_mel_coeffs_slaney (self->o, samplerate);
    165159  if (err > 0) {
    166     if (PyErr_Occurred() == NULL) {
    167       PyErr_SetString (PyExc_ValueError, "error running set_mel_coeffs_slaney");
    168     } else {
    169       // change the RuntimeError into ValueError
    170       PyObject *type, *value, *traceback;
    171       PyErr_Fetch(&type, &value, &traceback);
    172       PyErr_Restore(PyExc_ValueError, value, traceback);
    173     }
    174     return NULL;
    175   }
    176   Py_RETURN_NONE;
    177 }
    178 
    179 static PyObject *
    180 Py_filterbank_set_mel_coeffs (Py_filterbank * self, PyObject *args)
    181 {
    182   uint_t err = 0;
    183 
    184   smpl_t samplerate;
    185   smpl_t freq_min;
    186   smpl_t freq_max;
    187   if (!PyArg_ParseTuple (args, AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR
    188         AUBIO_NPY_SMPL_CHR, &samplerate, &freq_min, &freq_max)) {
    189     return NULL;
    190   }
    191 
    192   err = aubio_filterbank_set_mel_coeffs (self->o, samplerate,
    193       freq_min, freq_max);
    194   if (err > 0) {
    195     if (PyErr_Occurred() == NULL) {
    196       PyErr_SetString (PyExc_ValueError, "error running set_mel_coeffs");
    197     } else {
    198       // change the RuntimeError into ValueError
    199       PyObject *type, *value, *traceback;
    200       PyErr_Fetch(&type, &value, &traceback);
    201       PyErr_Restore(PyExc_ValueError, value, traceback);
    202     }
    203     return NULL;
    204   }
    205   Py_RETURN_NONE;
    206 }
    207 
    208 static PyObject *
    209 Py_filterbank_set_mel_coeffs_htk (Py_filterbank * self, PyObject *args)
    210 {
    211   uint_t err = 0;
    212 
    213   smpl_t samplerate;
    214   smpl_t freq_min;
    215   smpl_t freq_max;
    216   if (!PyArg_ParseTuple (args, AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR
    217         AUBIO_NPY_SMPL_CHR, &samplerate, &freq_min, &freq_max)) {
    218     return NULL;
    219   }
    220 
    221   err = aubio_filterbank_set_mel_coeffs_htk (self->o, samplerate,
    222       freq_min, freq_max);
    223   if (err > 0) {
    224     if (PyErr_Occurred() == NULL) {
    225       PyErr_SetString (PyExc_ValueError, "error running set_mel_coeffs_htk");
    226     } else {
    227       // change the RuntimeError into ValueError
    228       PyObject *type, *value, *traceback;
    229       PyErr_Fetch(&type, &value, &traceback);
    230       PyErr_Restore(PyExc_ValueError, value, traceback);
    231     }
     160    PyErr_SetString (PyExc_ValueError,
     161        "error when running set_mel_coeffs_slaney");
    232162    return NULL;
    233163  }
     
    264194  return (PyObject *)PyAubio_CFmatToArray(
    265195      aubio_filterbank_get_coeffs (self->o) );
    266 }
    267 
    268 static PyObject *
    269 Py_filterbank_set_power(Py_filterbank *self, PyObject *args)
    270 {
    271   uint_t power;
    272 
    273   if (!PyArg_ParseTuple (args, "I", &power)) {
    274     return NULL;
    275   }
    276   if(aubio_filterbank_set_power (self->o, power)) {
    277     if (PyErr_Occurred() == NULL) {
    278       PyErr_SetString (PyExc_ValueError,
    279           "error running filterbank.set_power");
    280     } else {
    281       // change the RuntimeError into ValueError
    282       PyObject *type, *value, *traceback;
    283       PyErr_Fetch(&type, &value, &traceback);
    284       PyErr_Restore(PyExc_ValueError, value, traceback);
    285     }
    286     return NULL;
    287   }
    288   Py_RETURN_NONE;
    289 }
    290 
    291 static PyObject *
    292 Py_filterbank_set_norm(Py_filterbank *self, PyObject *args)
    293 {
    294   uint_t playing;
    295 
    296   if (!PyArg_ParseTuple (args, "I", &playing)) {
    297     return NULL;
    298   }
    299   if(aubio_filterbank_set_norm (self->o, playing)) {
    300     if (PyErr_Occurred() == NULL) {
    301       PyErr_SetString (PyExc_ValueError,
    302           "error running filterbank.set_power");
    303     } else {
    304       // change the RuntimeError into ValueError
    305       PyObject *type, *value, *traceback;
    306       PyErr_Fetch(&type, &value, &traceback);
    307       PyErr_Restore(PyExc_ValueError, value, traceback);
    308     }
    309     return NULL;
    310   }
    311   Py_RETURN_NONE;
    312196}
    313197
     
    317201  {"set_mel_coeffs_slaney", (PyCFunction) Py_filterbank_set_mel_coeffs_slaney,
    318202    METH_VARARGS, "set coefficients of filterbank as in Auditory Toolbox"},
    319   {"set_mel_coeffs", (PyCFunction) Py_filterbank_set_mel_coeffs,
    320     METH_VARARGS, "set coefficients of filterbank to linearly spaced mel scale"},
    321   {"set_mel_coeffs_htk", (PyCFunction) Py_filterbank_set_mel_coeffs_htk,
    322     METH_VARARGS, "set coefficients of filterbank to linearly spaced mel scale"},
    323203  {"get_coeffs", (PyCFunction) Py_filterbank_get_coeffs,
    324204    METH_NOARGS, "get coefficients of filterbank"},
    325205  {"set_coeffs", (PyCFunction) Py_filterbank_set_coeffs,
    326206    METH_VARARGS, "set coefficients of filterbank"},
    327   {"set_power", (PyCFunction) Py_filterbank_set_power,
    328     METH_VARARGS, "set power applied to filterbank input spectrum"},
    329   {"set_norm", (PyCFunction) Py_filterbank_set_norm,
    330     METH_VARARGS, "set norm applied to filterbank input spectrum"},
    331207  {NULL}
    332208};
  • TabularUnified python/ext/py-musicutils.c

    ra95b386 r75f9fff  
    182182  return (PyObject *) PyAubio_CFvecToArray(&vec);
    183183}
    184 
    185 PyObject*
    186 Py_aubio_hztomel(PyObject *self, PyObject *args, PyObject *kwds)
    187 {
    188   smpl_t v;
    189   PyObject *htk = NULL;
    190   static char *kwlist[] = {"f", "htk", NULL};
    191   if (!PyArg_ParseTupleAndKeywords(args, kwds, AUBIO_NPY_SMPL_CHR "|O",
    192         kwlist, &v, &htk))
    193   {
    194     return NULL;
    195   }
    196   if (htk != NULL && PyObject_IsTrue(htk) == 1)
    197     return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v));
    198   else
    199     return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel(v));
    200 }
    201 
    202 PyObject*
    203 Py_aubio_meltohz(PyObject *self, PyObject *args, PyObject *kwds)
    204 {
    205   smpl_t v;
    206   PyObject *htk = NULL;
    207   static char *kwlist[] = {"m", "htk", NULL};
    208   if (!PyArg_ParseTupleAndKeywords(args, kwds, AUBIO_NPY_SMPL_CHR "|O",
    209         kwlist, &v, &htk))
    210   {
    211     return NULL;
    212   }
    213   if (htk != NULL && PyObject_IsTrue(htk) == 1)
    214     return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v));
    215   else
    216     return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz(v));
    217 }
    218 
    219 PyObject*
    220 Py_aubio_hztomel_htk(PyObject *self, PyObject *args)
    221 {
    222   smpl_t v;
    223   if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) {
    224     return NULL;
    225   }
    226   return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v));
    227 }
    228 
    229 PyObject*
    230 Py_aubio_meltohz_htk(PyObject *self, PyObject *args)
    231 {
    232   smpl_t v;
    233   if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) {
    234     return NULL;
    235   }
    236   return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v));
    237 }
  • TabularUnified python/ext/py-musicutils.h

    ra95b386 r75f9fff  
    301301PyObject * Py_aubio_ishift(PyObject *self, PyObject *args);
    302302
    303 static char Py_aubio_hztomel_doc[] = ""
    304 "hztomel(f, htk=False)\n"
    305 "\n"
    306 "Convert a scalar from frequency to mel scale.\n"
    307 "\n"
    308 "Parameters\n"
    309 "----------\n"
    310 "m : float\n"
    311 "   input frequency, in Hz\n"
    312 "htk : bool\n"
    313 "   if `True`, use Htk mel scale instead of Slaney.\n"
    314 "\n"
    315 "Returns\n"
    316 "-------\n"
    317 "float\n"
    318 "   output mel\n"
    319 "\n"
    320 "See Also\n"
    321 "--------\n"
    322 "meltohz\n"
    323 "";
    324 PyObject * Py_aubio_hztomel(PyObject *self, PyObject *args);
    325 
    326 static char Py_aubio_meltohz_doc[] = ""
    327 "meltohz(m, htk=False)\n"
    328 "\n"
    329 "Convert a scalar from mel scale to frequency.\n"
    330 "\n"
    331 "Parameters\n"
    332 "----------\n"
    333 "m : float\n"
    334 "   input mel\n"
    335 "htk : bool\n"
    336 "   if `True`, use Htk mel scale instead of Slaney.\n"
    337 "\n"
    338 "Returns\n"
    339 "-------\n"
    340 "float\n"
    341 "   output frequency, in Hz\n"
    342 "\n"
    343 "See Also\n"
    344 "--------\n"
    345 "hztomel\n"
    346 "";
    347 PyObject * Py_aubio_meltohz(PyObject *self, PyObject *args);
    348 
    349 static char Py_aubio_hztomel_htk_doc[] = ""
    350 "hztomel_htk(m)\n"
    351 "\n"
    352 "Same as `hztomel(m, htk=True)`\n"
    353 "\n"
    354 "See Also\n"
    355 "--------\n"
    356 "hztomel\n"
    357 "";
    358 PyObject * Py_aubio_hztomel_htk(PyObject *self, PyObject *args);
    359 
    360 static char Py_aubio_meltohz_htk_doc[] = ""
    361 "meltohz_htk(m)\n"
    362 "\n"
    363 "Same as `meltohz(m, htk=True)`\n"
    364 "\n"
    365 "See Also\n"
    366 "--------\n"
    367 "meltohz\n"
    368 "";
    369 PyObject * Py_aubio_meltohz_htk(PyObject *self, PyObject *args);
    370 
    371303#endif /* PY_AUBIO_MUSICUTILS_H */
  • TabularUnified python/lib/gen_code.py

    ra95b386 r75f9fff  
    463463""".format(**self.__dict__)
    464464        for set_param in self.prototypes['set']:
    465             params = get_params_types_names(set_param)[1:]
    466             param = self.shortname.split('_set_')[-1]
    467             paramdecls = "".join(["""
    468    {0} {1};""".format(p['type'], p['name']) for p in params])
     465            params = get_params_types_names(set_param)[1]
     466            paramtype = params['type']
    469467            method_name = get_name(set_param)
    470468            param = method_name.split('aubio_'+self.shortname+'_set_')[-1]
    471             refs = ", ".join(["&%s" % p['name'] for p in params])
    472             paramlist = ", ".join(["%s" % p['name'] for p in params])
    473             if len(params):
    474                 paramlist = "," + paramlist
    475             pyparamtypes = ''.join([pyargparse_chars[p['type']] for p in params])
     469            pyparamtype = pyargparse_chars[paramtype]
    476470            out += """
    477471static PyObject *
     
    479473{{
    480474  uint_t err = 0;
    481   {paramdecls}
    482 """.format(param = param, paramdecls = paramdecls, **self.__dict__)
    483 
    484             if len(refs) and len(pyparamtypes):
    485                 out += """
    486 
    487   if (!PyArg_ParseTuple (args, "{pyparamtypes}", {refs})) {{
     475  {paramtype} {param};
     476
     477  if (!PyArg_ParseTuple (args, "{pyparamtype}", &{param})) {{
    488478    return NULL;
    489479  }}
    490 """.format(pyparamtypes = pyparamtypes, refs = refs)
    491 
    492             out += """
    493   err = aubio_{shortname}_set_{param} (self->o {paramlist});
     480  err = aubio_{shortname}_set_{param} (self->o, {param});
    494481
    495482  if (err > 0) {{
     
    506493  Py_RETURN_NONE;
    507494}}
    508 """.format(param = param, refs = refs, paramdecls = paramdecls,
    509         pyparamtypes = pyparamtypes, paramlist = paramlist, **self.__dict__)
     495""".format(param = param, paramtype = paramtype, pyparamtype = pyparamtype, **self.__dict__)
    510496        return out
    511497
  • TabularUnified python/tests/test_fft.py

    ra95b386 r75f9fff  
    142142        assert_almost_equal ( r[1:], 0)
    143143
    144 class aubio_fft_odd_sizes(TestCase):
    145 
    146     def test_reconstruct_with_odd_size(self):
    147         win_s = 29
    148         self.recontruct(win_s, 'odd sizes not supported')
    149 
    150     def test_reconstruct_with_radix15(self):
    151         win_s = 2 ** 4 * 15
    152         self.recontruct(win_s, 'radix 15 supported')
    153 
    154     def test_reconstruct_with_radix5(self):
    155         win_s = 2 ** 4 * 5
    156         self.recontruct(win_s, 'radix 5 supported')
    157 
    158     def test_reconstruct_with_radix3(self):
    159         win_s = 2 ** 4 * 3
    160         self.recontruct(win_s, 'radix 3 supported')
    161 
    162     def recontruct(self, win_s, skipMessage):
    163         try:
    164             f = fft(win_s)
    165         except RuntimeError:
    166             self.skipTest(skipMessage)
    167         input_signal = fvec(win_s)
    168         input_signal[win_s//2] = 1
    169         c = f(input_signal)
    170         output_signal = f.rdo(c)
    171         assert_almost_equal(input_signal, output_signal)
    172 
    173 class aubio_fft_wrong_params(TestCase):
    174 
    175144    def test_large_input_timegrain(self):
    176145        win_s = 1024
     
    201170            f.rdo(s)
    202171
     172class aubio_fft_wrong_params(TestCase):
     173
    203174    def test_wrong_buf_size(self):
    204175        win_s = -1
    205176        with self.assertRaises(ValueError):
    206177            fft(win_s)
     178
     179    def test_buf_size_not_power_of_two(self):
     180        # when compiled with fftw3, aubio supports non power of two fft sizes
     181        win_s = 320
     182        try:
     183            with self.assertRaises(RuntimeError):
     184                fft(win_s)
     185        except AssertionError:
     186            self.skipTest('creating aubio.fft with size %d did not fail' % win_s)
    207187
    208188    def test_buf_size_too_small(self):
  • TabularUnified python/tests/test_filterbank_mel.py

    ra95b386 r75f9fff  
    110110
    111111
    112     def test_triangle_freqs_without_norm(self):
    113         """make sure set_triangle_bands works without """
    114         samplerate = 22050
    115         freq_list = fvec([0, 100, 1000, 10000])
    116         f = filterbank(len(freq_list) - 2, 1024)
    117         f.set_norm(0)
    118         f.set_triangle_bands(freq_list, samplerate)
    119         expected = f.get_coeffs()
    120         f.set_norm(1)
    121         f.set_triangle_bands(fvec(freq_list), samplerate)
    122         assert_almost_equal(f.get_coeffs().T,
    123                 expected.T * 2. / (freq_list[2:] - freq_list[:-2]))
    124 
    125     def test_triangle_freqs_wrong_norm(self):
    126         f = filterbank(10, 1024)
    127         with self.assertRaises(ValueError):
    128             f.set_norm(-1)
    129 
    130     def test_triangle_freqs_with_power(self):
    131         f = filterbank(9, 1024)
    132         freqs = fvec([40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000,
    133             24000])
    134         f.set_power(2)
    135         f.set_triangle_bands(freqs, 48000)
    136         spec = cvec(1024)
    137         spec.norm[:] = .1
    138         expected = fvec([0.02070313, 0.02138672, 0.02127604, 0.02135417,
    139             0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345])
    140         expected /= 100.
    141         assert_almost_equal(f(spec), expected)
    142 
    143     def test_mel_coeffs(self):
    144         f = filterbank(40, 1024)
    145         f.set_mel_coeffs(44100, 0, 44100 / 2)
    146 
    147     def test_zero_fmax(self):
    148         f = filterbank(40, 1024)
    149         f.set_mel_coeffs(44100, 0, 0)
    150 
    151     def test_wrong_mel_coeffs(self):
    152         f = filterbank(40, 1024)
    153         with self.assertRaises(ValueError):
    154             f.set_mel_coeffs_slaney(0)
    155         with self.assertRaises(ValueError):
    156             f.set_mel_coeffs(44100, 0, -44100 / 2)
    157         with self.assertRaises(ValueError):
    158             f.set_mel_coeffs(44100, -0.1, 44100 / 2)
    159         with self.assertRaises(ValueError):
    160             f.set_mel_coeffs(-44100, 0.1, 44100 / 2)
    161         with self.assertRaises(ValueError):
    162             f.set_mel_coeffs_htk(-1, 0, 0)
    163 
    164     def test_mel_coeffs_htk(self):
    165         f = filterbank(40, 1024)
    166         f.set_mel_coeffs_htk(44100, 0, 44100 / 2)
    167 
    168 
    169112if __name__ == '__main__':
    170113    from unittest import main
  • TabularUnified src/io/source_avcodec.c

    ra95b386 r75f9fff  
    9090  sint_t selected_stream;
    9191  uint_t eof;
     92  uint_t multi;
    9293};
    9394
    9495// create or re-create the context when _do or _do_multi is called
    95 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s);
     96void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s,
     97    uint_t multi);
    9698// actually read a frame
    9799void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s,
     
    283285  s->avFrame = avFrame;
    284286
    285   aubio_source_avcodec_reset_resampler(s);
     287  // default to mono output
     288  aubio_source_avcodec_reset_resampler(s, 0);
    286289
    287290  if (s->avr == NULL) goto beach;
    288291
    289292  s->eof = 0;
     293  s->multi = 0;
    290294
    291295  //av_log_set_level(AV_LOG_QUIET);
     
    300304}
    301305
    302 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s)
     306void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s,
     307    uint_t multi)
    303308{
    304309  // create or reset resampler to/from mono/multi-channel
    305   if ( s->avr == NULL ) {
     310  if ( (multi != s->multi) || (s->avr == NULL) ) {
    306311    int err;
    307312    int64_t input_layout = av_get_default_channel_layout(s->input_channels);
    308     int64_t output_layout = av_get_default_channel_layout(s->input_channels);
     313    uint_t output_channels = multi ? s->input_channels : 1;
     314    int64_t output_layout = av_get_default_channel_layout(output_channels);
    309315#ifdef HAVE_AVRESAMPLE
    310316    AVAudioResampleContext *avr = avresample_alloc_context();
     317    AVAudioResampleContext *oldavr = s->avr;
    311318#elif defined(HAVE_SWRESAMPLE)
    312319    SwrContext *avr = swr_alloc();
     320    SwrContext *oldavr = s->avr;
    313321#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    314322
     
    338346    }
    339347    s->avr = avr;
     348    if (oldavr != NULL) {
     349#ifdef HAVE_AVRESAMPLE
     350      avresample_close( oldavr );
     351#elif defined(HAVE_SWRESAMPLE)
     352      swr_close ( oldavr );
     353#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
     354      av_free ( oldavr );
     355      oldavr = NULL;
     356    }
     357    s->multi = multi;
    340358  }
    341359}
     
    478496void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data,
    479497    uint_t * read) {
    480   uint_t i, j;
     498  uint_t i;
    481499  uint_t end = 0;
    482500  uint_t total_wrote = 0;
     501  // switch from multi
     502  if (s->multi == 1) aubio_source_avcodec_reset_resampler(s, 0);
    483503  while (total_wrote < s->hop_size) {
    484504    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
    485505    for (i = 0; i < end; i++) {
    486       read_data->data[i + total_wrote] = 0.;
    487       for (j = 0; j < s->input_channels; j++) {
    488         read_data->data[i + total_wrote] +=
    489           s->output[(i + s->read_index) * s->input_channels + j];
    490       }
    491       read_data->data[i + total_wrote] *= 1./s->input_channels;
     506      read_data->data[i + total_wrote] = s->output[i + s->read_index];
    492507    }
    493508    total_wrote += end;
     
    517532  uint_t end = 0;
    518533  uint_t total_wrote = 0;
     534  // switch from mono
     535  if (s->multi == 0) aubio_source_avcodec_reset_resampler(s, 1);
    519536  while (total_wrote < s->hop_size) {
    520537    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
  • TabularUnified src/mathutils.c

    ra95b386 r75f9fff  
    388388}
    389389
    390 void
    391 fvec_mul (fvec_t *o, smpl_t val)
    392 {
    393   uint_t j;
    394   for (j = 0; j < o->length; j++) {
    395     o->data[j] *= val;
    396   }
    397 }
    398 
    399390void fvec_adapt_thres(fvec_t * vec, fvec_t * tmp,
    400391    uint_t post, uint_t pre) {
  • TabularUnified src/mathutils.h

    ra95b386 r75f9fff  
    193193*/
    194194void fvec_add (fvec_t * v, smpl_t c);
    195 
    196 /** multiply each elements of a vector by a scalar
    197 
    198   \param v vector to add constant to
    199   \param s constant to scale v with
    200 
    201 */
    202 void fvec_mul (fvec_t * v, smpl_t s);
    203195
    204196/** remove the minimum value of the vector to each elements
  • TabularUnified src/musicutils.h

    ra95b386 r75f9fff  
    8787smpl_t aubio_freqtobin (smpl_t freq, smpl_t samplerate, smpl_t fftsize);
    8888
    89 /** convert frequency (Hz) to mel
    90 
    91   \param freq input frequency, in Hz
    92 
    93   \return output mel
    94 
    95   Converts a scalar from the frequency domain to the mel scale using Slaney
    96   Auditory Toolbox's implementation:
    97 
    98   If \f$ f < 1000 \f$, \f$ m = 3 f / 200 \f$.
    99 
    100   If \f$ f >= 1000 \f$, \f$ m = 1000 + 27 \frac{{ln}(f) - ln(1000))}
    101   {{ln}(6400) - ln(1000)}
    102   \f$
    103 
    104   See also
    105   --------
    106 
    107   aubio_meltohz(), aubio_hztomel_htk().
    108 
    109 */
    110 smpl_t aubio_hztomel (smpl_t freq);
    111 
    112 /** convert mel to frequency (Hz)
    113 
    114   \param mel input mel
    115 
    116   \return output frequency, in Hz
    117 
    118   Converts a scalar from the mel scale to the frequency domain using Slaney
    119   Auditory Toolbox's implementation:
    120 
    121   If \f$ f < 1000 \f$, \f$ f = 200 m/3 \f$.
    122 
    123   If \f$ f \geq 1000 \f$, \f$ f = 1000 + \left(\frac{6400}{1000}\right)
    124   ^{\frac{m - 1000}{27}} \f$
    125 
    126   See also
    127   --------
    128 
    129   aubio_hztomel(), aubio_meltohz_htk().
    130 
    131   References
    132   ----------
    133 
    134   Malcolm Slaney, *Auditory Toolbox Version 2, Technical Report #1998-010*
    135   https://engineering.purdue.edu/~malcolm/interval/1998-010/
    136 
    137 */
    138 smpl_t aubio_meltohz (smpl_t mel);
    139 
    140 /** convert frequency (Hz) to mel
    141 
    142   \param freq input frequency, in Hz
    143 
    144   \return output mel
    145 
    146   Converts a scalar from the frequency domain to the mel scale, using the
    147   equation defined by O'Shaughnessy, as implemented in the HTK speech
    148   recognition toolkit:
    149 
    150   \f$ m = 1127 + ln(1 + \frac{f}{700}) \f$
    151 
    152   See also
    153   --------
    154 
    155   aubio_meltohz_htk(), aubio_hztomel().
    156 
    157   References
    158   ----------
    159 
    160   Douglas O'Shaughnessy (1987). *Speech communication: human and machine*.
    161   Addison-Wesley. p. 150. ISBN 978-0-201-16520-3.
    162 
    163   HTK Speech Recognition Toolkit: http://htk.eng.cam.ac.uk/
    164 
    165  */
    166 smpl_t aubio_hztomel_htk (smpl_t freq);
    167 
    168 /** convert mel to frequency (Hz)
    169 
    170   \param mel input mel
    171 
    172   \return output frequency, in Hz
    173 
    174   Converts a scalar from the mel scale to the frequency domain, using the
    175   equation defined by O'Shaughnessy, as implemented in the HTK speech
    176   recognition toolkit:
    177 
    178   \f$ f = 700 * {e}^\left(\frac{f}{1127} - 1\right) \f$
    179 
    180   See also
    181   --------
    182 
    183   aubio_hztomel_htk(), aubio_meltohz().
    184 
    185 */
    186 smpl_t aubio_meltohz_htk (smpl_t mel);
    187 
    18889/** convert frequency (Hz) to midi value (0-128) */
    18990smpl_t aubio_freqtomidi (smpl_t freq);
  • TabularUnified src/spectral/fft.c

    ra95b386 r75f9fff  
    9090#define aubio_vDSP_vsadd               vDSP_vsadd
    9191#define aubio_vDSP_vsmul               vDSP_vsmul
     92#define aubio_vDSP_create_fftsetup     vDSP_create_fftsetup
     93#define aubio_vDSP_destroy_fftsetup    vDSP_destroy_fftsetup
    9294#define aubio_DSPComplex               DSPComplex
    9395#define aubio_DSPSplitComplex          DSPSplitComplex
    94 #define aubio_vDSP_DFT_Setup           vDSP_DFT_Setup
    95 #define aubio_vDSP_DFT_zrop_CreateSetup vDSP_DFT_zrop_CreateSetup
    96 #define aubio_vDSP_DFT_Execute         vDSP_DFT_Execute
    97 #define aubio_vDSP_DFT_DestroySetup    vDSP_DFT_DestroySetup
     96#define aubio_FFTSetup                 FFTSetup
    9897#define aubio_vvsqrt                   vvsqrtf
    9998#else
     
    105104#define aubio_vDSP_vsadd               vDSP_vsaddD
    106105#define aubio_vDSP_vsmul               vDSP_vsmulD
     106#define aubio_vDSP_create_fftsetup     vDSP_create_fftsetupD
     107#define aubio_vDSP_destroy_fftsetup    vDSP_destroy_fftsetupD
    107108#define aubio_DSPComplex               DSPDoubleComplex
    108109#define aubio_DSPSplitComplex          DSPDoubleSplitComplex
    109 #define aubio_vDSP_DFT_Setup           vDSP_DFT_SetupD
    110 #define aubio_vDSP_DFT_zrop_CreateSetup vDSP_DFT_zrop_CreateSetupD
    111 #define aubio_vDSP_DFT_Execute         vDSP_DFT_ExecuteD
    112 #define aubio_vDSP_DFT_DestroySetup    vDSP_DFT_DestroySetupD
     110#define aubio_FFTSetup                 FFTSetupD
    113111#define aubio_vvsqrt                   vvsqrt
    114112#endif /* HAVE_AUBIO_DOUBLE */
     
    155153
    156154#elif defined HAVE_ACCELERATE  // using ACCELERATE
    157   aubio_vDSP_DFT_Setup fftSetupFwd;
    158   aubio_vDSP_DFT_Setup fftSetupBwd;
     155  int log2fftsize;
     156  aubio_FFTSetup fftSetup;
    159157  aubio_DSPSplitComplex spec;
    160158  smpl_t *in, *out;
     
    213211
    214212#elif defined HAVE_ACCELERATE  // using ACCELERATE
    215   {
    216     uint_t radix = winsize;
    217     uint_t order = 0;
    218     while ((radix / 2) * 2 == radix) {
    219       radix /= 2;
    220       order++;
    221     }
    222     if (order < 4 || (radix != 1 && radix != 3 && radix != 5 && radix != 15)) {
    223       AUBIO_ERR("fft: vDSP/Accelerate supports FFT with sizes = "
    224           "f * 2 ** n, where n > 4 and f in [1, 3, 5, 15], but requested %d. "
    225           "Use the closest power of two, or try recompiling aubio with "
    226           "--enable-fftw3.\n", winsize);
    227       goto beach;
    228     }
    229   }
    230213  s->winsize = winsize;
    231214  s->fft_size = winsize;
    232215  s->compspec = new_fvec(winsize);
     216  s->log2fftsize = aubio_power_of_two_order(s->fft_size);
    233217  s->in = AUBIO_ARRAY(smpl_t, s->fft_size);
    234218  s->out = AUBIO_ARRAY(smpl_t, s->fft_size);
    235219  s->spec.realp = AUBIO_ARRAY(smpl_t, s->fft_size/2);
    236220  s->spec.imagp = AUBIO_ARRAY(smpl_t, s->fft_size/2);
    237   s->fftSetupFwd = aubio_vDSP_DFT_zrop_CreateSetup(NULL,
    238       s->fft_size, vDSP_DFT_FORWARD);
    239   s->fftSetupBwd = aubio_vDSP_DFT_zrop_CreateSetup(s->fftSetupFwd,
    240       s->fft_size, vDSP_DFT_INVERSE);
     221  s->fftSetup = aubio_vDSP_create_fftsetup(s->log2fftsize, FFT_RADIX2);
    241222
    242223#elif defined HAVE_INTEL_IPP  // using Intel IPP
     
    312293  AUBIO_FREE(s->spec.realp);
    313294  AUBIO_FREE(s->spec.imagp);
    314   aubio_vDSP_DFT_DestroySetup(s->fftSetupBwd);
    315   aubio_vDSP_DFT_DestroySetup(s->fftSetupFwd);
     295  aubio_vDSP_destroy_fftsetup(s->fftSetup);
    316296
    317297#elif defined HAVE_INTEL_IPP  // using Intel IPP
     
    371351  aubio_vDSP_ctoz((aubio_DSPComplex*)s->in, 2, &s->spec, 1, s->fft_size/2);
    372352  // compute the FFT
    373   aubio_vDSP_DFT_Execute(s->fftSetupFwd, s->spec.realp, s->spec.imagp,
    374       s->spec.realp, s->spec.imagp);
     353  aubio_vDSP_fft_zrip(s->fftSetup, &s->spec, 1, s->log2fftsize, FFT_FORWARD);
    375354  // convert from vDSP complex split to [ r0, r1, ..., rN, iN-1, .., i2, i1]
    376355  compspec->data[0] = s->spec.realp[0];
     
    440419  aubio_vDSP_ctoz((aubio_DSPComplex*)s->out, 2, &s->spec, 1, s->fft_size/2);
    441420  // compute the FFT
    442   aubio_vDSP_DFT_Execute(s->fftSetupBwd, s->spec.realp, s->spec.imagp,
    443       s->spec.realp, s->spec.imagp);
     421  aubio_vDSP_fft_zrip(s->fftSetup, &s->spec, 1, s->log2fftsize, FFT_INVERSE);
    444422  // convert result to real output
    445423  aubio_vDSP_ztoc(&s->spec, 1, (aubio_DSPComplex*)output->data, 2, s->fft_size/2);
     
    516494  }
    517495#endif
    518 #ifdef HAVE_FFTW3
    519   // for even length only, make sure last element is 0 or PI
    520   if (2 * (compspec->length / 2) == compspec->length) {
    521 #endif
    522     if (compspec->data[compspec->length/2] < 0) {
    523       spectrum->phas[spectrum->length - 1] = PI;
    524     } else {
    525       spectrum->phas[spectrum->length - 1] = 0.;
    526     }
    527 #ifdef HAVE_FFTW3
     496  if (compspec->data[compspec->length/2] < 0) {
     497    spectrum->phas[spectrum->length - 1] = PI;
    528498  } else {
    529     i = spectrum->length - 1;
    530     spectrum->phas[i] = ATAN2(compspec->data[compspec->length-i],
    531         compspec->data[i]);
    532   }
    533 #endif
     499    spectrum->phas[spectrum->length - 1] = 0.;
     500  }
    534501}
    535502
     
    541508        + SQR(compspec->data[compspec->length - i]) );
    542509  }
    543 #ifdef HAVE_FFTW3
    544   // for even length, make sure last element is > 0
    545   if (2 * (compspec->length / 2) == compspec->length) {
    546 #endif
    547     spectrum->norm[spectrum->length-1] =
    548       ABS(compspec->data[compspec->length/2]);
    549 #ifdef HAVE_FFTW3
    550   } else {
    551     i = spectrum->length - 1;
    552     spectrum->norm[i] = SQRT(SQR(compspec->data[i])
    553         + SQR(compspec->data[compspec->length - i]) );
    554   }
    555 #endif
     510  spectrum->norm[spectrum->length-1] =
     511    ABS(compspec->data[compspec->length/2]);
    556512}
    557513
  • TabularUnified src/spectral/filterbank.c

    ra95b386 r75f9fff  
    2424#include "fmat.h"
    2525#include "cvec.h"
    26 #include "vecutils.h"
    2726#include "spectral/filterbank.h"
    2827#include "mathutils.h"
     
    3433  uint_t n_filters;
    3534  fmat_t *filters;
    36   smpl_t norm;
    37   smpl_t power;
    3835};
    3936
     
    4845  /* allocate filter tables, a matrix of length win_s and of height n_filters */
    4946  fb->filters = new_fmat (n_filters, win_s / 2 + 1);
    50 
    51   fb->norm = 1;
    52 
    53   fb->power = 1;
    5447
    5548  return fb;
     
    7568  tmp.data = in->norm;
    7669
    77   if (f->power != 1.) fvec_pow(&tmp, f->power);
    78 
    7970  fmat_vecmul(f->filters, &tmp, out);
    8071
     
    9485  return 0;
    9586}
    96 
    97 uint_t
    98 aubio_filterbank_set_norm (aubio_filterbank_t *f, smpl_t norm)
    99 {
    100   if (norm != 0 && norm != 1) return AUBIO_FAIL;
    101   f->norm = norm;
    102   return AUBIO_OK;
    103 }
    104 
    105 smpl_t
    106 aubio_filterbank_get_norm (aubio_filterbank_t *f)
    107 {
    108   return f->norm;
    109 }
    110 
    111 uint_t
    112 aubio_filterbank_set_power (aubio_filterbank_t *f, smpl_t power)
    113 {
    114   f->power = power;
    115   return AUBIO_OK;
    116 }
    117 
    118 smpl_t
    119 aubio_filterbank_get_power (aubio_filterbank_t *f)
    120 {
    121   return f->norm;
    122 }
  • TabularUnified src/spectral/filterbank.h

    ra95b386 r75f9fff  
    8484uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, const fmat_t * filters);
    8585
    86 /** set norm parameter
    87 
    88   \param f filterbank object, as returned by new_aubio_filterbank()
    89   \param norm `1` to norm the filters, `0` otherwise.
    90 
    91   If set to `0`, the filters will not be normalized. If set to `1`,
    92   each filter will be normalized to one. Defaults to `1`.
    93 
    94   This function should be called *before* setting the filters with one of
    95   aubio_filterbank_set_triangle_bands(), aubio_filterbank_set_mel_coeffs(),
    96   aubio_filterbank_set_mel_coeffs_htk(), or
    97   aubio_filterbank_set_mel_coeffs_slaney().
    98 
    99  */
    100 uint_t aubio_filterbank_set_norm (aubio_filterbank_t *f, smpl_t norm);
    101 
    102 /** get norm parameter
    103 
    104   \param f filterbank object, as returned by new_aubio_filterbank()
    105   \returns `1` if norm is set, `0` otherwise. Defaults to `1`.
    106 
    107  */
    108 smpl_t aubio_filterbank_get_norm (aubio_filterbank_t *f);
    109 
    110 /** set power parameter
    111 
    112   \param f filterbank object, as returned by new_aubio_filterbank()
    113   \param power Raise norm of the input spectrum norm to this power before
    114   computing filterbank.  Defaults to `1`.
    115 
    116  */
    117 uint_t aubio_filterbank_set_power (aubio_filterbank_t *f, smpl_t power);
    118 
    119 /** get power parameter
    120 
    121   \param f filterbank object, as returned by new_aubio_filterbank()
    122   \return current power parameter. Defaults to `1`.
    123 
    124  */
    125 smpl_t aubio_filterbank_get_power (aubio_filterbank_t *f);
    126 
    12786#ifdef __cplusplus
    12887}
  • TabularUnified src/spectral/filterbank_mel.c

    ra95b386 r75f9fff  
    9191
    9292  /* compute triangle heights so that each triangle has unit area */
    93   if (aubio_filterbank_get_norm(fb)) {
    94     for (fn = 0; fn < n_filters; fn++) {
    95       triangle_heights->data[fn] =
    96           2. / (upper_freqs->data[fn] - lower_freqs->data[fn]);
    97     }
    98   } else {
    99     fvec_ones (triangle_heights);
     93  for (fn = 0; fn < n_filters; fn++) {
     94    triangle_heights->data[fn] =
     95        2. / (upper_freqs->data[fn] - lower_freqs->data[fn]);
    10096  }
    10197
     
    122118
    123119    /* compute positive slope step size */
    124     riseInc = triangle_heights->data[fn]
    125       / (center_freqs->data[fn] - lower_freqs->data[fn]);
     120    riseInc =
     121        triangle_heights->data[fn] /
     122        (center_freqs->data[fn] - lower_freqs->data[fn]);
    126123
    127124    /* compute coefficients in positive slope */
     
    137134
    138135    /* compute negative slope step size */
    139     downInc = triangle_heights->data[fn]
    140       / (upper_freqs->data[fn] - center_freqs->data[fn]);
     136    downInc =
     137        triangle_heights->data[fn] /
     138        (upper_freqs->data[fn] - center_freqs->data[fn]);
    141139
    142140    /* compute coefficents in negative slope */
     
    171169    smpl_t samplerate)
    172170{
     171  uint_t retval;
     172
    173173  /* Malcolm Slaney parameters */
    174   const smpl_t lowestFrequency = 133.3333;
    175   const smpl_t linearSpacing = 66.66666666;
    176   const smpl_t logSpacing = 1.0711703;
    177 
    178   const uint_t linearFilters = 13;
    179   const uint_t logFilters = 27;
    180   const uint_t n_filters = linearFilters + logFilters;
    181 
    182   uint_t fn, retval;
     174  smpl_t lowestFrequency = 133.3333;
     175  smpl_t linearSpacing = 66.66666666;
     176  smpl_t logSpacing = 1.0711703;
     177
     178  uint_t linearFilters = 13;
     179  uint_t logFilters = 27;
     180  uint_t n_filters = linearFilters + logFilters;
     181
     182  uint_t fn;                    /* filter counter */
     183
    183184  smpl_t lastlinearCF;
    184185
    185186  /* buffers to compute filter frequencies */
    186   fvec_t *freqs;
    187 
    188   if (samplerate <= 0) {
    189     AUBIO_ERR("filterbank: set_mel_coeffs_slaney samplerate should be > 0\n");
    190     return AUBIO_FAIL;
    191   }
    192 
    193   freqs = new_fvec (n_filters + 2);
     187  fvec_t *freqs = new_fvec (n_filters + 2);
    194188
    195189  /* first step: fill all the linear filter frequencies */
     
    213207  return retval;
    214208}
    215 
    216 static uint_t aubio_filterbank_check_freqs (aubio_filterbank_t *fb UNUSED,
    217     smpl_t samplerate, smpl_t *freq_min, smpl_t *freq_max)
    218 {
    219   if (samplerate <= 0) {
    220     AUBIO_ERR("filterbank: set_mel_coeffs samplerate should be > 0\n");
    221     return AUBIO_FAIL;
    222   }
    223   if (*freq_max < 0) {
    224     AUBIO_ERR("filterbank: set_mel_coeffs freq_max should be > 0\n");
    225     return AUBIO_FAIL;
    226   } else if (*freq_max == 0) {
    227     *freq_max = samplerate / 2.;
    228   }
    229   if (*freq_min < 0) {
    230     AUBIO_ERR("filterbank: set_mel_coeffs freq_min should be > 0\n");
    231     return AUBIO_FAIL;
    232   }
    233   return AUBIO_OK;
    234 }
    235 
    236 uint_t
    237 aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, smpl_t samplerate,
    238     smpl_t freq_min, smpl_t freq_max)
    239 {
    240   uint_t m, retval;
    241   smpl_t start = freq_min, end = freq_max, step;
    242   fvec_t *freqs;
    243   fmat_t *coeffs = aubio_filterbank_get_coeffs(fb);
    244   uint_t n_bands = coeffs->height;
    245 
    246   if (aubio_filterbank_check_freqs(fb, samplerate, &start, &end)) {
    247     return AUBIO_FAIL;
    248   }
    249 
    250   start = aubio_hztomel(start);
    251   end = aubio_hztomel(end);
    252 
    253   freqs = new_fvec(n_bands + 2);
    254   step = (end - start) / (n_bands + 1);
    255 
    256   for (m = 0; m < n_bands + 2; m++)
    257   {
    258     freqs->data[m] = MIN(aubio_meltohz(start + step * m), samplerate/2.);
    259   }
    260 
    261   retval = aubio_filterbank_set_triangle_bands (fb, freqs, samplerate);
    262 
    263   /* destroy vector used to store frequency limits */
    264   del_fvec (freqs);
    265   return retval;
    266 }
    267 
    268 uint_t
    269 aubio_filterbank_set_mel_coeffs_htk (aubio_filterbank_t * fb, smpl_t samplerate,
    270     smpl_t freq_min, smpl_t freq_max)
    271 {
    272   uint_t m, retval;
    273   smpl_t start = freq_min, end = freq_max, step;
    274   fvec_t *freqs;
    275   fmat_t *coeffs = aubio_filterbank_get_coeffs(fb);
    276   uint_t n_bands = coeffs->height;
    277 
    278   if (aubio_filterbank_check_freqs(fb, samplerate, &start, &end)) {
    279     return AUBIO_FAIL;
    280   }
    281 
    282   start = aubio_hztomel_htk(start);
    283   end = aubio_hztomel_htk(end);
    284 
    285   freqs = new_fvec (n_bands + 2);
    286   step = (end - start) / (n_bands + 1);
    287 
    288   for (m = 0; m < n_bands + 2; m++)
    289   {
    290     freqs->data[m] = MIN(aubio_meltohz_htk(start + step * m), samplerate/2.);
    291   }
    292 
    293   retval = aubio_filterbank_set_triangle_bands (fb, freqs, samplerate);
    294 
    295   /* destroy vector used to store frequency limits */
    296   del_fvec (freqs);
    297   return retval;
    298 }
  • TabularUnified src/spectral/filterbank_mel.h

    ra95b386 r75f9fff  
    5656
    5757  \param fb filterbank object
    58   \param samplerate audio sampling rate, in Hz
     58  \param samplerate audio sampling rate
    5959
    60   The filter coefficients are built to match exactly Malcolm Slaney's Auditory
    61   Toolbox implementation (see file mfcc.m). The number of filters should be 40.
     60  The filter coefficients are built according to Malcolm Slaney's Auditory
     61  Toolbox, available online at the following address (see file mfcc.m):
    6262
    63   References
    64   ----------
    65 
    66   Malcolm Slaney, *Auditory Toolbox Version 2, Technical Report #1998-010*
    6763  https://engineering.purdue.edu/~malcolm/interval/1998-010/
    6864
     
    7167    smpl_t samplerate);
    7268
    73 /** Mel filterbank initialization
    74 
    75   \param fb filterbank object
    76   \param samplerate audio sampling rate
    77   \param fmin start frequency, in Hz
    78   \param fmax end frequency, in Hz
    79 
    80   The filterbank will be initialized with bands linearly spaced in the mel
    81   scale, from `fmin` to `fmax`.
    82 
    83   References
    84   ----------
    85 
    86   Malcolm Slaney, *Auditory Toolbox Version 2, Technical Report #1998-010*
    87   https://engineering.purdue.edu/~malcolm/interval/1998-010/
    88 
    89 */
    90 uint_t aubio_filterbank_set_mel_coeffs(aubio_filterbank_t * fb,
    91     smpl_t samplerate, smpl_t fmin, smpl_t fmax);
    92 
    93 /** Mel filterbank initialization
    94 
    95   \param fb filterbank object
    96   \param samplerate audio sampling rate
    97   \param fmin start frequency, in Hz
    98   \param fmax end frequency, in Hz
    99 
    100   The bank of filters will be initalized to to cover linearly spaced bands in
    101   the Htk mel scale, from `fmin` to `fmax`.
    102 
    103   References
    104   ----------
    105 
    106   Douglas O'Shaughnessy (1987). *Speech communication: human and machine*.
    107   Addison-Wesley. p. 150. ISBN 978-0-201-16520-3.
    108 
    109   HTK Speech Recognition Toolkit: http://htk.eng.cam.ac.uk/
    110 
    111 */
    112 uint_t aubio_filterbank_set_mel_coeffs_htk(aubio_filterbank_t * fb,
    113     smpl_t samplerate, smpl_t fmin, smpl_t fmax);
    114 
    11569#ifdef __cplusplus
    11670}
  • TabularUnified src/spectral/mfcc.c

    ra95b386 r75f9fff  
    5252  fvec_t *output;
    5353#endif
    54   smpl_t scale;
    5554};
    5655
     
    7675  /* filterbank allocation */
    7776  mfcc->fb = new_aubio_filterbank (n_filters, mfcc->win_s);
    78   if (n_filters == 40)
    79     aubio_filterbank_set_mel_coeffs_slaney (mfcc->fb, samplerate);
    80   else
    81     aubio_filterbank_set_mel_coeffs(mfcc->fb, samplerate,
    82         0, samplerate/2.);
     77  aubio_filterbank_set_mel_coeffs_slaney (mfcc->fb, samplerate);
    8378
    8479  /* allocating buffers */
     
    10297  mfcc->output = new_fvec (n_filters);
    10398#endif
    104 
    105   mfcc->scale = 1.;
    10699
    107100  return mfcc;
     
    135128  fvec_t tmp;
    136129#endif
    137 
    138130  /* compute filterbank */
    139131  aubio_filterbank_do (mf->fb, in, mf->in_dct);
     
    142134  fvec_log10 (mf->in_dct);
    143135
    144   if (mf->scale != 1) fvec_mul (mf->in_dct, mf->scale);
     136  /* raise power */
     137  //fvec_pow (mf->in_dct, 3.);
    145138
    146139  /* compute mfccs */
     
    158151  return;
    159152}
    160 
    161 uint_t aubio_mfcc_set_power (aubio_mfcc_t *mf, smpl_t power)
    162 {
    163   return aubio_filterbank_set_power(mf->fb, power);
    164 }
    165 
    166 uint_t aubio_mfcc_get_power (aubio_mfcc_t *mf)
    167 {
    168   return aubio_filterbank_get_power(mf->fb);
    169 }
    170 
    171 uint_t aubio_mfcc_set_scale (aubio_mfcc_t *mf, smpl_t scale)
    172 {
    173   mf->scale = scale;
    174   return AUBIO_OK;
    175 }
    176 
    177 uint_t aubio_mfcc_get_scale (aubio_mfcc_t *mf)
    178 {
    179   return mf->scale;
    180 }
    181 
    182 uint_t aubio_mfcc_set_mel_coeffs (aubio_mfcc_t *mf, smpl_t freq_min,
    183     smpl_t freq_max)
    184 {
    185   return aubio_filterbank_set_mel_coeffs(mf->fb, mf->samplerate,
    186       freq_min, freq_max);
    187 }
    188 
    189 uint_t aubio_mfcc_set_mel_coeffs_htk (aubio_mfcc_t *mf, smpl_t freq_min,
    190     smpl_t freq_max)
    191 {
    192   return aubio_filterbank_set_mel_coeffs_htk(mf->fb, mf->samplerate,
    193       freq_min, freq_max);
    194 }
    195 
    196 uint_t aubio_mfcc_set_mel_coeffs_slaney (aubio_mfcc_t *mf)
    197 {
    198   return aubio_filterbank_set_mel_coeffs_slaney (mf->fb, mf->samplerate);
    199 }
  • TabularUnified src/spectral/mfcc.h

    ra95b386 r75f9fff  
    7474void aubio_mfcc_do (aubio_mfcc_t * mf, const cvec_t * in, fvec_t * out);
    7575
    76 /** set power parameter
    77 
    78   \param mf mfcc object, as returned by new_aubio_mfcc()
    79   \param power Raise norm of the input spectrum norm to this power before
    80   computing filterbank.  Defaults to `1`.
    81 
    82   See aubio_filterbank_set_power().
    83 
    84  */
    85 uint_t aubio_mfcc_set_power (aubio_mfcc_t *mf, smpl_t power);
    86 
    87 /** get power parameter
    88 
    89   \param mf mfcc object, as returned by new_aubio_mfcc()
    90   \return current power parameter. Defaults to `1`.
    91 
    92   See aubio_filterbank_get_power().
    93 
    94  */
    95 uint_t aubio_mfcc_get_power (aubio_mfcc_t *mf);
    96 
    97 /** set scaling parameter
    98 
    99   \param mf mfcc object, as returned by new_aubio_mfcc()
    100   \param scale Scaling value to apply.
    101 
    102   Scales the output of the filterbank after taking its logarithm and before
    103   computing the DCT. Defaults to `1`.
    104 
    105 */
    106 uint_t aubio_mfcc_set_scale (aubio_mfcc_t *mf, smpl_t scale);
    107 
    108 /** get scaling parameter
    109 
    110   \param mf mfcc object, as returned by new_aubio_mfcc()
    111   \return current scaling parameter. Defaults to `1`.
    112 
    113  */
    114 uint_t aubio_mfcc_get_scale (aubio_mfcc_t *mf);
    115 
    116 /** Mel filterbank initialization
    117 
    118   \param mf mfcc object
    119   \param fmin start frequency, in Hz
    120   \param fmax end frequency, in Hz
    121 
    122   The filterbank will be initialized with bands linearly spaced in the mel
    123   scale, from `fmin` to `fmax`.
    124 
    125   See also
    126   --------
    127 
    128   aubio_filterbank_set_mel_coeffs()
    129 
    130 */
    131 uint_t aubio_mfcc_set_mel_coeffs (aubio_mfcc_t *mf,
    132         smpl_t fmin, smpl_t fmax);
    133 
    134 /** Mel filterbank initialization
    135 
    136   \param mf mfcc object
    137   \param fmin start frequency, in Hz
    138   \param fmax end frequency, in Hz
    139 
    140   The bank of filters will be initalized to to cover linearly spaced bands in
    141   the Htk mel scale, from `fmin` to `fmax`.
    142 
    143   See also
    144   --------
    145 
    146   aubio_filterbank_set_mel_coeffs_htk()
    147 
    148 */
    149 uint_t aubio_mfcc_set_mel_coeffs_htk (aubio_mfcc_t *mf,
    150         smpl_t fmin, smpl_t fmax);
    151 
    152 /** Mel filterbank initialization (Auditory Toolbox's parameters)
    153 
    154   \param mf mfcc object
    155   \param samplerate audio sampling rate, in Hz
    156 
    157   The filter coefficients are built to match exactly Malcolm Slaney's Auditory
    158   Toolbox implementation. The number of filters should be 40.
    159 
    160   This is the default filterbank when `mf` was created with `n_filters = 40`.
    161 
    162   See also
    163   --------
    164 
    165   aubio_filterbank_set_mel_coeffs_slaney()
    166 
    167 */
    168 uint_t aubio_mfcc_set_mel_coeffs_slaney (aubio_mfcc_t *mf);
    169 
    17076#ifdef __cplusplus
    17177}
  • TabularUnified tests/src/spectral/test-filterbank.c

    ra95b386 r75f9fff  
    1111  // create filterbank object
    1212  aubio_filterbank_t *o = new_aubio_filterbank (n_filters, win_s);
    13 
    14   smpl_t power = aubio_filterbank_get_power(o);
    15   smpl_t norm = aubio_filterbank_get_norm(o);
    16   if (aubio_filterbank_set_power(o, power)) {
    17     return 1;
    18   }
    19   if (aubio_filterbank_set_norm(o, norm)) {
    20     return 1;
    21   }
    2213
    2314  // apply filterbank ten times
Note: See TracChangeset for help on using the changeset viewer.