Playing sounds with python and changing their tone during playback?

Is there a way to do this? Also, I need this to work with pygame, since I want audio in my game. I'm asking this because I didn't see any tone change function in pygame.. Anyone knows?

Update:

I need to do something like the noise of a car accelerating. I don't really know if it is timbre or tone.

13.10.2009 15:44:54
What kind of tones? Do you want to just slow them down or speed them up, or are you trying to change the pitch without affecting the length?
endolith 10.11.2009 01:14:33
Yeah, what I meant is to change the pitch without affection on the length
Gabriele Cirulli 10.11.2009 20:30:38
1 ОТВЕТ
РЕШЕНИЕ

Well, it depends on how you're doing your sounds: I'm not sure if this is possible with pygame, but SDL (which pygame is based off of) lets you have a callback to retrieve data for the sound buffer, and it's possible to change the frequency of the sine wave (or whatever) to get different tones in the callback, given that you generate the sound there.

If you're using a pre-rendered tone, or sound file, then you'll probably have to resample it to get it to play at different frequencies, although it'd be difficult to keep the same length. If you're talking about changing the timbre of the sound, then that's a whole different ballpark...

Also, it depends on how fast the sound needs to change: if you can accept a little lag in response, you could probably generate a few short sounds, and play/loop them as necessary. I'm not sure how constant replaying of sounds would impact performance/the overall audio quality, though: you'd have to make sure the ends of all the waveform ends smoothly transition to the beginning of the next one (maybe).

1
13.10.2009 16:17:23