本文整理汇总了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
示例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()
示例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)
示例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()
示例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))
示例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)
示例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)
示例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()
示例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]))
示例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()
示例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()
示例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
示例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)
示例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")
示例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)