def play(loops=0, startpos=0.0): """play(loops=0, start=0.0): return None Start the playback of the music stream""" global _current_music, _music_pos, _music_pos_time, \ _music_frequency, _music_format, _music_channels check_mixer() if not _current_music: raise SDLError("music not loaded") sdl.Mix_HookMusicFinished(_endmusic_callback) sdl.Mix_SetPostMix(_mixmusic_callback, ffi.NULL) frequency, format, channels = (ffi.new('int*'), ffi.new('uint16_t*'), ffi.new('int*')) sdl.Mix_QuerySpec(frequency, format, channels) _music_pos = 0 _music_pos_time = sdl.SDL_GetTicks() _music_frequency = frequency[0] _music_format = format[0] _music_channels = channels[0] volume = sdl.Mix_VolumeMusic(-1) val = sdl.Mix_FadeInMusicPos(_current_music, loops, 0, startpos) sdl.Mix_VolumeMusic(volume) if val == -1: raise SDLError.from_sdl_error()
def get_length(self): """ get_length() -> seconds get the length of the Sound """ check_mixer() frequency, format, channels = (ffi.new('int*'), ffi.new('uint16_t*'), ffi.new('int*')) sdl.Mix_QuerySpec(frequency, format, channels) if format == sdl.AUDIO_S8 or format == sdl.AUDIO_U8: mixerbytes = 1.0 else: mixerbytes = 2.0 numsamples = self.chunk.alen / mixerbytes / channels[0] return numsamples / frequency[0]
def get_init(): """get_init(): return (frequency, format, channels) test if the mixer is initialized""" if not sdl.SDL_WasInit(sdl.SDL_INIT_AUDIO): return None freq = ffi.new("int *") audioformat = ffi.new("uint16_t *") chan = ffi.new("int *") if not sdl.Mix_QuerySpec(freq, audioformat, chan): return None if audioformat[0] & ~0xff: format_in_bits = -(audioformat[0] & 0xff) else: format_in_bits = audioformat[0] & 0xff return (int(freq[0]), format_in_bits, int(chan[0]))