예제 #1
0
def autoquit():
    for joydata in Joystick._OPEN_JOYSTICKS:
        sdl.SDL_JoystickClose(joydata)
    Joystick._OPEN_JOYSTICKS.clear()

    if sdl.SDL_WasInit(sdl.SDL_INIT_JOYSTICK):
        sdl.SDL_JoystickEventState(sdl.SDL_DISABLE)
        sdl.SDL_QuitSubSystem(sdl.SDL_INIT_JOYSTICK)
예제 #2
0
파일: mixer.py 프로젝트: tazjel/pygame_cffi
def autoinit(frequency=None, size=None, channels=None, chunksize=None):
    if not frequency:
        frequency = _request_frequency
    if not size:
        size = _request_size
    if not channels:
        channels = _request_stereo
    if not chunksize:
        chunksize = _request_chunksize

    if channels >= 2:
        channels = 2
    else:
        channels = 1

    # chunk must be a power of 2
    chunksize = int(math.log(chunksize, 2))
    chunksize = 2**chunksize
    if chunksize < buffer:
        chunksize *= 2

    # fmt is a bunch of flags
    if size == 8:
        fmt = sdl.AUDIO_U8
    elif size == -8:
        fmt = sdl.AUDIO_S8
    elif size == 16:
        fmt = sdl.AUDIO_U16SYS
    elif size == -16:
        fmt = sdl.AUDIO_S16SYS
    else:
        raise ValueError("unsupported size %d" % size)

    global _numchanneldata, _channeldata
    if not sdl.SDL_WasInit(sdl.SDL_INIT_AUDIO):
        register_quit(autoquit)
        # channel stuff
        if not _channeldata:
            _numchanneldata = sdl.MIX_CHANNELS
            _channeldata = [ChannelData() for i in range(_numchanneldata)]

        if sdl.SDL_InitSubSystem(sdl.SDL_INIT_AUDIO) == -1:
            return False

        if sdl.Mix_OpenAudio(frequency, fmt, channels, chunksize) == -1:
            sdl.SDL_QuitSubSystem(sdl.SDL_INIT_AUDIO)
            return False
        sdl.Mix_ChannelFinished(_endsound_callback)
        # TODO: reverse stereo for 8-bit below SDL 1.2.8
        sdl.Mix_VolumeMusic(127)
    return True
예제 #3
0
def autoquit():
    global _channeldata, _numchanneldata, _current_music, \
           _queue_music
    if sdl.SDL_WasInit(sdl.SDL_INIT_AUDIO):
        sdl.Mix_HaltMusic()
        # cleanup
        if _channeldata:
            _channeldata = None
            _numchanneldata = 0
        if _current_music:
            sdl.Mix_FreeMusic(_current_music)
            _current_music = None
        if _queue_music:
            sdl.Mix_FreeMusic(_queue_music)
            _queue_music = None

        sdl.Mix_CloseAudio()
        sdl.SDL_QuitSubSystem(sdl.SDL_INIT_AUDIO)
예제 #4
0
def video_autoquit():
    if sdl.SDL_WasInit(sdl.SDL_INIT_VIDEO):
        sdl.SDL_QuitSubSystem(sdl.SDL_INIT_VIDEO)