summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJohn Glover <j@johnglover.net>2012-07-29 20:39:06 +0100
committerJohn Glover <j@johnglover.net>2012-07-29 20:39:06 +0100
commit6780446f3c6ace7cfbeafdf0b9145ee2fc7b590a (patch)
treeb24947176270d31411bf135ca94aefb0e60edaeb /tests
parent4e56550800e95d8a31531045ddab3eb5884da62a (diff)
downloadsimpl-6780446f3c6ace7cfbeafdf0b9145ee2fc7b590a.tar.gz
simpl-6780446f3c6ace7cfbeafdf0b9145ee2fc7b590a.tar.bz2
simpl-6780446f3c6ace7cfbeafdf0b9145ee2fc7b590a.zip
[peak_detection] Make PeakDetection.find_peaks
return 1 frame per hop size (zero pad frames at the end of the signal if necessary).
Diffstat (limited to 'tests')
-rw-r--r--tests/test_peak_detection.py21
-rw-r--r--tests/test_synthesis.py6
2 files changed, 18 insertions, 9 deletions
diff --git a/tests/test_peak_detection.py b/tests/test_peak_detection.py
index 0864a59..b1f9ff4 100644
--- a/tests/test_peak_detection.py
+++ b/tests/test_peak_detection.py
@@ -31,14 +31,14 @@ class TestPeakDetection(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.max_peaks = max_peaks
pd.find_peaks(self.audio)
- assert len(pd.frames) == \
- ((len(self.audio) - pd.frame_size) / hop_size) + 1
+ assert len(pd.frames) == num_frames
assert len(pd.frames[0].peaks) == 0
assert pd.frames[0].max_peaks == max_peaks
@@ -93,16 +93,23 @@ class TestSMSPeakDetection(object):
class TestSndObjPeakDetection(object):
- def test_peak_detection(self):
- audio, sampling_rate = simpl.read_wav(audio_path)
- audio = audio[len(audio) / 2:(len(audio) / 2) + num_samples]
+ @classmethod
+ def setup_class(cls):
+ cls.audio = simpl.read_wav(audio_path)[0]
+ cls.audio = cls.audio[len(cls.audio) / 2:
+ (len(cls.audio) / 2) + num_samples]
+ def test_peak_detection(self):
pd = SndObjPeakDetection()
pd.hop_size = hop_size
pd.max_peaks = max_peaks
- frames = pd.find_peaks(audio)
+ frames = pd.find_peaks(self.audio)
+
+ assert len(frames) == num_frames
- assert len(frames) == ((num_samples - pd.frame_size) / hop_size) + 1
+ # last 4 frames could be empty (with default frame size of 2048
+ # and hop size of 512) so ignore
+ frames = frames[0:len(frames) - 4]
for frame in frames:
assert len(frame.peaks) <= max_peaks, len(frame.peaks)
diff --git a/tests/test_synthesis.py b/tests/test_synthesis.py
index 2e620ea..aed6556 100644
--- a/tests/test_synthesis.py
+++ b/tests/test_synthesis.py
@@ -49,7 +49,8 @@ class TestSynthesis(object):
s.hop_size = hop_size
synth_audio = s.synth(frames)
- assert len(synth_audio) == len(self.audio)
+ assert len(synth_audio) == len(self.audio),\
+ (len(synth_audio), len(self.audio))
class TestSMSSynthesis(object):
@@ -71,7 +72,8 @@ class TestSMSSynthesis(object):
s.hop_size = hop_size
synth_audio = s.synth(frames)
- assert len(synth_audio) == len(self.audio)
+ assert len(synth_audio) == len(self.audio),\
+ (len(synth_audio), len(self.audio))
def test_harmonic_synthesis_ifft(self):
pd = SMSPeakDetection()