def test_Graph(): from gum.lib.mock import Mock, Fake import numpy sound = Mock({"numchan": 1}) sound.changed = Fake() sound.frames = numpy.array(list(range(1000)), DTYPE) c = Graph(sound) c.set_width(200) o = c.channels() class Foo: def foo(self): print("Changed.") f = Foo() c = Graph(sound) c.changed.connect(f.foo) c.set_width(200) o = c.channels() # stereo import numpy sound = Mock({"numchan": 2}) sound.changed = Fake() data = numpy.array([[1, 1], [2, 2], [3, 3]], DTYPE) sound.frames = data c = Graph(sound) o = c.channels() assert (len(o)) == 2
def test_Graph(): from gum.lib.mock import Mock, Fake import numpy sound = Mock({"numchan": 1}) sound.changed = Fake() sound.frames = numpy.array(range(1000), DTYPE) c = Graph(sound) c.set_width(200) o = c.channels() class Foo: def foo(self): print "Changed." f = Foo() c = Graph(sound) c.changed.connect(f.foo) c.set_width(200) o = c.channels() # stereo import numpy sound = Mock({"numchan": 2}) sound.changed = Fake() data = numpy.array([[1, 1], [2, 2], [3, 3]], DTYPE) sound.frames = data c = Graph(sound) o = c.channels() assert(len(o)) == 2
def test_middle(): from gum.lib.mock import Mock, Fake import numpy sound = Mock({"numchan": 1}) sound.changed = Fake() sound.frames = [] g = Graph(sound) for nframes, mid in [(4, 1.5), (9, 4), (10, 4.5)]: sound.frames = numpy.array(list(range(nframes))) g.set_sound(sound) assert g.middle() == mid
def test_middle(): from gum.lib.mock import Mock, Fake import numpy sound = Mock({"numchan": 1}) sound.changed = Fake() sound.frames = [] g = Graph(sound) for nframes, mid in [(4, 1.5), (9, 4), (10, 4.5)]: sound.frames = numpy.array(range(nframes)) g.set_sound(sound) assert g.middle() == mid
def test_channels(): import numpy from gum.lib.mock import Mock, Fake sound = Mock({"numchan": 1}) sound.changed = Fake() sound.frames = numpy.array(list(range(1000000)), DTYPE) g = Graph(sound) for w in [1, 10, 11, 12, 13, 14, 15, 29, 54, 12.0, 347, 231., 1030]: g.set_width(w) c = g.channels() assert len(c[0]) == w, \ "expected: %d, got: %d, density: %f, last value: %s " % \ (w, len(c[0]), g.density, str(c[0][-1]))
def test_channels(): import numpy from gum.lib.mock import Mock, Fake sound = Mock({"numchan": 1}) sound.changed = Fake() sound.frames = numpy.array(range(1000000), DTYPE) g = Graph(sound) for w in [1, 10, 11, 12, 13, 14, 15, 29, 54, 12.0, 347, 231., 1030]: g.set_width(w) c = g.channels() assert len(c[0]) == w, \ "expected: %d, got: %d, density: %f, last value: %s " % \ (w, len(c[0]), g.density, str(c[0][-1]))
def test_scroll(): import numpy from gum.lib.mock import Mock, Fake sound = Mock({}) data = numpy.array([1, 2, 3, 4]) sound.frames = data sound.changed = Fake() g = Graph(sound) g.set_width(4) g.scroll_right() length = g.numframes() start, end = g.view() assert length == 4 assert start == 0 assert end == 4
def test_zoom_in(): import numpy from gum.lib.mock import Mock, Fake sound = Mock({"numchan": 1}) sound.changed = Fake() data = numpy.array([1, 2, 3, 4], DTYPE) sound.frames = data g = Graph(sound) g.set_width(2) g.zoom_in() o = g.channels() assert o == [[(2, 2), (3, 3)]] g.zoom_out() g.set_width(4) o = g.channels() assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]]
def testPlayer(): from gum.lib.mock import Mock from math import sin SR = 44100 f0 = 440 time = 1 sine = numpy.array([sin(2 * 3.14 * f0 / SR * x) for x in range(time * SR)]) sound = Mock({"numchan": 1}) sound.samplerate = 44100 sound.frames = sine player = Player(sound) player.thread_play().join() from gum.lib import pysndfile import gum f = pysndfile.sndfile(gum.basedir + '/data/test/test1.wav') data = f.read_frames(f.get_nframes()) sound.frames = data player.set_sound(sound) player.thread_play().join() player.thread_play().join() # Testing position player.start = 40000 player.thread_play().join() player.start = 0 # Test reentrancy print("Two threads will attempt to play at a small interval, you should " "hear the first one being interrupted by the second one.") from time import sleep t1 = player.thread_play() sleep(0.5) t2 = player.thread_play() t1.join() t2.join() print("Two threads will attempt to play simultaneously, you should " "hear only one.") from time import sleep t1 = player.thread_play() t2 = player.thread_play() t1.join() t2.join() # Testing stop print() print("Testing stop(): the sound should stop after 0.3 seconds.") player.thread_play() sleep(0.3) player.stop() # Testing stereo f = pysndfile.sndfile(gum.basedir + '/data/test/test2.wav') data = f.read_frames(f.get_nframes()) sound = Mock({"numchan": 2}) sound.samplerate = 44100 sound.frames = data player = Player(sound) player.thread_play().join()
def testPlayer(): from gum.lib.mock import Mock from math import sin SR = 44100 f0 = 440 time = 1 sine = numpy.array([sin(2 * 3.14 * f0/SR * x) for x in range(time * SR)]) sound = Mock({"numchan": 1}) sound.samplerate = 44100 sound.frames = sine player = Player(sound) player.thread_play().join() from gum.lib import pysndfile import gum f = pysndfile.sndfile(gum.basedir + '/data/test/test1.wav') data = f.read_frames(f.get_nframes()) sound.frames = data player.set_sound(sound) player.thread_play().join() player.thread_play().join() # Testing position player.start = 40000 player.thread_play().join() player.start = 0 # Test reentrancy print ("Two threads will attempt to play at a small interval, you should " "hear the first one being interrupted by the second one.") from time import sleep t1 = player.thread_play() sleep(0.5) t2 = player.thread_play() t1.join() t2.join() print ("Two threads will attempt to play simultaneously, you should " "hear only one.") from time import sleep t1 = player.thread_play() t2 = player.thread_play() t1.join() t2.join() # Testing stop print print "Testing stop(): the sound should stop after 0.3 seconds." player.thread_play() sleep(0.3) player.stop() # Testing stereo f = pysndfile.sndfile(gum.basedir + '/data/test/test2.wav') data = f.read_frames(f.get_nframes()) sound = Mock({"numchan": 2}) sound.samplerate = 44100 sound.frames = data player = Player(sound) player.thread_play().join()
def test_zoom(): from gum.lib.mock import Mock, Fake import numpy sound = Mock({"numchan": 1}) data = numpy.array([1, 2, 3, 4], DTYPE) sound.frames = data sound.changed = Fake() g = Graph(sound) g.set_width(4) g._zoom(1) g.center_on(1.5) o = g.channels() assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]] g._zoom(factor=1) g.center_on(0) o = g.channels() assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]] g._zoom(1) g.center_on(6) o = g.channels() assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]] g._zoom(factor=0.5) g.center_on(1.5) g.set_width(4) o = g.channels() assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]] g.set_width(2) g._zoom(0.5) g.center_on(0) o = g.channels() assert o == [[(1, 1), (2, 2)]] g.set_width(4) g._zoom(0.25) g.center_on(0) o = g.channels() assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]] g.set_width(4) g._zoom(4) g.center_on(4) o = g.channels() assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]], o g.set_width(100) data = numpy.array(list(range(3241))) sound.frames = data g.zoom_out_full() g._zoom(factor=0.5) g._zoom(factor=0.5) start, end = g.view() g.zoom_out_full() g._zoom(factor=0.5 * 0.5) assert (start, end) == g.view()
def test_zoom(): from gum.lib.mock import Mock, Fake import numpy sound = Mock({"numchan": 1}) data = numpy.array([1, 2, 3, 4], DTYPE) sound.frames = data sound.changed = Fake() g = Graph(sound) g.set_width(4) g._zoom(1) g.center_on(1.5) o = g.channels() assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]] g._zoom(factor=1) g.center_on(0) o = g.channels() assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]] g._zoom(1) g.center_on(6) o = g.channels() assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]] g._zoom(factor=0.5) g.center_on(1.5) g.set_width(4) o = g.channels() assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]] g.set_width(2) g._zoom(0.5) g.center_on(0) o = g.channels() assert o == [[(1, 1), (2, 2)]] g.set_width(4) g._zoom(0.25) g.center_on(0) o = g.channels() assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]] g.set_width(4) g._zoom(4) g.center_on(4) o = g.channels() assert o == [[(1, 1), (2, 2), (3, 3), (4, 4)]], o g.set_width(100) data = numpy.array(range(3241)) sound.frames = data g.zoom_out_full() g._zoom(factor=0.5) g._zoom(factor=0.5) start, end = g.view() g.zoom_out_full() g._zoom(factor=0.5 * 0.5) assert (start, end) == g.view()