Пример #1
0
 def test_read_with(self):
     samplerate = 44100
     sink_path = get_tmp_sink_path()
     vec = fvec(128)
     with sink(sink_path, samplerate) as g:
         for _ in range(10):
             g(vec, 128)
Пример #2
0
    def test_read_and_write_multi(self):

        if not len(list_of_sounds):
            self.skipTest('add some sound files in \'python/tests/sounds\'')

        for path in list_of_sounds:
            for samplerate, hop_size in zip([0, 44100, 8000, 32000],
                                            [512, 1024, 64, 256]):
                f = source(path, samplerate, hop_size)
                if samplerate == 0: samplerate = f.samplerate
                sink_path = get_tmp_sink_path()
                g = sink(sink_path, samplerate, channels=f.channels)
                total_frames = 0
                while True:
                    vec, read = f.do_multi()
                    g.do_multi(vec, read)
                    total_frames += read
                    if read < f.hop_size: break
                if 0:
                    print("read",
                          "%.2fs" % (total_frames / float(f.samplerate)),
                          end=' ')
                    print("(", total_frames, "frames", "in", end=' ')
                    print(f.channels, "channels", "in", end=' ')
                    print(total_frames / f.hop_size,
                          "blocks",
                          "at",
                          "%dHz" % f.samplerate,
                          ")",
                          end=' ')
                    print("from", f.uri, end=' ')
                    print("to", g.uri, end=' ')
                    print("in", g.channels, "channels")
                del_tmp_sink_path(sink_path)
Пример #3
0
 def test_read_with(self):
     samplerate = 44100
     sink_path = get_tmp_sink_path()
     vec = fvec(128)
     with sink(sink_path, samplerate) as g:
         for _ in range(10):
             g(vec, 128)
Пример #4
0
 def test_close_file_twice(self):
     samplerate = 44100
     sink_path = get_tmp_sink_path()
     g = sink(sink_path, samplerate)
     g.close()
     g.close()
     del_tmp_sink_path(sink_path)
Пример #5
0
 def test_close_file_twice(self):
     samplerate = 44100
     sink_path = get_tmp_sink_path()
     g = sink(sink_path, samplerate)
     g.close()
     g.close()
     del_tmp_sink_path(sink_path)
Пример #6
0
 def test_read_from_stereo(self):
     out = get_tmp_sink_path()
     samplerate = 44100
     hop_size = 256
     blocks = 10
     channels = 1
     write_samples = np.ones([channels, hop_size], dtype=aubio.float_type)
     write_samples *= .5
     self.check_write_and_read(samplerate, channels, hop_size, blocks,
                               write_samples)
Пример #7
0
 def test_read_and_write_multi(self, hop_size, samplerate, path):
     try:
         f = source(path, samplerate, hop_size)
     except RuntimeError as e:
         self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
     if samplerate == 0: samplerate = f.samplerate
     sink_path = get_tmp_sink_path()
     g = sink(sink_path, samplerate, channels = f.channels)
     total_frames = 0
     while True:
         vec, read = f.do_multi()
         g.do_multi(vec, read)
         total_frames += read
         if read < f.hop_size: break
     del_tmp_sink_path(sink_path)
Пример #8
0
 def test_read_and_write_multi(self, hop_size, samplerate, path):
     try:
         f = source(path, samplerate, hop_size)
     except RuntimeError as e:
         self.skipTest(
             'failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.
             format(hop_size, samplerate, str(e)))
     if samplerate == 0: samplerate = f.samplerate
     sink_path = get_tmp_sink_path()
     g = sink(sink_path, samplerate, channels=f.channels)
     total_frames = 0
     while True:
         vec, read = f.do_multi()
         g.do_multi(vec, read)
         total_frames += read
         if read < f.hop_size: break
     del_tmp_sink_path(sink_path)
Пример #9
0
    def check_write_and_read(self, samplerate, channels, hop_size, blocks,
                             write_samples):
        expected_mono = np.sum(write_samples, axis=0) / write_samples.shape[0]
        out = get_tmp_sink_path()
        snk = aubio.sink(out, samplerate, channels=channels)
        for i in range(blocks):
            snk.do_multi(write_samples, hop_size)
        # close the sink before reading from it
        snk.close()

        src = aubio.source(out, samplerate, hop_size)
        for i in range(blocks):
            read_samples, read = src.do_multi()
            assert_equal(read_samples, write_samples)
            assert_equal(read, hop_size)

        src.seek(0)
        for i in range(blocks):
            read_samples, read = src()
            assert_equal(read, hop_size)
            assert_equal(read_samples, expected_mono)
Пример #10
0
 def test_read_and_write_multi(self, hop_size, samplerate, path):
     orig_samplerate = parse_file_samplerate(soundfile)
     try:
         if orig_samplerate is not None and orig_samplerate < samplerate:
             # upsampling should emit a warning
             with assert_warns(UserWarning):
                 f = source(soundfile, samplerate, hop_size)
         else:
             f = source(soundfile, samplerate, hop_size)
     except RuntimeError as e:
         err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
         skipTest(err_msg.format(str(e), hop_size, samplerate))
     if samplerate == 0: samplerate = f.samplerate
     sink_path = get_tmp_sink_path()
     g = sink(sink_path, samplerate, channels = f.channels)
     total_frames = 0
     while True:
         vec, read = f.do_multi()
         g.do_multi(vec, read)
         total_frames += read
         if read < f.hop_size: break
     del_tmp_sink_path(sink_path)
Пример #11
0
 def test_read_and_write_multi(self, hop_size, samplerate, path):
     orig_samplerate = parse_file_samplerate(soundfile)
     try:
         if orig_samplerate is not None and orig_samplerate < samplerate:
             # upsampling should emit a warning
             with assert_warns(UserWarning):
                 f = source(soundfile, samplerate, hop_size)
         else:
             f = source(soundfile, samplerate, hop_size)
     except RuntimeError as e:
         err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})'
         skipTest(err_msg.format(str(e), hop_size, samplerate))
     if samplerate == 0: samplerate = f.samplerate
     sink_path = get_tmp_sink_path()
     g = sink(sink_path, samplerate, channels=f.channels)
     total_frames = 0
     while True:
         vec, read = f.do_multi()
         g.do_multi(vec, read)
         total_frames += read
         if read < f.hop_size: break
     del_tmp_sink_path(sink_path)
Пример #12
0
 def test_wrong_channels_too_large(self):
     with assert_raises(RuntimeError):
         sink(get_tmp_sink_path(), 44100, 202020)
Пример #13
0
 def test_wrong_channels(self):
     with assert_raises(RuntimeError):
         sink(get_tmp_sink_path(), 44100, -1)
Пример #14
0
 def test_wrong_samplerate_too_large(self):
     with assert_raises(RuntimeError):
         sink(get_tmp_sink_path(), 1536001, 2)
Пример #15
0
 def test_wrong_samplerate_too_large(self):
     with assert_raises(RuntimeError):
         sink(get_tmp_sink_path(), 1536001, 2)
Пример #16
0
 def test_wrong_channels_too_large(self):
     with assert_raises(RuntimeError):
         sink(get_tmp_sink_path(), 44100, 202020)
Пример #17
0
 def test_wrong_channels(self):
     with assert_raises(RuntimeError):
         sink(get_tmp_sink_path(), 44100, -1)
Пример #18
0
 def test_wrong_samplerate(self):
     with assert_raises(RuntimeError):
         sink(get_tmp_sink_path(), -1)
Пример #19
0
 def test_wrong_samplerate(self):
     with assert_raises(RuntimeError):
         sink(get_tmp_sink_path(), -1)