[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Synthesised sound



Damien Miller wrote:
> I am pretty new to PyGame (and python in general), but I am loving it
> so far. The combination of PyGame + PIL + PyOpenGL seems especially
> powerful.

cool. glad things are working. i'm curious, what are you using PIL for? 
i know it has some more advanced filtering like blurs and such, but is 
there something specific you are using that pygame doesn't do?


> The equivalent for audio is not so clear. I would like to be able to
> do audio synthesis and/or processing in my application (e.g, doppler 
> shifting). Can anyone point me in the right direction.

your best bet will be to use Numeric to create and alter sounds. there 
are no real examples of this currently, but if you understand how sound 
works it should not be difficult to start playing with it.

for example, to create a solid tone sound you would do something like this..

     import Numeric, pygame
     pygame.init()

     tone_array = Numeric.arange(44100) / 4.0
     tone_array = Numeric.sin(tone_array)

     tone_sound = pygame.sndarray.make_sound(tone_array)
     tone_sound.play()


once you understand Numeric, it is pretty simple to do simple filters 
like echo, reverse, and envelopes. pygame already supports stereo 
panning effects, but something like a doppler shift is going to be tricky.

your best bet is to probably have two versions of a sound, high and low 
pitch, then mix between them. unfortunately it will be a bit tricky to 
do this "realtime" in the game. the easiest way is to play both sounds 
at the same time, and tweak the volume on them as the game runs.

in cvs pygame also has new "sound queueing" functions, so you can 
sequence sounds together. this lets you create continuous dynamic sound 
be feeding small buffers of audio data to the mixer and having it queue 
them together. i have an example of this somewhere, i should put it 
online, since it needs a little explanation on how to tie it all 
together. (basically mixing the new sound "finished" events and sound 
queues)




____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org