diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/signals.py | 50 | ||||
-rw-r--r-- | tests/sms.py (renamed from tests/testsms.py) | 4 | ||||
-rw-r--r-- | tests/sndobj.py (renamed from tests/testsndobj.py) | 58 |
3 files changed, 81 insertions, 31 deletions
diff --git a/tests/signals.py b/tests/signals.py new file mode 100644 index 0000000..1ebf44e --- /dev/null +++ b/tests/signals.py @@ -0,0 +1,50 @@ +# Copyright (c) 2010 John Glover, National University of Ireland, Maynooth +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import simpl +import numpy as np + +def sine_wave(n, f=220, sr=44100): + s = simpl.zeros(n) + for i in range(n): + s[i] = np.sin(2.0 * np.pi * f * i/sr) + return s + +def noisy_sine_wave(n, f=220, sr=44100): + s = simpl.zeros(n) + for i in range(n): + s[i] = np.sin(2*np.pi*f*i/sr) + (np.random.random() / 4) + return s + +def sinechirpsine(): + initial_freq = 220 + final_freq = 440 + amp = 0.5 + section_length = 1 # seconds + sampling_rate = 44100 + + audio = simpl.zeros(section_length*sampling_rate*3) + chirp_freq = initial_freq + chirp_rate = (final_freq - initial_freq) / 2 + + for i in range(section_length*sampling_rate): + t = float(i) / sampling_rate + audio[i] = amp * np.sin(2 * np.pi * initial_freq * t) + audio[i+(section_length*sampling_rate)] = amp * np.sin(2 * np.pi * (initial_freq*t + chirp_rate*t*t)) + audio[i+(section_length*sampling_rate*2)] = amp * np.sin(2 * np.pi * final_freq * t) + + return audio + diff --git a/tests/testsms.py b/tests/sms.py index 7c1c0b3..4c1f4bb 100644 --- a/tests/testsms.py +++ b/tests/sms.py @@ -24,7 +24,7 @@ import numpy as np FLOAT_PRECISION = 3 # number of decimal places to check for accuracy input_file = 'audio/flute.wav' audio_in_data = read(input_file) -audio_in = np.asarray(audio_in_data[1], np.float32) / 32768.0 +audio_in = simpl.asarray(audio_in_data[1]) / 32768.0 sampling_rate = audio_in_data[0] frame_size = 2048 hop_size = 256 @@ -609,4 +609,4 @@ if __name__ == '__main__': suite.addTest(TestSimplSMS('test_interpolate_frames')) suite.addTest(TestSimplSMS('test_harmonic_synthesis')) suite.addTest(TestSimplSMS('test_residual_synthesis')) - unittest.TextTestRunner().run(suite)
\ No newline at end of file + unittest.TextTestRunner().run(suite) diff --git a/tests/testsndobj.py b/tests/sndobj.py index 7ef0a85..527a9d7 100644 --- a/tests/testsndobj.py +++ b/tests/sndobj.py @@ -35,11 +35,11 @@ class TestSimplSndObj(unittest.TestCase): num_samples = frame_size + (num_frames * hop_size) audio_in_data = read(self.input_file) - audio_in = np.asarray(audio_in_data[1], np.float32) / 32768.0 + audio_in = simpl.asarray(audio_in_data[1]) / 32768.0 audio_in = audio_in[0:num_samples] - frame = np.zeros(frame_size, dtype=np.float32) - frame_out = np.zeros(hop_size, dtype=np.float32) - audio_out = np.array([]) + frame = simpl.zeros(frame_size) + frame_out = simpl.zeros(hop_size) + audio_out = simpl.array([]) input = pysndobj.SndObj() input.SetVectorSize(frame_size) @@ -72,9 +72,9 @@ class TestSimplSndObj(unittest.TestCase): num_samples = frame_size + ((num_frames - 1) * hop_size) audio_in_data = read(self.input_file) - audio_in = np.asarray(audio_in_data[1], np.float32) / 32768.0 + audio_in = simpl.asarray(audio_in_data[1]) / 32768.0 audio_in = audio_in[0:num_samples] - frame = np.zeros(frame_size, dtype=np.float32) + frame = simpl.zeros(frame_size) sndobj_input = sndobj.SndObj() simpl_input = pysndobj.SndObj() @@ -106,9 +106,9 @@ class TestSimplSndObj(unittest.TestCase): num_samples = frame_size + ((num_frames - 1) * hop_size) audio_in_data = read(self.input_file) - audio_in = np.asarray(audio_in_data[1], np.float32) / 32768.0 + audio_in = simpl.asarray(audio_in_data[1]) / 32768.0 audio_in = audio_in[0:num_samples] - frame = np.zeros(frame_size, dtype=np.float32) + frame = simpl.zeros(frame_size) sndobj_input = sndobj.SndObj() simpl_input = pysndobj.SndObj() @@ -144,13 +144,13 @@ class TestSimplSndObj(unittest.TestCase): num_samples = frame_size + ((num_frames - 1) * hop_size) audio_in_data = read(self.input_file) - audio_in = np.asarray(audio_in_data[1], np.float32) / 32768.0 + audio_in = simpl.asarray(audio_in_data[1]) / 32768.0 audio_in = audio_in[0:num_samples] - frame = np.zeros(frame_size, dtype=np.float32) - sndobj_frame_out = np.zeros(hop_size, dtype=np.float32) - simpl_frame_out = np.zeros(hop_size, dtype=np.float32) - sndobj_audio_out = np.array([]) - simpl_audio_out = np.array([]) + frame = simpl.zeros(frame_size) + sndobj_frame_out = simpl.zeros(hop_size) + simpl_frame_out = simpl.zeros(hop_size) + sndobj_audio_out = simpl.array([]) + simpl_audio_out = simpl.array([]) sndobj_input = sndobj.SndObj() simpl_input = pysndobj.SndObj() @@ -198,13 +198,13 @@ class TestSimplSndObj(unittest.TestCase): num_samples = frame_size + ((num_frames - 1) * hop_size) audio_in_data = read(self.input_file) - audio_in = np.asarray(audio_in_data[1], np.float32) / 32768.0 + audio_in = simpl.asarray(audio_in_data[1]) / 32768.0 audio_in = audio_in[0:num_samples] - frame = np.zeros(frame_size, dtype=np.float32) - sndobj_frame_out = np.zeros(hop_size, dtype=np.float32) - simpl_frame_out = np.zeros(hop_size, dtype=np.float32) - sndobj_audio_out = np.array([]) - simpl_audio_out = np.array([]) + frame = simpl.zeros(frame_size) + sndobj_frame_out = simpl.zeros(hop_size) + simpl_frame_out = simpl.zeros(hop_size) + sndobj_audio_out = simpl.array([]) + simpl_audio_out = simpl.array([]) sndobj_input = sndobj.SndObj() simpl_input = pysndobj.SndObj() @@ -253,9 +253,9 @@ class TestSimplSndObj(unittest.TestCase): num_samples = frame_size + ((num_frames - 1) * hop_size) audio_in_data = read(self.input_file) - audio_in = np.asarray(audio_in_data[1], np.float32) / 32768.0 + audio_in = simpl.asarray(audio_in_data[1]) / 32768.0 audio_in = audio_in[0:num_samples] - frame = np.zeros(frame_size, dtype=np.float32) + frame = simpl.zeros(frame_size) sndobj_input = sndobj.SndObj() sndobj_input.SetVectorSize(frame_size) @@ -298,9 +298,9 @@ class TestSimplSndObj(unittest.TestCase): num_samples = frame_size + ((num_frames - 1) * hop_size) audio_in_data = read(self.input_file) - audio_in = np.asarray(audio_in_data[1], np.float32) / 32768.0 + audio_in = simpl.asarray(audio_in_data[1]) / 32768.0 audio_in = audio_in[0:num_samples] - frame = np.zeros(frame_size, dtype=np.float32) + frame = simpl.zeros(frame_size) sndobj_input = sndobj.SndObj() sndobj_input.SetVectorSize(frame_size) @@ -347,11 +347,11 @@ class TestSimplSndObj(unittest.TestCase): num_samples = frame_size + ((num_frames - 1) * hop_size) audio_in_data = read(self.input_file) - audio_in = np.asarray(audio_in_data[1], np.float32) / 32768.0 + audio_in = simpl.asarray(audio_in_data[1]) / 32768.0 audio_in = audio_in[0:num_samples] - frame = np.zeros(frame_size, dtype=np.float32) - sndobj_frame_out = np.zeros(hop_size, dtype=np.float32) - sndobj_audio_out = np.array([]) + frame = simpl.zeros(frame_size) + sndobj_frame_out = simpl.zeros(hop_size) + sndobj_audio_out = simpl.array([]) sndobj_input = sndobj.SndObj() sndobj_input.SetVectorSize(frame_size) @@ -386,4 +386,4 @@ class TestSimplSndObj(unittest.TestCase): places = FLOAT_PRECISION) if __name__ == '__main__': - unittest.main()
\ No newline at end of file + unittest.main() |