ref: 6f277195cce2c6bb6f80206b1714181f51016d61
parent: aee840b6e69427658b1c80540c08da514e92836c
author: Paul Brossier <piem@piem.org>
date: Sat Jan 11 18:28:49 EST 2014
python/lib/aubio/slicing.py: improve slicing, make tests faster
--- a/python/lib/aubio/slicing.py
+++ b/python/lib/aubio/slicing.py
@@ -37,7 +37,7 @@
vec, read = s()
remaining = next_stamp - total_frames
# not enough frames remaining, time to split
- if remaining <= read:
+ if remaining < read:
if remaining != 0:
# write remaining samples from current region
g(vec[0:remaining], remaining)
@@ -47,9 +47,8 @@
new_sink_path = new_sink_name(source_base_name, next_stamp / float(samplerate))
#print "new slice", total_frames, "+", remaining, "=", next_stamp
g = sink(new_sink_path, samplerate)
- if remaining != read:
- # write the remaining samples in the new file
- g(vec[remaining:read], read - remaining)
+ # write the remaining samples in the new file
+ g(vec[remaining:read], read - remaining)
if len(timestamps):
next_stamp = int(timestamps.pop(0))
else:
@@ -59,4 +58,5 @@
total_frames += read
if read < hopsize: break
+ # close the last file
del g
--- a/python/tests/test_slicing.py
+++ b/python/tests/test_slicing.py
@@ -10,6 +10,8 @@
import tempfile
import shutil
+n_slices = 8
+
class aubio_slicing_test_case(TestCase):
def setUp(self):
@@ -17,15 +19,15 @@
self.output_dir = tempfile.mkdtemp(suffix = 'aubio_slicing_test_case')
def test_slice_start_only(self):
- regions_start = [i*1000 for i in range(100)]
+ regions_start = [i*1000 for i in range(n_slices)]
slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir)
def test_slice_start_only_no_zero(self):
- regions_start = [i*1000 for i in range(1, 100)]
+ regions_start = [i*1000 for i in range(1, n_slices)]
slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir)
def test_slice_start_beyond_end(self):
- regions_start = [i*1000 for i in range(1, 100)]
+ regions_start = [i*1000 for i in range(1, n_slices)]
regions_start += [count_samples_in_file(self.source_file)]
regions_start += [count_samples_in_file(self.source_file) + 1000]
slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir)
@@ -33,8 +35,8 @@
def tearDown(self):
original_samples = count_samples_in_file(self.source_file)
written_samples = count_samples_in_directory(self.output_dir)
- assert_equal(original_samples, written_samples,
- "number samples written different from number of original samples")
+ assert_equal(written_samples, original_samples,
+ "number of samples written different from number of original samples")
shutil.rmtree(self.output_dir)
class aubio_slicing_wrong_starts_test_case(TestCase):
@@ -78,8 +80,8 @@
output_dir = self.output_dir)
original_samples = count_samples_in_file(self.source_file)
written_samples = count_samples_in_directory(self.output_dir)
- assert_equal(original_samples, written_samples,
- "number samples written different from number of original samples")
+ assert_equal(written_samples, original_samples,
+ "number of samples written different from number of original samples")
def tearDown(self):
shutil.rmtree(self.output_dir)