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

Re: [pygame] noob questions about creating and playing sounds



>> def play_maxtime(sound, duration):
>>     sound.play(loops=-1, maxtime=duration)
>>     pygame.time.delay(duration)
>>
>> I have a few questions about this:
>>
>>  * Why is it that play_maxtime doesn't work without the time.delay?
>> When I remove the delay line, no sound is played, despite the use of
>> the maxtime argument.
>
> Because without that the program finishes and quits. You would not need
> the time.delay if you were using this in a game, since you would be
> playing your sounds inside the game's loop.

OK, thanks, James!
This shouldn't be a problem, then, if I succeed in somehow creating &
reproducing the sound in real-time, inside some kind main() loop.

That was actually the third question in my original post:
> * Anyone knows how to create the sound in real-time, and feed it to
> the sound card? For example, make the frequency depend on the mouse
> position.