diff options
author | John Glover <j@johnglover.net> | 2012-08-11 20:00:14 +0100 |
---|---|---|
committer | John Glover <j@johnglover.net> | 2012-08-11 20:00:14 +0100 |
commit | 773e21b80a38de52ed59738a152ef34d001e4cee (patch) | |
tree | d816ae7f2a658ac457747df3652fd328ab93334f /tests | |
parent | 1a9b414bc24a894c602d2d5794ebea1ce612c713 (diff) | |
download | simpl-773e21b80a38de52ed59738a152ef34d001e4cee.tar.gz simpl-773e21b80a38de52ed59738a152ef34d001e4cee.tar.bz2 simpl-773e21b80a38de52ed59738a152ef34d001e4cee.zip |
[sndobj] Add C++ implementation of SndObjPartialTracking.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/create_test_data.py | 2 | ||||
-rw-r--r-- | tests/test_partial_tracking.py | 66 |
2 files changed, 67 insertions, 1 deletions
diff --git a/tests/create_test_data.py b/tests/create_test_data.py index 0bb1567..b44a855 100644 --- a/tests/create_test_data.py +++ b/tests/create_test_data.py @@ -333,7 +333,7 @@ def sndobj_partial_tracking(): frames = [] i = 0 - while i < len(audio) - hop_size: + while (i < len(audio) - hop_size) and len(frames) < num_frames: frame = np.asarray(audio[i:i + frame_size], dtype=np.float32) input.PushIn(frame) ifgram.DoProcess() diff --git a/tests/test_partial_tracking.py b/tests/test_partial_tracking.py index cab6b2b..69e2548 100644 --- a/tests/test_partial_tracking.py +++ b/tests/test_partial_tracking.py @@ -7,8 +7,10 @@ import simpl.partial_tracking as partial_tracking PeakDetection = peak_detection.PeakDetection SMSPeakDetection = peak_detection.SMSPeakDetection +SndObjPeakDetection = peak_detection.SndObjPeakDetection PartialTracking = partial_tracking.PartialTracking SMSPartialTracking = partial_tracking.SMSPartialTracking +SndObjPartialTracking = partial_tracking.SndObjPartialTracking float_precision = 2 frame_size = 512 @@ -23,6 +25,9 @@ audio_path = os.path.join( libsms_test_data_path = os.path.join( os.path.dirname(__file__), 'libsms_test_data.json' ) +sndobj_test_data_path = os.path.join( + os.path.dirname(__file__), 'sndobj_test_data.json' +) def _load_libsms_test_data(): @@ -32,6 +37,13 @@ def _load_libsms_test_data(): return test_data +def _load_sndobj_test_data(): + test_data = None + with open(sndobj_test_data_path, 'r') as f: + test_data = json.loads(f.read()) + return test_data + + class TestPartialTracking(object): @classmethod def setup_class(cls): @@ -99,3 +111,57 @@ class TestSMSPartialTracking(object): assert_almost_equals(frames[i].partials[p].phase, sms_frames[i]['partials'][p]['phase'], float_precision) + + +class TestSndObjPartialTracking(object): + @classmethod + def setup_class(cls): + cls.audio = simpl.read_wav(audio_path)[0] + cls.audio = cls.audio[0:num_samples] + cls.test_data = _load_sndobj_test_data() + + def test_basic(self): + pd = SndObjPeakDetection() + pd.hop_size = hop_size + pd.frame_size = hop_size + pd.max_peaks = max_peaks + frames = pd.find_peaks(self.audio) + + pt = SndObjPartialTracking() + pt.max_partials = max_partials + frames = pt.find_partials(frames) + + assert len(frames[0].partials) == max_partials + assert frames[0].max_partials == max_partials + + def test_partial_tracking(self): + pd = SndObjPeakDetection() + pd.max_peaks = max_peaks + pd.frame_size = hop_size + pd.hop_size = hop_size + peaks = pd.find_peaks(self.audio) + pt = SndObjPartialTracking() + pt.max_partials = max_partials + frames = pt.find_partials(peaks) + + sndobj_frames = self.test_data['partial_tracking'] + + assert len(sndobj_frames) == len(frames), \ + (len(sndobj_frames), len(frames)) + + for i in range(len(frames)): + print sndobj_frames[i] + assert len(frames[i].partials) == len(sndobj_frames[i]) + + for p in range(len(frames[i].partials)): + partial = frames[i].partials[p] + sndobj_partial = sndobj_frames[i][p] + assert_almost_equals(partial.amplitude, + sndobj_partial['amplitude'], + float_precision) + assert_almost_equals(partial.frequency, + sndobj_partial['frequency'], + float_precision) + assert_almost_equals(partial.phase, + sndobj_partial['phase'], + float_precision) |