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()