diff options
Diffstat (limited to 'tests/test_synthesis.py')
-rw-r--r-- | tests/test_synthesis.py | 89 |
1 files changed, 83 insertions, 6 deletions
diff --git a/tests/test_synthesis.py b/tests/test_synthesis.py index 794b047..8c592a5 100644 --- a/tests/test_synthesis.py +++ b/tests/test_synthesis.py @@ -1,4 +1,5 @@ import os +import json import numpy as np from nose.tools import assert_almost_equals import simpl @@ -6,27 +7,103 @@ import simpl.peak_detection as peak_detection import simpl.partial_tracking as partial_tracking import simpl.synthesis as synthesis -float_precision = 5 +float_precision = 2 frame_size = 512 hop_size = 512 +max_peaks = 10 +max_partials = 10 +num_frames = 30 +num_samples = num_frames * hop_size audio_path = os.path.join( os.path.dirname(__file__), 'audio/flute.wav' ) +libsms_test_data_path = os.path.join( + os.path.dirname(__file__), 'libsms_test_data.json' +) +libsms_harmonic_synthesis_path = os.path.join( + os.path.dirname(__file__), 'libsms_harmonic_synthesis.wav' +) + +PeakDetection = peak_detection.PeakDetection +SMSPeakDetection = peak_detection.SMSPeakDetection +PartialTracking = partial_tracking.PartialTracking +SMSPartialTracking = partial_tracking.SMSPartialTracking +Synthesis = synthesis.Synthesis +SMSSynthesis = synthesis.SMSSynthesis + + +def _load_libsms_test_data(): + test_data = None + with open(libsms_test_data_path, 'r') as f: + test_data = json.loads(f.read()) + return test_data class TestSynthesis(object): @classmethod def setup_class(cls): cls.audio = simpl.read_wav(audio_path)[0] + cls.audio = cls.audio[0:num_samples] + + def test_basic(self): + pd = PeakDetection() + pd.hop_size = hop_size + frames = pd.find_peaks(self.audio) + + pt = PartialTracking() + pt.max_partials = max_partials + frames = pt.find_partials(frames) + + s = Synthesis() + s.hop_size = hop_size + synth_audio = s.synth(frames) + + assert len(synth_audio) == len(self.audio) + + +class TestSMSSynthesis(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_libsms_test_data() - def test_synthesis(self): - pd = peak_detection.PeakDetection() + def test_basic(self): + pd = SMSPeakDetection() + pd.hop_size = hop_size frames = pd.find_peaks(self.audio) - pt = partial_tracking.PartialTracking() + pt = SMSPartialTracking() + pt.max_partials = max_partials frames = pt.find_partials(frames) - s = synthesis.Synthesis() + s = SMSSynthesis() + s.hop_size = hop_size synth_audio = s.synth(frames) - assert len(synth_audio) + assert len(synth_audio) == len(self.audio) + + def test_harmonic_synthesis(self): + pd = SMSPeakDetection() + pd.hop_size = hop_size + frames = pd.find_peaks(self.audio) + + pt = SMSPartialTracking() + pt.max_partials = max_partials + frames = pt.find_partials(frames) + + synth = SMSSynthesis() + synth.hop_size = hop_size + synth.det_synthesis_type = SMSSynthesis.SMS_DET_IFFT + synth_audio = synth.synth(frames) + + assert len(synth_audio) == len(self.audio) + + sms_audio, sampling_rate = simpl.read_wav( + libsms_harmonic_synthesis_path + ) + + assert len(synth_audio) == len(sms_audio) + + for i in range(len(synth_audio)): + assert_almost_equals(synth_audio[i], sms_audio[i], float_precision) |