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


Python mixer.get_init函数代码示例

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


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


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