def test_make_sound(self):
if not arraytype:
self.fail("no array package installed")
def check_sound(size, channels, test_data):
try:
pygame.mixer.init(22050, size, channels)
except pygame.error:
# Not all sizes are supported on all systems.
return
try:
__, sz, __ = pygame.mixer.get_init()
if sz == size:
srcarr = array(test_data, self.array_dtypes[size])
snd = pygame.sndarray.make_sound(srcarr)
arr = pygame.sndarray.samples(snd)
self.failUnless(alltrue(arr == srcarr),
"size: %i\n%s\n%s" %
(size, arr, test_data))
finally:
pygame.mixer.quit()
check_sound(8, 1, [0, 0x0f, 0xf0, 0xff])
check_sound(8, 2,
[[0, 0x80], [0x2D, 0x41], [0x64, 0xA1], [0xff, 0x40]])
check_sound(16, 1, [0, 0x00ff, 0xff00, 0xffff])
check_sound(16, 2, [[0, 0xffff], [0xffff, 0],
[0x00ff, 0xff00], [0x0f0f, 0xf0f0]])
check_sound(-8, 1, [0, -0x80, 0x7f, 0x64])
check_sound(-8, 2,
[[0, -0x80], [-0x64, 0x64], [0x25, -0x50], [0xff, 0]])
check_sound(-16, 1, [0, 0x7fff, -0x7fff, -1])
check_sound(-16, 2, [[0, -0x7fff], [-0x7fff, 0],
[0x7fff, 0], [0, 0x7fff]])
评论列表
文章目录