source: python/tests/test_sink.py @ ca45e58

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since ca45e58 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
RevLine 
[e1bfde5]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
[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
44if __name__ == '__main__':
[9e6695d]45    from unittest import main
46    main()
Note: See TracBrowser for help on using the repository browser.