当前位置: 首页>>代码示例>>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;未经允许,请勿转载。