[e1bfde5] | 1 | #! /usr/bin/env python |
---|
| 2 | |
---|
| 3 | from numpy.testing import TestCase, assert_equal, assert_almost_equal |
---|
| 4 | from aubio import fvec, source, sink |
---|
| 5 | from numpy import array |
---|
| 6 | from utils import list_all_sounds |
---|
| 7 | |
---|
| 8 | list_of_sounds = list_all_sounds('sounds') |
---|
| 9 | path = None |
---|
| 10 | |
---|
| 11 | class aubio_sink_test_case(TestCase): |
---|
| 12 | |
---|
| 13 | def setUp(self): |
---|
| 14 | if not len(list_of_sounds): self.skipTest('add some sound files in \'python/tests/sounds\'') |
---|
| 15 | |
---|
[9e6695d] | 16 | def test_many_sinks(self): |
---|
| 17 | for i in range(100): |
---|
| 18 | g = sink('/tmp/f.wav', 0) |
---|
| 19 | write = 256 |
---|
| 20 | for n in range(200): |
---|
| 21 | vec = fvec(write) |
---|
| 22 | g(vec, write) |
---|
| 23 | del g |
---|
| 24 | |
---|
[e1bfde5] | 25 | def test_read(self): |
---|
| 26 | for path in list_of_sounds: |
---|
| 27 | for samplerate, hop_size in zip([0, 44100, 8000, 32000], [512, 1024, 64, 256]): |
---|
| 28 | f = source(path, samplerate, hop_size) |
---|
| 29 | if samplerate == 0: samplerate = f.samplerate |
---|
| 30 | g = sink('/tmp/f.wav', samplerate) |
---|
| 31 | total_frames = 0 |
---|
| 32 | while True: |
---|
| 33 | vec, read = f() |
---|
[db1eab7] | 34 | g(vec, read) |
---|
[e1bfde5] | 35 | total_frames += read |
---|
| 36 | if read < f.hop_size: break |
---|
| 37 | print "read", "%.2fs" % (total_frames / float(f.samplerate) ), |
---|
| 38 | print "(", total_frames, "frames", "in", |
---|
| 39 | print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")", |
---|
| 40 | print "from", f.uri, |
---|
| 41 | print "to", g.uri |
---|
[9e6695d] | 42 | #del f, g |
---|
[e1bfde5] | 43 | |
---|
[4949182] | 44 | def test_close_file(self): |
---|
| 45 | samplerate = 44100 |
---|
| 46 | g = sink('/tmp/f.wav', samplerate) |
---|
| 47 | g.close() |
---|
| 48 | |
---|
| 49 | def test_close_file_twice(self): |
---|
| 50 | samplerate = 44100 |
---|
| 51 | g = sink('/tmp/f.wav', samplerate) |
---|
| 52 | g.close() |
---|
| 53 | g.close() |
---|
| 54 | |
---|
[e1bfde5] | 55 | if __name__ == '__main__': |
---|
[9e6695d] | 56 | from unittest import main |
---|
| 57 | main() |
---|