[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pygame] Synthesised sound
>>>>> "Pete" == Pete Shinners <email@example.com> writes:
>> 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
Pete> your best bet will be to use Numeric to create and alter
Pete> sounds. there are no real examples of this currently, but if
Pete> you understand how sound works it should not be difficult to
Pete> start playing with it.
Pete> for example, to create a solid tone sound you would do
Pete> something like this..
Pete> import Numeric, pygame pygame.init()
Pete> tone_array = Numeric.arange(44100) / 4.0 tone_array =
Pete> tone_sound = pygame.sndarray.make_sound(tone_array)
Pete> once you understand Numeric, it is pretty simple to do
Pete> simple filters like echo, reverse, and envelopes. pygame
Pete> already supports stereo panning effects, but something like
Pete> a doppler shift is going to be tricky.
Pete> your best bet is to probably have two versions of a sound,
Pete> high and low pitch, then mix between them. unfortunately it
Pete> will be a bit tricky to do this "realtime" in the game. the
Pete> easiest way is to play both sounds at the same time, and
Pete> tweak the volume on them as the game runs.
One non-Python tool which could be a big help is Csound, with a bunch
of info on csounds.com. It is essentially a software synthesizer,
something like a compiler for sound. You can create audio from
scratch, as well as process samples you already have.
If you can get away with pre-processing your samples, you could use
this to pitch-bend them whichever way you like, so run-time becomes
more an issue of playing back the one you want. The effects don't have
to be linear, you can use a waveform to modulate the effect.
pygame mailing list