OS: Ubuntu 9.04 Python: 2.6.2 PyGame: 1.8.1release I'm trying to generate some sounds with pygame.
I was hindered some by how to use sndarray - but it all got easier once I set the mixer-init to easy/retro defaults. The first experiment was to just play a "sawtooth" wave: <code src="sndtest.py"> import pygame import Numeric pygame.mixer.pre_init(11025,8,1,4096) #mono, unsigned, 8-bit sound. C64 ;) pygame.init() print pygame.mixer.get_init() # to make sure I got what I wanted, just watch stdout pygame.sndarray.make_sound(Numeric.array(range(250)*100)).play() while pygame.mixer.get_busy(): pygame.time.wait(200) </code> 'python sndtest.py' produces slightly different audio each time. I improved readability a little, to find out where I did go wrong, and to my great surprise, this *silenced* my speakers: <code src="sndtest2.py"> import pygame import Numeric pygame.mixer.pre_init(11025,8,1,4096) #mono, unsigned, 8-bit sound. C64 ;) pygame.init() print pygame.mixer.get_init() # to make sure I got what I wanted, just watch stdout seq = range(250)*100 na = Numeric.array(seq) snd = pygame.sndarray.make_sound(na) snd.play() while pygame.mixer.get_busy(): pygame.time.wait(200) </code> 'python sndtest2.py' only produces a low-volume "spark" then nothing each time run. What am I doing wrong here? There is no randomness in 'sndtest.py', and 'sndtest2.py' should at least produce the same output, afaiks. -- twitter.com/olofb olofb.wordpress.com