Python alsaaudio.Mixer() Examples

The following are 14 code examples of alsaaudio.Mixer(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module alsaaudio , or try the search function .
Example #1
Source File: playback.py    From PiPod with MIT License 6 votes vote down vote up
def __init__(self):
        self.vlcInstance = vlc.Instance()
        self.player = self.vlcInstance.media_player_new()
        self.alsa = alsaaudio.Mixer(alsaaudio.mixers()[0])
        self.alsa.setvolume(self.volume) 
Example #2
Source File: above_all_patch.py    From launcher with GNU General Public License v3.0 6 votes vote down vote up
def VolumeUp(self):
        m = alsaaudio.Mixer()
        vol = m.getvolume()[0]

 #       print("VolumeUp vol %d " % vol)
        for i,v in enumerate(self.snd_segs):
            if  vol >= v[0] and vol <= v[1]:
                self._Needle = i
                break
          
        self._Needle += 1
        
        if self._Needle > len(self.snd_segs) -1:
            self._Needle = len(self.snd_segs) -1

#        print("Set volume %d" % self.snd_segs[self._Needle][1] )
        m.setvolume( self.snd_segs[self._Needle][0] +  (self.snd_segs[self._Needle][1] - self.snd_segs[self._Needle][0])/2   ) ## prefer bigger one  

        self._Value = self.snd_segs[self._Needle][1]

#        print( self._Value)
        return self._Value 
Example #3
Source File: above_all_patch.py    From launcher with GNU General Public License v3.0 6 votes vote down vote up
def VolumeDown(self):
        m = alsaaudio.Mixer()
        vol = m.getvolume()[0]

        for i,v in enumerate(self.snd_segs):
            if  vol >= v[0] and vol <= v[1]:
                self._Needle = i
                break

        self._Needle -= 1
        if self._Needle < 0:
            self._Needle = 0
        
        vol =  self.snd_segs[self._Needle][0] ## prefer smaller one
        
        if vol < 0:
            vol = 0
        m.setvolume(vol)

#        print(vol)

        self._Value = vol
        return vol 
Example #4
Source File: sound_page.py    From launcher with GNU General Public License v3.0 6 votes vote down vote up
def Init(self):
        self._CanvasHWND = self._Screen._CanvasHWND
        self._Width =  self._Screen._Width
        self._Height = self._Screen._Height
        
        self._MySlider = SoundSlider()

        self._MySlider._Parent = self        
        self._MySlider.SetCanvasHWND(self._CanvasHWND)

        self._MySlider.OnChangeCB = self.WhenSliderDrag

        self._MySlider.Init()
        
        try:
            m = alsaaudio.Mixer()
            self._MySlider.SetValue(m.getvolume()[0])
        except Exception,e:
            print(str(e))
            self._MySlider.SetValue(0) 
Example #5
Source File: alsasync.py    From hifiberry-dsp with MIT License 6 votes vote down vote up
def set_alsa_control(self, alsa_control):
        from alsaaudio import Mixer
        try:
            self.mixer = Mixer(alsa_control)
            logging.debug("using existing ALSA control %s", alsa_control)
        except:
            try:
                logging.debug(
                    "ALSA control %s does not exist, creating it", alsa_control)

                self.mixer = self.create_mixer(alsa_control)
            except Exception as e:
                logging.error(
                    "can't create ALSA mixer control %s (%s)",
                    alsa_control, e)
            return False

        if self.mixer == None:
            logging.error("ALSA mixer %s not found", alsa_control)
            return False

        self.mixername = alsa_control
        return True 
Example #6
Source File: alsasync.py    From hifiberry-dsp with MIT License 6 votes vote down vote up
def read_alsa_data(self):
        from alsaaudio import Mixer
        volumes = Mixer(self.mixername).getvolume()
        channels = 0
        vol = 0
        for i in range(len(volumes)):
            channels += 1
            vol += volumes[i]

        if channels > 0:
            vol = round(vol / channels)
            
        if vol != self.alsavol:
            logging.debug(
                "ALSA volume changed from {}% to {}%".format(self.alsavol, vol))
            self.alsavol = vol
            return True
        else:
            return False 
Example #7
Source File: mastervolume.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        self._osd = OSDPercentage(font=FONT, colour="#6a5acd", timeout=3) # slate blue
        kn = self._knob = PowerVolume()
        kn.open()
        kn.register_motion(self.change_volume)
        kn.register_button(self.handle_button)
        am = self._mixer = alsaaudio.Mixer(alsaaudio.mixers()[0]) # XXX
        self._volume = am.getvolume()[0] 
Example #8
Source File: title_bar.py    From launcher with GNU General Public License v3.0 5 votes vote down vote up
def SyncSoundVolume(self):
        try:
	        m = alsaaudio.Mixer()
	        vol = m.getvolume()[0]	
        except Exception,e:
            print(str(e))
            vol = 0 
Example #9
Source File: sound_page.py    From launcher with GNU General Public License v3.0 5 votes vote down vote up
def OnLoadCb(self):
        try:
            m = alsaaudio.Mixer()
            self._MySlider.SetValue(m.getvolume()[0])
        except Exception,e:
            print(str(e)) 
Example #10
Source File: sound_manager.py    From piclodio3 with MIT License 5 votes vote down vote up
def _get_mixer():
        try:
            mixer = alsaaudio.Mixer()
        except alsaaudio.ALSAAudioError:
            # no master, we are on a Rpi
            mixer = alsaaudio.Mixer("PCM")
        return mixer 
Example #11
Source File: alsasync.py    From hifiberry-dsp with MIT License 5 votes vote down vote up
def create_mixer(name):

        with tempfile.NamedTemporaryFile(mode='w', dir="/tmp", delete=False) as asoundstate:
            content = ALSA_STATE_FILE.replace("%VOLUME%", name)
            logging.debug("asoundstate file %s", content)
            asoundstate.write(content)
            asoundstate.close()

        command = "/usr/sbin/alsactl -f {} restore".format(
            asoundstate.name)
        logging.debug("runnning %s", command)
        os.system(command)
        from alsaaudio import Mixer
        return Mixer(name) 
Example #12
Source File: mixer.py    From mopidy-alsamixer with Apache License 2.0 5 votes vote down vote up
def _mixer(self):
        # The mixer must be recreated every time it is used to be able to
        # observe volume/mute changes done by other applications.
        return alsaaudio.Mixer(cardindex=self.cardindex, control=self.control) 
Example #13
Source File: mixer.py    From mopidy-alsamixer with Apache License 2.0 5 votes vote down vote up
def __init__(self, cardindex, control, callback=None):
        super().__init__()
        self.running = True

        # Keep the mixer instance alive for the descriptors to work
        self.mixer = alsaaudio.Mixer(cardindex=cardindex, control=control)
        descriptors = self.mixer.polldescriptors()
        assert len(descriptors) == 1
        self.fd = descriptors[0][0]
        self.event_mask = descriptors[0][1]

        self.callback = callback 
Example #14
Source File: sound_alsa.py    From pynab with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, hw_model):

        (
            card_index,
            self.sound_card,
            playback_device,
        ) = SoundAlsa.sound_configuration()
        self.playback_device = playback_device

        if self.sound_card == SoundAlsa.MODEL_2018_CARD_NAME:
            self.playback_mixer = None
            self.record_device = "null"
            self.record_mixer = None
        else:
            # do we have anyone else? either way it is not supported
            assert self.sound_card == SoundAlsa.MODEL_2019_CARD_NAME

            self.playback_mixer = alsaaudio.Mixer(
                control="Playback", cardindex=card_index
            )
            self.record_device = self.playback_device
            self.record_mixer = alsaaudio.Mixer(
                control="Capture", cardindex=card_index
            )

            if not SoundAlsa.__test_device(self.record_device, True):
                raise RuntimeError(
                    "Unable to configure sound card for recording"
                )

        self.executor = ThreadPoolExecutor(max_workers=1)

        self.future = None
        self.currently_playing = False
        self.currently_recording = False