Skip to content

Commit

Permalink
Merge pull request #142 from CPJKU/fix_issue_141
Browse files Browse the repository at this point in the history
Fix custom filterbanks in FilteredSpectrograms
  • Loading branch information
Sebastian Böck committed Jun 9, 2016
2 parents 6b34ba9 + d2b668c commit 7076096
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ Other changes:
* added classes for onset/note/beat detection with RNNs to `features.*` (#118)
* converted `madmom.modules` into a Python package (#125)


Version 0.13.2 (release date: 2016-06-09)
-----------------------------------------

This is a bugfix release.

* Fix custom filterbank in FilteredSpectrogram (#142)

Version 0.13.1 (release date: 2016-03-14)
-----------------------------------------

Expand Down
8 changes: 4 additions & 4 deletions madmom/audio/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,13 +1058,13 @@ class MelFilterbank(Filterbank):

def __init__(self, bin_frequencies, num_bands=NUM_BANDS, fmin=FMIN,
fmax=FMAX, norm_filters=NORM_FILTERS,
unique_filters=UNIQUE_FILTERS):
unique_filters=UNIQUE_FILTERS, **kwargs):
# this method is for documentation purposes only
pass

def __new__(cls, bin_frequencies, num_bands=NUM_BANDS, fmin=FMIN,
fmax=FMAX, norm_filters=NORM_FILTERS,
unique_filters=UNIQUE_FILTERS):
unique_filters=UNIQUE_FILTERS, **kwargs):
# pylint: disable=arguments-differ
# get a list of frequencies aligned on the Mel scale
# request 2 more bands, because these are the edge frequencies
Expand Down Expand Up @@ -1112,13 +1112,13 @@ class BarkFilterbank(Filterbank):

def __init__(self, bin_frequencies, num_bands=NUM_BANDS, fmin=FMIN,
fmax=FMAX, norm_filters=NORM_FILTERS,
unique_filters=UNIQUE_FILTERS):
unique_filters=UNIQUE_FILTERS, **kwargs):
# this method is for documentation purposes only
pass

def __new__(cls, bin_frequencies, num_bands=NUM_BANDS, fmin=FMIN,
fmax=FMAX, norm_filters=NORM_FILTERS,
unique_filters=UNIQUE_FILTERS):
unique_filters=UNIQUE_FILTERS, **kwargs):
# pylint: disable=arguments-differ
# get a list of frequencies
if num_bands == 'normal':
Expand Down
20 changes: 19 additions & 1 deletion tests/test_audio_spectrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from .test_audio_filters import FFT_FREQS_1024, LOG_FILTERBANK_CENTER_FREQS

from madmom.audio.spectrogram import *
from madmom.audio.filters import Filterbank, LogarithmicFilterbank
from madmom.audio.filters import (Filterbank, LogarithmicFilterbank,
MelFilterbank, BarkFilterbank)
from madmom.audio.stft import ShortTimeFourierTransform


Expand Down Expand Up @@ -224,6 +225,23 @@ def test_values(self):
self.assertTrue(result.num_bins == 81)
self.assertTrue(result.num_frames == 281)

def test_filterbanks(self):
# with Mel filterbank
result = FilteredSpectrogram(AUDIO_PATH + '/sample.wav',
filterbank=MelFilterbank, num_bands=40)
self.assertTrue(np.allclose(result[0, :6],
[8.42887115, 17.98174477, 19.50165367,
6.48194313, 2.96991181, 4.06280804]))
self.assertTrue(result.shape == (281, 40))
# with Bark filterbank
result = FilteredSpectrogram(AUDIO_PATH + '/sample.wav',
filterbank=BarkFilterbank,
num_bands='normal')
self.assertTrue(np.allclose(result[0, :6],
[16.42251968, 17.36715126, 2.81979132,
4.27050114, 3.08699131, 1.50553513]))
self.assertTrue(result.shape == (281, 23))

def test_methods(self):
result = FilteredSpectrogram(AUDIO_PATH + '/sample.wav')
self.assertIsInstance(result.diff(), SpectrogramDifference)
Expand Down

0 comments on commit 7076096

Please sign in to comment.