Changeset 893e699


Ignore:
Timestamp:
Nov 10, 2018, 11:58:54 AM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
ed09ba7c
Parents:
568fc60 (diff), 9ef3c6e (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 feature/pytest

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_filterbank_mel.py

    r568fc60 r893e699  
    55from _tools import assert_warns
    66
    7 from aubio import cvec, filterbank, float_type
     7from aubio import fvec, cvec, filterbank, float_type
    88
    99class aubio_filterbank_mel_test_case(TestCase):
     
    7979            f.set_triangle_bands(freqs, 44100)
    8080
     81    def test_triangle_freqs_with_zeros(self):
     82        """make sure set_triangle_bands works when list starts with 0"""
     83        freq_list = [0, 40, 80]
     84        freqs = np.array(freq_list, dtype = float_type)
     85        f = filterbank(len(freqs)-2, 1024)
     86        f.set_triangle_bands(freqs, 48000)
     87        assert_equal ( f(cvec(1024)), 0)
     88        self.assertIsInstance(f.get_coeffs(), np.ndarray)
     89
     90    def test_triangle_freqs_with_wrong_negative(self):
     91        """make sure set_triangle_bands fails when list contains a negative"""
     92        freq_list = [-10, 0, 80]
     93        f = filterbank(len(freq_list)-2, 1024)
     94        with self.assertRaises(ValueError):
     95            f.set_triangle_bands(fvec(freq_list), 48000)
     96
     97    def test_triangle_freqs_with_wrong_ordering(self):
     98        """make sure set_triangle_bands fails when list not ordered"""
     99        freq_list = [0, 80, 40]
     100        f = filterbank(len(freq_list)-2, 1024)
     101        with self.assertRaises(ValueError):
     102            f.set_triangle_bands(fvec(freq_list), 48000)
     103
     104    def test_triangle_freqs_with_large_freq(self):
     105        """make sure set_triangle_bands warns when freq > nyquist"""
     106        samplerate = 22050
     107        freq_list = [0, samplerate//4, samplerate // 2 + 1]
     108        f = filterbank(len(freq_list)-2, 1024)
     109        # TODO add assert_warns
     110        f.set_triangle_bands(fvec(freq_list), samplerate)
     111
     112    def test_triangle_freqs_with_not_enough_filters(self):
     113        """make sure set_triangle_bands warns when not enough filters"""
     114        samplerate = 22050
     115        freq_list = [0, 100, 1000, 4000, 8000, 10000]
     116        f = filterbank(len(freq_list)-3, 1024)
     117        # TODO add assert_warns
     118        f.set_triangle_bands(fvec(freq_list), samplerate)
     119
     120    def test_triangle_freqs_with_too_many_filters(self):
     121        """make sure set_triangle_bands warns when too many filters"""
     122        samplerate = 22050
     123        freq_list = [0, 100, 1000, 4000, 8000, 10000]
     124        f = filterbank(len(freq_list)-1, 1024)
     125        # TODO add assert_warns
     126        f.set_triangle_bands(fvec(freq_list), samplerate)
     127
     128    def test_triangle_freqs_with_double_value(self):
     129        """make sure set_triangle_bands works with 2 duplicate freqs"""
     130        samplerate = 22050
     131        freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
     132        f = filterbank(len(freq_list)-2, 1024)
     133        # TODO add assert_warns
     134        f.set_triangle_bands(fvec(freq_list), samplerate)
     135
     136    def test_triangle_freqs_with_triple(self):
     137        """make sure set_triangle_bands works with 3 duplicate freqs"""
     138        samplerate = 22050
     139        freq_list = [0, 100, 1000, 4000, 4000, 4000, 10000]
     140        f = filterbank(len(freq_list)-2, 1024)
     141        # TODO add assert_warns
     142        f.set_triangle_bands(fvec(freq_list), samplerate)
     143
     144
    81145if __name__ == '__main__':
    82146    from unittest import main
  • src/spectral/filterbank_mel.c

    r568fc60 r893e699  
    5555  }
    5656
    57   if (freqs->data[freqs->length - 1] > samplerate / 2) {
    58     AUBIO_WRN ("Nyquist frequency is %fHz, but highest frequency band ends at \
    59 %fHz\n", samplerate / 2, freqs->data[freqs->length - 1]);
     57  for (fn = 0; fn < freqs->length; fn++) {
     58    if (freqs->data[fn] < 0) {
     59      AUBIO_ERR("filterbank_mel: freqs must contain only positive values.\n");
     60      return AUBIO_FAIL;
     61    } else if (freqs->data[fn] > samplerate / 2) {
     62      AUBIO_WRN("filterbank_mel: freqs should contain only "
     63          "values < samplerate / 2.\n");
     64    } else if (fn > 0 && freqs->data[fn] < freqs->data[fn-1]) {
     65      AUBIO_ERR("filterbank_mel: freqs should be a list of frequencies "
     66          "sorted from low to high, but freq[%d] < freq[%d-1]\n", fn, fn);
     67      return AUBIO_FAIL;
     68    } else if (fn > 0 && freqs->data[fn] == freqs->data[fn-1]) {
     69      AUBIO_WRN("filterbank_mel: set_triangle_bands received a list "
     70          "with twice the frequency %f\n", freqs->data[fn]);
     71    }
    6072  }
    6173
     
    92104  /* zeroing of all filters */
    93105  fmat_zeros (filters);
    94 
    95   if (fft_freqs->data[1] >= lower_freqs->data[0]) {
    96     /* - 1 to make sure we don't miss the smallest power of two */
    97     uint_t min_win_s =
    98         (uint_t) FLOOR (samplerate / lower_freqs->data[0]) - 1;
    99     AUBIO_WRN ("Lowest frequency bin (%.2fHz) is higher than lowest frequency \
    100 band (%.2f-%.2fHz). Consider increasing the window size from %d to %d.\n",
    101         fft_freqs->data[1], lower_freqs->data[0],
    102         upper_freqs->data[0], (win_s - 1) * 2,
    103         aubio_next_power_of_two (min_win_s));
    104   }
    105106
    106107  /* building each filter table */
     
    161162  del_fvec (fft_freqs);
    162163
    163   return 0;
     164  return AUBIO_OK;
    164165}
    165166
Note: See TracChangeset for help on using the changeset viewer.