def stop_when_empty_test(self): config.frame_rate = 4 config.block_size = 2 def source_mono(): for i in range(0, 3): yield numpy.ones((1, 1)) * 1 * (i + 1) mixer = stream.mixer(1, stop_when_empty=False) numpy.testing.assert_array_equal(next(mixer), [ [0], [0] ]) mixer.plug(source_mono()) numpy.testing.assert_array_equal(next(mixer), [ [1], [2] ]) numpy.testing.assert_array_equal(next(mixer), [ [3], [0] ]) numpy.testing.assert_array_equal(next(mixer), [ [0], [0] ])
def schedule_plug_test(self): config.frame_rate = 4 config.block_size = 4 def source_stereo(): for i in range(0, 2): yield numpy.ones((2, 2)) * 0.1 * (i + 1) def source_mono(): for i in range(0, 3): yield numpy.ones((3, 1)) * 0.01 * (i + 1) mixer = stream.mixer(2) mixer.plug(source_mono()) mixer.clock.run_after(1.5, mixer.plug, args=[source_stereo()]) numpy.testing.assert_array_equal(next(mixer), [ [0.01, 0], [0.01, 0], [0.01, 0], [0.02, 0] ]) numpy.testing.assert_array_equal(next(mixer), [ [0.02, 0], [0.02, 0] ]) numpy.testing.assert_array_equal(next(mixer), [ [0.1 + 0.03, 0.1], [0.1 + 0.03, 0.1], [0.2 + 0.03, 0.2], [0.2, 0.2] ]) self.assertRaises(StopIteration, next, mixer)
def unplug_test(self): config.frame_rate = 4 config.block_size = 2 def source_stereo(): for i in range(0, 3): yield numpy.ones((1, 2)) * 1 * (i + 1) def source_mono(): for i in range(0, 3): yield numpy.ones((3, 1)) * 0.01 * (i + 1) mixer = stream.mixer(2) src1 = source_mono() src2 = source_stereo() mixer.plug(src2) mixer.plug(src1) numpy.testing.assert_array_equal(next(mixer), [ [1 + 0.01, 1], [2 + 0.01, 2] ]) mixer.unplug(src2) numpy.testing.assert_array_equal(next(mixer), [ [0.01, 0], [0.02, 0] ]) numpy.testing.assert_array_equal(next(mixer), [ [0.02, 0], [0.02, 0] ]) mixer.unplug(src1) self.assertRaises(StopIteration, next, mixer)
def dynamic_plug_test(self): config.frame_rate = 4 config.block_size = 2 def source_stereo1(): for i in range(0, 3): yield numpy.ones((1, 2)) * 1 * (i + 1) def source_stereo2(): for i in range(0, 2): yield numpy.ones((2, 2)) * 0.1 * (i + 1) def source_mono1(): for i in range(0, 3): yield numpy.ones((3, 1)) * 0.01 * (i + 1) mixer = stream.mixer(2) mixer.plug(source_stereo1()) mixer.plug(source_mono1()) numpy.testing.assert_array_equal(next(mixer), [ [1 + 0.01, 1], [2 + 0.01, 2] ]) numpy.testing.assert_array_equal(next(mixer), [ [3 + 0.01, 3], [0.02, 0] ]) numpy.testing.assert_array_equal(next(mixer), [ [0.02, 0], [0.02, 0] ]) mixer.plug(source_stereo2()) numpy.testing.assert_array_equal(next(mixer), [ [0.1 + 0.03, 0.1], [0.1 + 0.03, 0.1] ]) numpy.testing.assert_array_equal(next(mixer), [ [0.2 + 0.03, 0.2], [0.2, 0.2] ]) self.assertRaises(StopIteration, next, mixer)