Esempio n. 1
0
 def set_volume(self, lvolume, rvolume=None):
     check_mixer()
     # This logic differs a bit from pygames because we can use a better
     # sentinal value
     if rvolume is None:
         # No Panning
         if sdl.Mix_SetPanning(self.chan, 255, 255) == 0:
             raise SDLError.from_sdl_error()
         volume = int(lvolume * 128)
     else:
         # Panning
         left = int(lvolume * 255)
         right = int(rvolume * 255)
         if sdl.Mix_SetPanning(self.chan, left, right) == 0:
             raise SDLError.from_sdl_error()
         volume = 128
     sdl.Mix_Volume(self.chan, volume)
Esempio n. 2
0
    def play(self, loops=0, maxtime=-1, fade_ms=0):
        """play(loops=0, maxtime=-1, fade_ms=0) -> Channel
        begin sound playback"""
        if fade_ms > 0:
            channelnum = sdl.Mix_FadeInChannelTimed(-1, self.chunk, loops,
                                                    fade_ms, maxtime)
        else:
            channelnum = sdl.Mix_PlayChannelTimed(-1, self.chunk, loops,
                                                  maxtime)
        if channelnum < 0:
            # failure
            return None

        _channeldata[channelnum].sound = self
        _channeldata[channelnum].queue = None
        sdl.Mix_Volume(channelnum, 128)
        sdl.Mix_GroupChannel(channelnum, self._chunk_tag)
        return Channel(channelnum)
Esempio n. 3
0
 def get_volume(self):
     check_mixer()
     volume = sdl.Mix_Volume(self.chan, -1)
     return volume / 128.0