summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJohn Glover <j@johnglover.net>2012-07-03 17:27:12 +0100
committerJohn Glover <j@johnglover.net>2012-07-03 17:27:12 +0100
commit23a5f9888e4c28ff5273b16e984caff32caeac69 (patch)
treedc4111d13217b0e5cbf594a0dd167f5f8da9a703 /tests
parent9d5c3da8942305461d42627d686abdeac7fba30c (diff)
downloadsimpl-23a5f9888e4c28ff5273b16e984caff32caeac69.tar.gz
simpl-23a5f9888e4c28ff5273b16e984caff32caeac69.tar.bz2
simpl-23a5f9888e4c28ff5273b16e984caff32caeac69.zip
[synthesis] Fix SMSSynthesis (was using Peak data instead of tracked Partials). Add test for harmonic synthesis using sum of sines.
Diffstat (limited to 'tests')
-rw-r--r--tests/create_libsms_test_data.py33
-rw-r--r--tests/test_synthesis.py38
2 files changed, 52 insertions, 19 deletions
diff --git a/tests/create_libsms_test_data.py b/tests/create_libsms_test_data.py
index 0fedbc0..553c292 100644
--- a/tests/create_libsms_test_data.py
+++ b/tests/create_libsms_test_data.py
@@ -46,7 +46,7 @@ def _pysms_synthesis_params(sampling_rate):
synth_params.iSynthesisType = pysms.SMS_STYPE_DET
synth_params.iStochasticType = pysms.SMS_STOC_NONE
synth_params.sizeHop = hop_size
- synth_params.nTracks = max_peaks
+ synth_params.nTracks = max_partials
synth_params.deEmphasis = 0
return synth_params
@@ -178,7 +178,7 @@ def _partial_tracking():
return sms_frames
-def _harmonic_synthesis():
+def _harmonic_synthesis(det_synth_type):
pysms.sms_init()
snd_header = pysms.SMS_SndHeader()
@@ -216,20 +216,20 @@ def _harmonic_synthesis():
status = pysms.sms_analyze(frame_audio, analysis_data,
analysis_params)
- if status == 1:
- current_frame += 1
- analysis_frames.append(analysis_data)
- elif status == 0:
- pysms.sms_freeFrame(analysis_data)
+ analysis_frames.append(analysis_data)
+ current_frame += 1
+
if status == -1:
do_analysis = False
- pysms.sms_freeFrame(analysis_data)
-
- # blank_frame = analysis_frames[0]
- # analysis_frames = analysis_frames[1:]
- # pysms.sms_freeFrame(blank_frame)
synth_params = _pysms_synthesis_params(sampling_rate)
+ if det_synth_type == 'ifft':
+ synth_params.iDetSynthType = pysms.SMS_DET_IFFT
+ elif det_synth_type == 'sin':
+ synth_params.iDetSynthType = pysms.SMS_DET_SIN
+ else:
+ raise Exception("Invalid deterministic synthesis type")
+
pysms.sms_initSynth(sms_header, synth_params)
synth_frame = np.zeros(synth_params.sizeHop, dtype=np.float32)
@@ -254,7 +254,8 @@ def _harmonic_synthesis():
if __name__ == '__main__':
size_next_read = _size_next_read()
partial_tracking = _partial_tracking()
- harmonic_synthesis = _harmonic_synthesis()
+ harmonic_synthesis_ifft = _harmonic_synthesis('ifft')
+ harmonic_synthesis_sin = _harmonic_synthesis('sin')
test_data = {'size_next_read': size_next_read,
'peak_detection': partial_tracking,
@@ -264,5 +265,7 @@ if __name__ == '__main__':
with open('libsms_test_data.json', 'w') as f:
f.write(test_data)
- wav.write('libsms_harmonic_synthesis.wav', sampling_rate,
- harmonic_synthesis)
+ wav.write('libsms_harmonic_synthesis_ifft.wav', sampling_rate,
+ harmonic_synthesis_ifft)
+ wav.write('libsms_harmonic_synthesis_sin.wav', sampling_rate,
+ harmonic_synthesis_sin)
diff --git a/tests/test_synthesis.py b/tests/test_synthesis.py
index 8c592a5..9a81c8e 100644
--- a/tests/test_synthesis.py
+++ b/tests/test_synthesis.py
@@ -20,8 +20,11 @@ audio_path = os.path.join(
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'
+libsms_harmonic_synthesis_ifft_path = os.path.join(
+ os.path.dirname(__file__), 'libsms_harmonic_synthesis_ifft.wav'
+)
+libsms_harmonic_synthesis_sin_path = os.path.join(
+ os.path.dirname(__file__), 'libsms_harmonic_synthesis_sin.wav'
)
PeakDetection = peak_detection.PeakDetection
@@ -83,7 +86,7 @@ class TestSMSSynthesis(object):
assert len(synth_audio) == len(self.audio)
- def test_harmonic_synthesis(self):
+ def test_harmonic_synthesis_ifft(self):
pd = SMSPeakDetection()
pd.hop_size = hop_size
frames = pd.find_peaks(self.audio)
@@ -94,13 +97,40 @@ class TestSMSSynthesis(object):
synth = SMSSynthesis()
synth.hop_size = hop_size
+ synth.max_partials = max_partials
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
+ libsms_harmonic_synthesis_ifft_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)
+
+ def test_harmonic_synthesis_sin(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.max_partials = max_partials
+ synth.det_synthesis_type = SMSSynthesis.SMS_DET_SIN
+ synth_audio = synth.synth(frames)
+
+ assert len(synth_audio) == len(self.audio)
+
+ sms_audio, sampling_rate = simpl.read_wav(
+ libsms_harmonic_synthesis_sin_path
)
assert len(synth_audio) == len(sms_audio)