當前位置: 首頁>>代碼示例>>Python>>正文


Python pygame.mixer方法代碼示例

本文整理匯總了Python中pygame.mixer方法的典型用法代碼示例。如果您正苦於以下問題:Python pygame.mixer方法的具體用法?Python pygame.mixer怎麽用?Python pygame.mixer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pygame的用法示例。


在下文中一共展示了pygame.mixer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: pygamesound

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def pygamesound(sound):
    ''' Create numpy array from pygame sound object
        rate is determined by pygame.mixer settings
    '''
    import pygame
    pygame.sndarray.use_arraytype('numpy')
    array = pygame.sndarray.array(sound)
    rate, format, channels = pygame.mixer.get_init()
    data = numpy.zeros(len(array))
    for i, sample in enumerate(array):
        data[i] = sum(sample)
    if format < 0:
        data /= (2 ** -format) / 2
    else:
        data = (data / (2 ** format)) * 2 - 1
    return data 
開發者ID:wybiral,項目名稱:python-musical,代碼行數:18,代碼來源:source.py

示例2: get_sound

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def get_sound(*names, **kwds):
    if sound_cache is None:
        return dummy_sound
    path = _resource_path("sounds", names, **kwds)
    sound = sound_cache.get(path)
    if not sound:
        try:
            from pygame.mixer import Sound
        except ImportError, e:
            no_sound(e)
            return dummy_sound
        try:
            sound = Sound(path)
        except pygame.error, e:
            missing_sound(e, path)
            return dummy_sound 
開發者ID:mcgreentn,項目名稱:GDMC,代碼行數:18,代碼來源:resource.py

示例3: music

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def music(amusic=None, load=True, play=True, stop=False):
    """ For loading and playing music.

    ::Example::

    music('bla.ogg', load=True, play=True)
    music(stop=True)
    """
    # perhaps the mixer is not included or initialised.
    if pygame.mixer and pygame.mixer.get_init():
        if load and not stop:
            pygame.mixer.music.load(music_path(amusic))
        if play and stop is None or stop is False:
            pygame.mixer.music.play()
        elif stop:
            pygame.mixer.music.stop() 
開發者ID:pygame,項目名稱:stuntcat,代碼行數:18,代碼來源:resources.py

示例4: sfx

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def sfx(snd, play=False, stop=False):
    global _sfx_cache
    snd_key = snd
    if snd_key in _sfx_cache:
        asound = _sfx_cache[snd_key]
    else:
        path = os.path.join(data_path(), 'sounds', snd)
        asound = pygame.mixer.Sound(path)
        _sfx_cache[snd_key] = asound

    # print(snd_key, play, stop, time.time())
    if play:
        asound.play()
    if stop:
        asound.stop()
    return asound 
開發者ID:pygame,項目名稱:stuntcat,代碼行數:18,代碼來源:resources.py

示例5: get_sound

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def get_sound(*names, **kwds):
    if sound_cache is None:
        return dummy_sound
    path = _resource_path("sounds", names, **kwds)
    sound = sound_cache.get(path)
    if not sound:
        try:
            from pygame.mixer import Sound
        except ImportError as e:
            no_sound(e)
            return dummy_sound
        try:
            sound = Sound(path)
        except pygame.error as e:
            missing_sound(e, path)
            return dummy_sound
        sound_cache[path] = sound
    return sound 
開發者ID:Podshot,項目名稱:MCEdit-Unified,代碼行數:20,代碼來源:resource.py

示例6: load_sound

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def load_sound(file):
    if not pygame.mixer: return dummysound()
    file = os.path.join(main_dir, 'data', file)
    try:
        sound = pygame.mixer.Sound(file)
        return sound
    except pygame.error:
        print ('Warning, unable to load, %s' % file)
    return dummysound()



# each type of game object gets an init and an
# update function. the update function is called
# once per frame, and it is when each object should
# change it's current position and state. the Player
# object actually gets a "move" function instead of
# update, since it is passed extra information about
# the keyboard 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:21,代碼來源:aliens.py

示例7: load_sound

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def load_sound(file):
    if not pygame.mixer: return dummysound()
    file = os.path.join('data', file)
    try:
        sound = pygame.mixer.Sound(file)
        return sound
    except pygame.error:
        print ('Warning, unable to load,', file)
    return dummysound()



# each type of game object gets an init and an
# update function. the update function is called
# once per frame, and it is when each object should
# change it's current position and state. the Player
# object actually gets a "move" function instead of
# update, since it is passed extra information about
# the keyboard 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:21,代碼來源:aliens.py

示例8: load_sound

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def load_sound(name):
    class NoneSound:
        def play(self): pass
    if not pygame.mixer or not pygame.mixer.get_init():
        return NoneSound()
    fullname = os.path.join(data_dir, 'sound', name)
    try:
        sound = pygame.mixer.Sound(fullname)
    except pygame.error:
        print('Cannot load sound: %s' % fullname)
        raise SystemExit(str(geterror()))
    return sound 
開發者ID:HuangJunye,項目名稱:QPong,代碼行數:14,代碼來源:resources.py

示例9: _i_eegecx

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def _i_eegecx():
    try:
        import pygame.mixer as ghfkd
        return ghfkd
    except ImportError:
        print "Music not available"
        return None 
開發者ID:mcgreentn,項目名稱:GDMC,代碼行數:9,代碼來源:resource.py

示例10: init

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def init(audio_params):
    """Use this instead of ``pygame.mixer.init``"""
    if config.SOUND:
        pygame.mixer.init(audio_params[0], audio_params[1], audio_params[2], audio_params[3]) 
開發者ID:tobykurien,項目名稱:rpi_lcars,代碼行數:6,代碼來源:sound.py

示例11: load_sound

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def load_sound(name):
    class NoneSound:
        def play(self): pass
    if not pygame.mixer or not pygame.mixer.get_init():
        return NoneSound()
    fullname = os.path.join(data_dir, name)
    try:
        sound = pygame.mixer.Sound(fullname)
    except pygame.error:
        print('Cannot load sound: %s' % fullname)
        raise SystemExit(str(geterror()))
    return sound


# classes for our game objects 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:17,代碼來源:chimp.py

示例12: sound_from_pos

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def sound_from_pos(sound, start_pos, samples_per_second = None, inplace = 1):
    """  returns a sound which begins at the start_pos.
         start_pos - in seconds from the begining.
         samples_per_second - 
    """

    # see if we want to reuse the sound data or not.
    if inplace:
        a1 = pygame.sndarray.samples(sound)
    else:
        a1 = pygame.sndarray.array(sound)

    # see if samples per second has been given.  If not, query the mixer.
    #   eg. it might be set to 22050
    if samples_per_second is None:
        samples_per_second = pygame.mixer.get_init()[0]

    # figure out the start position in terms of samples.
    start_pos_in_samples = int(start_pos * samples_per_second)

    # cut the begining off the sound at the start position.
    a2 = a1[start_pos_in_samples:]

    # make the Sound instance from the array.
    sound2 = pygame.sndarray.make_sound(a2)

    return sound2 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:29,代碼來源:sound_array_demos.py

示例13: array

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def array (sound):
    """pygame._numpysndarray.array(Sound): return array

    Copy Sound samples into an array.

    Creates a new array for the sound data and copies the samples. The
    array will always be in the format returned from
    pygame.mixer.get_init().
    """

    return numpy.array (sound, copy=True) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:13,代碼來源:_numpysndarray.py

示例14: make_sound

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def make_sound (array):
    """pygame._numpysndarray.make_sound(array): return Sound

    Convert an array into a Sound object.
    
    Create a new playable Sound object from an array. The mixer module
    must be initialized and the array format must be similar to the mixer
    audio format.
    """
    
    return mixer.Sound (array=array) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:13,代碼來源:_numpysndarray.py

示例15: samples

# 需要導入模塊: import pygame [as 別名]
# 或者: from pygame import mixer [as 別名]
def samples (sound):
    """pygame._numpysndarray.samples(Sound): return array

    Reference Sound samples into an array.

    Creates a new array that directly references the samples in a Sound
    object. Modifying the array will change the Sound. The array will
    always be in the format returned from pygame.mixer.get_init().
    """

    return numpy.array (sound, copy=False) 
開發者ID:wistbean,項目名稱:fxxkpython,代碼行數:13,代碼來源:_numpysndarray.py


注:本文中的pygame.mixer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。