• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mixer.get_init函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __init__

    def __init__(self, value="C", secs=0.5, octave=4, sampleRate=44100,
                 bits=16, name='', autoLog=True, loops=0, stereo=True):
        """
        """
        self.name = name  # only needed for autoLogging
        self.autoLog = autoLog

        if stereo == True:
            stereoChans = 2
        else:
            stereoChans = 0
        if bits == 16:
            # for pygame bits are signed for 16bit, signified by the minus
            bits = -16

        # check initialisation
        if not mixer.get_init():
            pygame.mixer.init(sampleRate, bits, stereoChans, 3072)

        inits = mixer.get_init()
        if inits is None:
            init()
            inits = mixer.get_init()
        self.sampleRate, self.format, self.isStereo = inits

        # try to create sound
        self._snd = None
        # distinguish the loops requested from loops actual because of
        # infinite tones (which have many loops but none requested)
        # -1 for infinite or a number of loops
        self.requestedLoops = self.loops = int(loops)
        self.setSound(value=value, secs=secs, octave=octave)
开发者ID:ChenTzuYin,项目名称:psychopy,代码行数:32,代码来源:backend_pygame.py


示例2: build_samples

 def build_samples(self):
     period = int(round(get_init()[0] / self.frequency))
     samples = array("h", [0] * period)
     amplitude = 2 ** (abs(get_init()[1]) - 1) - 1
     for time in xrange(period):
         if time < period / 2:
             samples[time] = amplitude
         else:
             samples[time] = -amplitude
     return samples
开发者ID:BasedOnTechnology,项目名称:GarbagePython,代码行数:10,代码来源:sonoheadphone.py


示例3: test_get_init__returns_exact_values_used_for_init

    def test_get_init__returns_exact_values_used_for_init(self):
        return 
        # fix in 1.9 - I think it's a SDL_mixer bug.

        # TODO: When this bug is fixed, testing through every combination
        #       will be too slow so adjust as necessary, at the moment it
        #       breaks the loop after first failure

        configs = []
        for f in FREQUENCIES:
            for s in SIZES:
                for c in CHANNELS:
                    configs.append ((f,s,c))

        print (configs)
    

        for init_conf in configs:
            print (init_conf)
            f,s,c = init_conf
            if (f,s) == (22050,16):continue
            mixer.init(f,s,c)

            mixer_conf = mixer.get_init()
            import time
            time.sleep(0.1)

            mixer.quit()
            time.sleep(0.1)

            if init_conf != mixer_conf:
                continue
            self.assertEquals(init_conf, mixer_conf)
开发者ID:IuryAlves,项目名称:pygame,代码行数:33,代码来源:mixer_test.py


示例4: stop_channel

def stop_channel(channel):
    """ Stop sound on a channel. """
    if mixer.get_init():
        mixer.Channel(channel).stop()
        # play short silence to avoid blocking the channel - it won't play on queue()
        silence = pygame.sndarray.make_sound(numpy.zeros(1, numpy.int16))
        mixer.Channel(channel).play(silence)
开发者ID:boriel,项目名称:pcbasic,代码行数:7,代码来源:audio_pygame.py


示例5: 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


示例6: __init__

    def __init__(self, display_w, display_h):
        pygame.init()
        mixer.init()
        font.init()

        # check if the mixer was successfully initialized
        if mixer.get_init() is None:
            print("Failed to initialize the audio mixer module.")

        if font.get_init() is None:
            print("Failed to initialize the font module.")

        self.fps = 120
        self.world = None
        self.gui = Gui(self)

        # Create screen display with 32 bits per pixel, no flags set
        self.display = pygame.display.set_mode((display_w, display_h), pygame.HWSURFACE, 32)
        self.delta_time = 0.0
        self.debug = False
        self.paused = False

        self.print_fps = False

        self.worlds = list()

        self.game = None
开发者ID:Unit978,项目名称:luminescence_standalone,代码行数:27,代码来源:engine.py


示例7: build_samples

 def build_samples(frequency):
     """Build an array of the wave for this frequency"""
     # Hz is cycles per second
     # period = 44100 Hz / 440 Hz = 100 samples per cycle
     # Given samples and cycles per second get the period of each cycle
     period = int(round(mixer.get_init()[0] / frequency))
     # Make one full wave's period
     samples = array("h", [0] * period)
     # Fill with a square wave
     amplitude = 2 ** (abs(mixer.get_init()[1]) - 1) - 1
     for time in xrange(period):
         if time < period / 2:
             samples[time] = amplitude
         else:
             samples[time] = -amplitude
     return samples
开发者ID:solarmist,项目名称:python-learning-experiments,代码行数:16,代码来源:notes.py


示例8: playSound

def playSound(nom):
    """Joue un son une fois"""
    global volumeGlobal, volumeSons
    if not mixer.get_init() : mixer.init()
    son = mixer.Sound('Sons/' + nom + '.ogg')
    son.set_volume(float(volumeGlobal)*float(volumeSound)/10000)
    son.play()
开发者ID:Hugal31,项目名称:Donjon-Python,代码行数:7,代码来源:Audio.py


示例9: initPygame

def initPygame(rate=22050, bits=16, stereo=True, buffer=1024):
    """If you need a specific format for sounds you need to run this init
    function. Run this *before creating your visual.Window*.

    The format cannot be changed once initialised or once a Window has been created.

    If a Sound object is created before this function is run it will be
    executed with default format (signed 16bit stereo at 22KHz).

    For more details see pygame help page for the mixer.
    """
    global Sound, audioDriver
    Sound = SoundPygame
    audioDriver='n/a'
    if stereo==True: stereoChans=2
    else:   stereoChans=0
    if bits==16: bits=-16 #for pygame bits are signed for 16bit, signified by the minus
    mixer.init(rate, bits, stereoChans, buffer) #defaults: 22050Hz, 16bit, stereo,
    sndarray.use_arraytype("numpy")
    setRate, setBits, setStereo = mixer.get_init()
    if setRate!=rate:
        logging.warn('Requested sound sample rate was not poossible')
    if setBits!=bits:
        logging.warn('Requested sound depth (bits) was not possible')
    if setStereo!=2 and stereo==True:
        logging.warn('Requested stereo setting was not possible')
开发者ID:9173860,项目名称:psychopy,代码行数:26,代码来源:sound.py


示例10: __init__

    def __init__(self,value="C",secs=0.5,octave=4, sampleRate=44100, bits=16):
        """
        """

        #check initialisation
        if not mixer.get_init():
            pygame.mixer.init(22050, -16, 2, 3072)
        
        inits = mixer.get_init()
        if inits is None:
            init()
            inits = mixer.get_init()                
        self.sampleRate, self.format, self.isStereo = inits
        
        #try to create sound
        self._snd=None
        self.setSound(value=value, secs=secs, octave=octave)
开发者ID:bjanus,项目名称:psychopy,代码行数:17,代码来源:sound.py


示例11: play

    def play(self, name, queue_sounds=False, play_next_queued_sound=False, loop_forever=False, callback=None):

        if not mixer.get_init():
            print "Mixer not initialized! Cannot play sound."

        #channel = mixer.find_channel()
        #channel.play(self.sounds[id])

        sound_item = self.sounds[name]

        if queue_sounds:
            if mixer.music.get_busy():
                mixer.music.queue(sound_item.path)
                print "Queued sound: " + name

                if play_next_queued_sound:
                    mixer.music.play()
                    if callback:
                        print "Channel playback end callback defined"
                        self.channel_playback_ended_listener(mixer.music, callback)

            else:
                mixer.music.load(sound_item.path)
                if loop_forever:
                    mixer.music.play(-1)
                else:
                    mixer.music.play()

                print "Playing sound: " + name

                if callback:
                        print "Channel playback end callback defined"
                        self.channel_playback_ended_listener(mixer.music, callback)

        else:

            if loop_forever:
                loops = -1
            else:
                loops = 0

            if sound_item.delay == sound_item.delay_min == sound_item.delay_max == 0:
                sound_item.sound.play(loops)

            elif sound_item.delay > 0:
                #pygame.time.wait(sound_item.delay)
                self.play_after_delay(sound_item.sound, sound_item.delay, loops)

            elif sound_item.delay_min == sound_item.delay_max:
                self.play_after_delay(sound_item.sound, sound_item.delay_min, loops)
                #pygame.time.wait(sound_item.delay_min)

            elif sound_item.delay_min > 0 and sound_item.delay_max > 0:
                rand = random.randrange(sound_item.delay_min, sound_item.delay_max, 250)
                #pygame.time.wait(rand)
                self.play_after_delay(sound_item.sound, rand, loops)

            print "Playing sound: " + name
开发者ID:HAZARDU5,项目名称:sgdialer,代码行数:58,代码来源:SoundController.py


示例12: __init__

    def __init__(self,value="C",secs=0.5,octave=4, sampleRate=44100, bits=16, name='', autoLog=True):
        """
        """
        self.name=name#only needed for autoLogging
        self.autoLog=autoLog
        #check initialisation
        if not mixer.get_init():
            pygame.mixer.init(sampleRate, -16, 2, 3072)

        inits = mixer.get_init()
        if inits is None:
            init()
            inits = mixer.get_init()
        self.sampleRate, self.format, self.isStereo = inits

        #try to create sound
        self._snd=None
        self.setSound(value=value, secs=secs, octave=octave)
开发者ID:9173860,项目名称:psychopy,代码行数:18,代码来源:sound.py


示例13: 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


示例14: 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


示例15: test_sound_mixer

 def test_sound_mixer(self):
     """Tests that the app can initialize the pygame audio mixer."""
     import pygame.mixer as mix
     mix.init()
     # check that the mixer initialized
     self.assertIsNotNone(mix.get_init())
     # try to play a sound
     mix.music.load(settings.ARMED_SOUND_FILE)
     mix.music.play()
     while mix.music.get_busy():
         continue
     mix.quit()
开发者ID:bbbenji,项目名称:doorpi2,代码行数:12,代码来源:test_alarm.py


示例16: __init__

    def __init__(self,value="C",secs=0.5,octave=4, sampleRate=44100, bits=16,
                 name='', autoLog=True, loops=0):
        """
        """
        self.name=name#only needed for autoLogging
        self.autoLog=autoLog
        #check initialisation
        if not mixer.get_init():
            pygame.mixer.init(sampleRate, -16, 2, 3072)

        inits = mixer.get_init()
        if inits is None:
            init()
            inits = mixer.get_init()
        self.sampleRate, self.format, self.isStereo = inits

        #try to create sound
        self._snd=None
        #distinguish the loops requested from loops actual because of infinite tones
        # (which have many loops but none requested)
        self.requestedLoops = self.loops = int(loops) #-1 for infinite or a number of loops
        self.setSound(value=value, secs=secs, octave=octave)
开发者ID:TBuwalda,项目名称:psychopy,代码行数:22,代码来源:sound.py


示例17: _check_quit

 def _check_quit(self):
     """Quit the mixer if not running a program and sound quiet for a while."""
     if self.next_tone != [None, None, None, None]:
         self.quiet_ticks = 0
     else:
         self.quiet_ticks += 1
         if not self._persist and self.quiet_ticks > self.quiet_quit:
             # mixer is quiet and we're not running a program.
             # quit to reduce pulseaudio cpu load
             # this takes quite a while and leads to missed frames...
             if mixer.get_init() is not None:
                 mixer.quit()
             self.quiet_ticks = 0
开发者ID:hongriTianqi,项目名称:pcbasic,代码行数:13,代码来源:audio_pygame.py


示例18: check_quit

def check_quit():
    """ Quit the mixer if not running a program and sound quiet for a while. """
    global quiet_ticks
    if next_tone != [None, None, None, None]:
        quiet_ticks = 0
    else:
        quiet_ticks += 1
        if not persist and quiet_ticks > quiet_quit:
            # mixer is quiet and we're not running a program.
            # quit to reduce pulseaudio cpu load
            # this takes quite a while and leads to missed frames...
            if mixer.get_init() is not None:
                mixer.quit()
            quiet_ticks = 0
开发者ID:nony05,项目名称:pcbasic,代码行数:14,代码来源:audio_pygame.py


示例19: alt_1_pushed

 def alt_1_pushed(self):
     if self.data[1]!='':
         if mixer.get_init()!=None:
             if self.mp3media[1]!=None:
                 mixer.music.load(self.mp3media[1])
                 mixer.music.set_volume(config.config['mp3_volume'] / 100.0)
                 mixer.music.play()
         config.config['mascot'] = self.data[1]
         self.setPixmaps()
         self.width = int(self.pixmaps[0].width() * config.config['picture_scale'])
         self.height = int(self.pixmaps[0].height() * config.config['picture_scale'])
         self.resize(self.width, self.height)
         self.label.setGeometry(QtCore.QRect(0, 0, self.width, self.height))
         config.write()
开发者ID:leo-typeb,项目名称:Puppet,代码行数:14,代码来源:puppet.py


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mixer.init函数代码示例发布时间:2022-05-25
下一篇:
Python midi.init函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap