source: python/tests/test_sink.py @ ff74460

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since ff74460 was 9e6695d, checked in by Paul Brossier <piem@piem.org>, 12 years ago

python/: use Py_RETURN_NONE, fixing a memory bug triggered after opening many sinks

  • Property mode set to 100755
File size: 1.5 KB
Line 
1#! /usr/bin/env python
2
3from numpy.testing import TestCase, assert_equal, assert_almost_equal
4from aubio import fvec, source, sink
5from numpy import array
6from utils import list_all_sounds
7
8list_of_sounds = list_all_sounds('sounds')
9path = None
10
11class 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
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
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()
34                    g(vec, read)
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
42                #del f, g
43
44if __name__ == '__main__':
45    from unittest import main
46    main()
Note: See TracBrowser for help on using the repository browser.