[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] mixer/sndarray voes





On Fri, Jan 22, 2010 at 7:31 PM, Olof Bjarnason <olof.bjarnason@xxxxxxxxx> wrote:
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=""> 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=""> 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


hi,


here's your example expanded with some of the details commented for you:
    http://rene.f0o.com/~rene/stuff/sndtest2.1.py


Please use a recent pygame.  sndarray has had bugs fixed since 1.8.1.

For ubuntu you may have to compile from source, since they still haven't updated their package in time for ubuntu 9.10:
    http://pygame.org/wiki/CompileUbuntu

However, as of the 14th of jan 2010 it looks like ubuntu has pygame 1.9.1 in for the next ubuntu release (10.4)... :)


Also please use numpy instead of numeric... since numpy is the new numeric for the past few years.  The most recent sound array examples use numpy.


It may also be worth searching on pygame.org for sndarray examples, and looking at the example that comes with pygame.  Also searching with google search turns up some results.
    http://www.google.com/codesearch?hl=en&lr=&q=file%3A\.py%24+pygame.sndarray&sbtn=Search



cheers,