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

Re: [pygame] Incrementing the frequency of the Pygame.mixer with a Loop?



Hi,

I don't know the specific circumstances that required pygame.mixer.pre_init(). But according to the docs (python -m pyagme.docs will display the docs in the default browser) the requirement was that pgyame.mixer was initialized after the display. So I suppose you can initialize pygame and the display outside the loop, then do pygame.mizer.quit() and pygame.mixer.init() calls in the loop.

Lenard


Brian Gryder wrote:
pygame.quit() worked! I can now hear the pitch changing, Thanks!
Is there a way to do this without closing the pygame window everytime it loops?

Here is the working code with the pygame window closing and reopening each loop:
----------------------------------------
import pygame
from pygame.locals import *
from sys import exit

screen = pygame.display.set_mode((800, 600), 0, 32)
frequency = 44100
while True:
   frequency = frequency + 2000
   print frequency
   pygame.mixer.pre_init(frequency, 16, 2, 4096)
   pygame.init()
   test_sound = pygame.mixer.Sound("check.wav")
   mychannel = test_sound.play()
   while pygame.mixer.get_busy() == True:
       pass
   pygame.quit()
screen = pygame.display.set_mode((800, 600), 0, 32) #to reopen the closed window.
----------------------------------------------------------------------


On Thu, Jul 9, 2009 at 8:22 PM, Lenard Lindstrom <len-l@xxxxxxxxx <mailto:len-l@xxxxxxxxx>> wrote:

    Hi,

    You have pygame.quit instead of pygame.quit() .

    Lenard

    Brian Gryder wrote:

        Thanks for the reply Lenard,  I tried your suggestion and the
        pitch is still not changing as the frequency increments with
        the loop.

        This is a strange issue. if I manually change the value if
        frequency before I run it, the sound changes. it is as if the
        pygame.mixer's parameters are "Stuck"and can't be changed
        during runtime. Is there a way I can verify that the
        pygame.mixer and the sound objects are unloaded before I
        restart the loop?

        Is there anything else I can try? Any links or snippet of code
        would be greatly appreciated.

        Here is the updated program
        ---------------------------------------------
        import pygame
        from pygame.locals import *
        from sys import exit

        #pgyame.display.set_mode must also come after the pygame.init.
        The display is not necessary for mixer though. -Lenard
        #screen = pygame.display.set_mode((800, 600), 0, 32)
        frequency = 44100
        while True:
           frequency = frequency + 2000
           print frequency
           pygame.mixer.pre_init(frequency, 16, 2, 4096)
           pygame.init()
           test_sound = pygame.mixer.Sound("check.wav")
           mychannel = test_sound.play()
           while pygame.mixer.get_busy() == True:
               pass
           pygame.quit # "do a pygame.quit rather than
        pygame.mixer.quit for each loop -Lenard

-------------------------------------------------------------------------------------------


        On Wed, Jul 8, 2009 at 2:26 AM, Lenard Lindstrom
        <len-l@xxxxxxxxx <mailto:len-l@xxxxxxxxx>
        <mailto:len-l@xxxxxxxxx <mailto:len-l@xxxxxxxxx>>> wrote:

           Hi Brian,

           You would probably have to do a pygame.quit rather than
           pygame.mixer.quit for each pass of the loop. The
           pgyame.display.set_mode must also come after the
        pygame.init. The
           display is not necessary for mixer though.

           Lenard


           Brian Gryder wrote:

               '''
               How do I change the frequency of the Pygame.mixer by
               incrementing the frequency value in a loop?

               Please see the example below where I am trying to
        initialize
               the frequency at 44100 and then add 2000 to the
        frequency each
               time it loops. In this example below the pitch does not
               change, I really want it to change.

               Any links or snippet of code would be greatly
        appreciated, Thanks!
                '''

               import pygame
               from pygame.locals import *
               from sys import exit

               screen = pygame.display.set_mode((800, 600), 0, 32)
               frequency = 44100

               while True:

                  frequency = frequency + 2000
                  print frequency

                  pygame.mixer.pre_init(frequency, 16, 2, 4096)
                  pygame.init()
                  test_sound = ""
                  test_sound = pygame.mixer.Sound("check.wav")
                  mychannel = test_sound.play()

                  while pygame.mixer.get_busy() == True:
                      pass
                      #"passing"

                  pygame.mixer.quit