当前位置: 首页>>代码示例>>Python>>正文


Python mixer.pre_init函数代码示例

本文整理汇总了Python中pygame.mixer.pre_init函数的典型用法代码示例。如果您正苦于以下问题:Python pre_init函数的具体用法?Python pre_init怎么用?Python pre_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了pre_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: prepare

def prepare():
    """ Initialise sound module. """
    audio.plugin_dict['pygame'] = AudioPygame
    if pygame:
        # must be called before pygame.init()
        if mixer:
            mixer.pre_init(sample_rate, -mixer_bits, channels=1, buffer=1024) #4096
开发者ID:nestormh,项目名称:pcbasic,代码行数:7,代码来源:audio_pygame.py

示例2: todo_test_pre_init__keyword_args

    def todo_test_pre_init__keyword_args(self):
        # Fails on Mac; probably older SDL_mixer
## Probably don't need to be so exhaustive. Besides being slow the repeated
## init/quit calls may be causing problems on the Mac.
##        configs = ( {'frequency' : f, 'size' : s, 'channels': c }
##                    for f in FREQUENCIES
##                    for s in SIZES
##                    for c in CHANNELS )
        configs = [{'frequency' : 44100, 'size' : 16, 'channels' : 1}]

        for kw_conf in configs:
            mixer.pre_init(**kw_conf)
            mixer.init()

            mixer_conf = mixer.get_init()
            
            self.assertEquals(
                # Not all "sizes" are supported on all systems.
                (mixer_conf[0], abs(mixer_conf[1]), mixer_conf[2]),
                (kw_conf['frequency'],
                 abs(kw_conf['size']),
                 kw_conf['channels'])
            )
            
            mixer.quit()
开发者ID:IuryAlves,项目名称:pygame,代码行数:25,代码来源:mixer_test.py

示例3: init

def init():
    """ Must be called before pygame.init() to enable low latency sound
    """
    # reduce sound latency.  the pygame defaults were ok for 2001,
    # but these values are more acceptable for faster computers
    if _pygame:
        mixer.pre_init(frequency=44100, size=-16, channels=2, buffer=512)
开发者ID:Airon90,项目名称:Tuxemon,代码行数:7,代码来源:__init__.py

示例4: main

def main():
    intervals = {'major 2nd': 2,
                 'minor 3rd': 3, 'major 3rd': 4,
                 'perfect 4th': 5,
                 'perfect 5th': 7}
    interval_lookup = {}
    for key, val in intervals.copy().iteritems():
        # We don't want to modify the dict we're iterating though
        interval_lookup[val] = key  # Add the reverse to the dict

    used_tones = [False] * 12
    notes = len(Note.chromatic)
    tune = []

    def prev_interval():
        """Return the most recent interval"""
        previous_interval = (tune[-2] - tune[-1]) % notes
        # interval might not be in intervals
        if previous_interval in interval_lookup:
            previous_interval = interval_lookup[previous_interval]
        return previous_interval

    def get_new_note(pitch, interval=None):
        """This is embedded so we don't need to pass in used_tones.
        Checks that the note is valid otherwise it picks a new note and sets it
        as used"""
        if interval is not None:
            pitch = (pitch + interval) % len(Note.chromatic)
        if used_tones[pitch] is True and False in used_tones:
            pitch = rand_choice([i for i, used in enumerate(used_tones)
                                 if used is False])
        used_tones[pitch] = True
        return pitch


    tune.append(get_new_note(randint(0, notes - 1)))
    tune.append(get_new_note(tune[-1], rand_choice(intervals.values())))

    while False in used_tones:
        # intelligently choose a new pitch based on the interval between the
        # previous two
        note = get_new_note(randint(0, notes - 1))
        if randint(1, 4) > 1:  # 1 in 4 chance for a random note
            if prev_interval() == 'major 3rd':
                # if the previous interval was a minor 3rd, attempt to follow
                # it with a major 2nd
                # mod is used to stay in the octave
                note = get_new_note(tune[-1], intervals['major 2nd'])
            elif prev_interval == 'perfect 4th':
                # if the previous interval was a major 3rd, attempt to follow
                # by going down a minor 3rd
                note = get_new_note(tune[-1], -1* intervals['major 3rd'])

        tune.append(note)

    mixer.pre_init(44100, -16, 1, 1024)
    pygame.init()
    play_tune([Note.chromatic[note] for note in tune])
    pygame.quit()
开发者ID:solarmist,项目名称:python-learning-experiments,代码行数:59,代码来源:tonerow.py

示例5: __init__

 def __init__(self, delegate):
     super(SoundController, self).__init__()
     self.logger = logging.getLogger('game.sound')
     try:
         mixer.pre_init(44100,-16,2,2048)
         mixer.init()
     except Exception, e:
         # The import mixer above may work, but init can still fail if mixer is not fully supported.
         self.enabled = False
         self.logger.error("pygame mixer init failed; sound will be disabled: "+str(e))
开发者ID:CarnyPriest,项目名称:CCCforVP,代码行数:10,代码来源:sound.py

示例6: todo_test_init__zero_values

 def todo_test_init__zero_values(self):
     # Ensure that argument values of 0 are replaced with
     # preset values. No way to check buffer size though.
     mixer.pre_init(44100, 8, 1)  # None default values
     mixer.init(0, 0, 0)
     try:
         self.failUnlessEqual(mixer.get_init(), (44100, 8, 1))
     finally:
         mixer.quit()
         mixer.pre_init(0, 0, 0, 0)
开发者ID:IuryAlves,项目名称:pygame,代码行数:10,代码来源:mixer_test.py

示例7: main

def main():
    mixer.pre_init(44100, -16, 2, 1024) #sound effects are delayed on my windows machine without this, I think the buffer is initialized too large by default
    pygame.init()
    if android:
        android.init()
        android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)
    while True:
        screen =  get_screen()
        pygame.display.set_caption(TITLE)
        pygame.display.set_icon(load_image(os.path.join('blocks', 'lightgreen.png')))
        menu = Menu(screen)
开发者ID:ubuntunux,项目名称:KivyProject,代码行数:11,代码来源:main.py

示例8: init_mixer

def init_mixer():
    """
    Check that the mixer's initialized and initialize it if not.
    
    """
    # Check PyGame is available
    # This will raise an error if it's not
    check_pygame()
    from pygame import init, mixer
    # Set the mixer settings before initializing everything
    mixer.pre_init(frequency=44100)
    init()
开发者ID:johndpope,项目名称:jazzparser,代码行数:12,代码来源:output.py

示例9: __init__

  def __init__(self, music_directory):
    """ Initialize the MusicPlayer with the music in the given directory. 
    Needs to be called before pygame.init().

    """
    self.music_directory = music_directory
    songs = self.get_list_of_songs(self.music_directory)
    if (len(songs) <= 0):
      print("Please place a .wav file in the directory %s" % directory)
    
    # Initialize mixer with correct frame rate
    mixer.pre_init(self.get_frame_rate(music_directory + '/' + songs[0]))    
开发者ID:SheldonSandbekkhaug,项目名称:radio,代码行数:12,代码来源:MusicPlayer.py

示例10: init_sound

def init_sound(experiment):

	print(
		u"openexp.sampler._legacy.init_sound(): sampling freq = %d, buffer size = %d" \
		% (experiment.sound_freq, experiment.sound_buf_size))
	if hasattr(mixer, u'get_init') and mixer.get_init():
		print(
			u'openexp.sampler._legacy.init_sound(): mixer already initialized, closing')
		pygame.mixer.quit()
	mixer.pre_init(experiment.sound_freq, experiment.sound_sample_size, \
		experiment.sound_channels, experiment.sound_buf_size)
	mixer.init()
开发者ID:FieldDB,项目名称:OpenSesame,代码行数:12,代码来源:legacy.py

示例11: init_sound

def init_sound(experiment):

	"""
	Initializes the pygame mixer before the experiment begins.

	Arguments:
	experiment -- An instance of libopensesame.experiment.experiment
	"""

	print "openexp.sampler._legacy.init_sound(): sampling freq = %d, buffer size = %d" \
		% (experiment.sound_freq, experiment.sound_buf_size)
	if hasattr(mixer, 'get_init') and mixer.get_init():
		print 'openexp.sampler._legacy.init_sound(): mixer already initialized, closing'
		pygame.mixer.quit()
	mixer.pre_init(experiment.sound_freq, experiment.sound_sample_size, \
		experiment.sound_channels, experiment.sound_buf_size)	
	mixer.init()
开发者ID:EoinTravers,项目名称:OpenSesame,代码行数:17,代码来源:legacy.py

示例12: __init__

    def __init__(self,game,priority=10):
        super(SoundController, self).__init__(game,priority)
        self.logger = logging.getLogger('game.sound')
        try:
            mixer.pre_init(frequency=22050, size=-16, channels=2, buffer=256)  #256 prev
            mixer.init()
            mixer.set_num_channels(8)

            self.queue=deque() #for queing up quotes

            mixer.set_reserved(CH_MUSIC_1)
            mixer.set_reserved(CH_MUSIC_2)
            mixer.set_reserved(CH_VOICE)

            #mixer.Channel(CH_VOICE).set_endevent(pygame.locals.USEREVENT)  -- pygame event queue really needs display and cause a ton of issues, creating own

        except Exception, e:
            self.logger.error("pygame mixer init failed; sound will be disabled: "+str(e))
            self.enabled = False
开发者ID:mjocean,项目名称:PyProcGameHD-SkeletonGame,代码行数:19,代码来源:sound.py

示例13: __init__

    def __init__(self, volume):
        mixer.pre_init(44100, -16, 2, 1024)
        mixer.init()
        
        self.menuSound = normpath("sounds/theme.mp3")
        self.gameSound = normpath("sounds/gameTheme.mp3")

        self.successSound = mixer.Sound(normpath("sounds/success.wav"))
        self.failureSound = mixer.Sound(normpath("sounds/failure.wav"))
        self.victorySound = mixer.Sound(normpath("sounds/victory.wav"))

        self.currSound = self.menuSound

        
        self.volumeLevel = volume
        self.setVolume(self.volumeLevel)

        
        mixer.music.load(self.menuSound)
开发者ID:hackerj,项目名称:Treasure-Hunting-Game,代码行数:19,代码来源:Sounds.py

示例14: __init__

 def __init__(self):
     try:
         #Inicilializo el modulo para ejecutar sonidos
         if sys.platform.find('win') != -1:
             mixer.pre_init(44100,16,1,4096)
         else:
             mixer.pre_init(44100)
         mixer.init()
         self.__canal = mixer.find_channel()
         self.__cola = []
         self.__ejecutando_sonidos = False
         self.__end_sound_event = False
         self.__new_sound_event = False
         self.__escuchar = True
         self.__sonido_actual = ""
         self.SILENCE_CHANNEL = USEREVENT + 4
         self.nombre_grupo_sonido = ""
     except pygame.error, e:
         raise Exception("ERROR!: " + str(e) + ", al inicilizar el video. La aplicacion se cerrara")
开发者ID:joausaga,项目名称:clubdeothello,代码行数:19,代码来源:audio.py

示例15: __init__

    def __init__(self):
        """Initializes player in this order:
		   External libraries
		   Data attributes
		   Populating data attributes
		"""
        threading.Thread.__init__(self)
        pygame.init()
        mixer.pre_init(44100, -16, 2, 2048)  # frequency, size, channels, buffersize
        mixer.music.set_endevent(SONG_END)

        self.isPaused = False
        self.isStopped = False
        self.isOnDrakeToday = True
        self.Files = []
        self.CurrentPosition = 0

        self.__loadFiles()

        self.TotalFiles = len(self.Files)
开发者ID:johnmarinelli,项目名称:drake-player,代码行数:20,代码来源:player.py


注:本文中的pygame.mixer.pre_init函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。