def __init__(self, pcm=False, adj=False, arg=None): self.mixer = ossaudiodev.openmixer() get, set = self.mixer.get, self.mixer.set self.channels = [['MASTER', ossaudiodev.SOUND_MIXER_VOLUME], ['PCM', ossaudiodev.SOUND_MIXER_PCM]] if pcm == True: self.channels.insert(0, self.channels.pop()) name, channel = self.channels[0] self.label = "Volume: " #% name # There is no simple way to toggle mute on a channel with ossaudiodev? if adj == True: if arg == -100: if not get(channel)[0]: # Copy the PCM channel #arg = get(self.channels[1][1])[0] # Set to a pre-defined value arg = 94 self.label = "Unmuted: " else: self.label = "Muted: " arg = min(100, max(0, get(channel)[0] + int(arg))) set(channel, (arg, arg)) self.percent = get(channel)[0] self.label = self.label + "%.0f%%" % self.percent self.mixer.close()
def get_controls(driver, device): """Return a list of available controls on the device""" if driver not in available_drivers: raise MixerError("Invalid driver: '{0}'".format(str(driver))) if driver == "ALSA": # Convert device to index dev = _alsa_device_to_idx(device) # Filter out the controls that can't control the volume valid = [] for c in alsaaudio.mixers(): try: m = alsaaudio.Mixer(c, cardindex=dev) if len(m.volumecap()) > 0: valid.append(c) m.close() except alsaaudio.ALSAAudioError: pass elif driver == "OSS": try: om = ossaudiodev.openmixer(device) except (IOError, ossaudiodev.OSSAudioError) as oe: raise MixerError("Error opening mixer: {0}".format(str(oe))) bitmask = om.controls() om.close() # Filter out unavailable controls valid = [ossaudiodev.control_labels[c].rstrip() for c in range(len(ossaudiodev.control_labels)) if bitmask & (1 << c)] if len(valid) < 1: raise MixerError("Could not find any controls for {0}".format(device)) else: return valid
def initWidget(widget): global mixer mixer = ossaudiodev.openmixer() vol_main = karamba.getThemeImage(widget, "vol_main") (l, r) = mixer.get(ossaudiodev.SOUND_MIXER_VOLUME) vol_main_value = max(l, r) karamba.resizeImage(widget, vol_main, vol_main_value, 10) vol_pcm = karamba.getThemeImage(widget, "vol_pcm") (l, r) = mixer.get(ossaudiodev.SOUND_MIXER_PCM) vol_pcm_value = max(l, r) karamba.resizeImage(widget, vol_pcm, vol_pcm_value, 10) vol_cd = karamba.getThemeImage(widget, "vol_cd") (l, r) = mixer.get(ossaudiodev.SOUND_MIXER_CD) vol_cd_value = max(l, r) karamba.resizeImage(widget, vol_cd, vol_cd_value, 10) vol_mic = karamba.getThemeImage(widget, "vol_mic") (l, r) = mixer.get(ossaudiodev.SOUND_MIXER_MIC) vol_mic_value = max(l, r) karamba.resizeImage(widget, vol_mic, vol_mic_value, 10) karamba.redrawWidget(widget)
def __init__(self): abstract.Plugin.__init__(self) box = gtk.HBox(False, 0) self.add(box) btn = gtk.Button() img = gtk.image_new_from_icon_name("stock_volume", gtk.ICON_SIZE_BUTTON) btn.add(img) btn.set_name("EdgeButton") btn.set_relief(gtk.RELIEF_NONE) box.add(btn) globals.tooltips.set_tip(btn, _("Open the volume control")) self._eb = gtk.EventBox() self.bar = gtk.ProgressBar() self.bar.set_orientation(gtk.PROGRESS_BOTTOM_TO_TOP) self.bar.set_size_request(11, 55) box.add(self._eb) self._eb.add(self.bar) btn.connect("clicked", self.__cb_mixer) btn.connect("scroll-event", self.__cb_scroll) self._eb.connect("scroll-event", self.__cb_scroll) self.mixer = ossaudiodev.openmixer() self.update() gobject.timeout_add(1000, self.update) self.show_all()
def __init__(self,name): """Return a named channel of the OSS mixer device. List of all valid audio channel names: ossaudiodev.control_labels.""" self.name = name self.channel = ossaudiodev.control_labels.index(name) self.mixer = ossaudiodev.openmixer() self.saved_vol = self.mixer.get(self.channel) self.is_muted = False
def __init__(self,pcm = False): self.mixer = ossaudiodev.openmixer() self.channels = [['MASTER', ossaudiodev.SOUND_MIXER_VOLUME], ['PCM', ossaudiodev.SOUND_MIXER_PCM]] self.channel = self.channels[0][1] if not pcm else self.channels[1][1] self.get = lambda: self.mixer.get(self.channel)[0] self.set = lambda percents: self.mixer.set(self.channel,(percents,percents)) # pulseaudio default sink (required for unmute method) self.sink = os.popen('pactl info').read().split('Default Sink: ')[1].split('\n')[0] self.value_before_muted = 10
def read_vol(self, widget): """ Devuelve el volumen de la salida de audio """ try: mixer = ossaudiodev.openmixer() if mixer.controls() & (1 << ossaudiodev.SOUND_MIXER_VOLUME): vol = mixer.get(ossaudiodev.SOUND_MIXER_VOLUME) widget.set_value((vol[0]+vol[1])/200.0) except: print "No se pudo leer el volumen"
def _set_volume(self, level): if not self._volume_control: return if level < 0 or level > 100: print >>sys.stderr, "Wrong volume level: %d" % level return try: mixer = ossaudiodev.openmixer() except IOError, reason: print >>sys.stderr, str(reason) return
def volume(self, d = 0): """ Establece el volumen relativo de la salida de audio """ try: mixer = ossaudiodev.openmixer() if mixer.controls() & (1 << ossaudiodev.SOUND_MIXER_VOLUME): vol = mixer.get(ossaudiodev.SOUND_MIXER_VOLUME) new_vol = [vol[0]+d,vol[1]+d] mixer.set(ossaudiodev.SOUND_MIXER_VOLUME, new_vol) except: print "No se pudo leer el volumen"
def __init__(self, pcm=False): self.mixer = ossaudiodev.openmixer() self.channels = [['MASTER', ossaudiodev.SOUND_MIXER_VOLUME], ['PCM', ossaudiodev.SOUND_MIXER_PCM]] self.channel = self.channels[0][1] if not pcm else self.channels[1][1] self.get = lambda: self.mixer.get(self.channel)[0] self.set = lambda percents: self.mixer.set(self.channel, (percents, percents)) # pulseaudio default sink (required for unmute method) self.sink = os.popen('pactl info').read().split( 'Default Sink: ')[1].split('\n')[0] self.value_before_muted = 10
def set_volume(self, widget=None, vol=75): """ Establece el volumen de la salida de audio """ if widget: vol = int(widget.get_value()*100) self.session["volume"] = vol try: mixer = ossaudiodev.openmixer() if mixer.controls() & (1 << ossaudiodev.SOUND_MIXER_VOLUME): mixer.set(ossaudiodev.SOUND_MIXER_VOLUME, (vol,vol)) except: print "No se pudo cambiar el volumen"
def set_format(self, sample_rate, channels, channel_mask, bits_per_sample): """sets the output stream to the given format if the stream hasn't been initialized, this method initializes it if the stream has been initialized to a different format, this method closes and reopens the stream to the new format if the stream has been initialized to the same format, this method does nothing""" if (self.__ossaudio__ is None): # output hasn't been initialized import ossaudiodev AudioOutput.set_format(self, sample_rate, channels, channel_mask, bits_per_sample) # initialize audio output device and setup framelist converter self.__ossaudio__ = ossaudiodev.open('w') self.__ossmixer__ = ossaudiodev.openmixer() if (self.bits_per_sample == 8): self.__ossaudio__.setfmt(ossaudiodev.AFMT_S8_LE) self.__converter__ = lambda f: f.to_bytes(False, True) elif (self.bits_per_sample == 16): self.__ossaudio__.setfmt(ossaudiodev.AFMT_S16_LE) self.__converter__ = lambda f: f.to_bytes(False, True) elif (self.bits_per_sample == 24): from audiotools.pcm import from_list self.__ossaudio__.setfmt(ossaudiodev.AFMT_S16_LE) self.__converter__ = lambda f: from_list([ i >> 8 for i in list(f) ], self.channels, 16, True).to_bytes(False, True) else: raise ValueError("Unsupported bits-per-sample") self.__ossaudio__.channels(channels) self.__ossaudio__.speed(sample_rate) elif (not self.compatible(sample_rate=sample_rate, channels=channels, channel_mask=channel_mask, bits_per_sample=bits_per_sample)): # output has been initialized to a different format self.close() self.set_format(sample_rate=sample_rate, channels=channels, channel_mask=channel_mask, bits_per_sample=bits_per_sample)
def set_format(self, sample_rate, channels, channel_mask, bits_per_sample): """sets the output stream to the given format if the stream hasn't been initialized, this method initializes it if the stream has been initialized to a different format, this method closes and reopens the stream to the new format if the stream has been initialized to the same format, this method does nothing""" if (self.__ossaudio__ is None): #output hasn't been initialized import ossaudiodev AudioOutput.set_format(self, sample_rate, channels, channel_mask, bits_per_sample) #initialize audio output device and setup framelist converter self.__ossaudio__ = ossaudiodev.open('w') self.__ossmixer__ = ossaudiodev.openmixer() if (self.bits_per_sample == 8): self.__ossaudio__.setfmt(ossaudiodev.AFMT_S8_LE) self.__converter__ = lambda f: f.to_bytes(False, True) elif (self.bits_per_sample == 16): self.__ossaudio__.setfmt(ossaudiodev.AFMT_S16_LE) self.__converter__ = lambda f: f.to_bytes(False, True) elif (self.bits_per_sample == 24): from .pcm import from_list self.__ossaudio__.setfmt(ossaudiodev.AFMT_S16_LE) self.__converter__ = lambda f: from_list( [i >> 8 for i in list(f)], self.channels, 16, True).to_bytes(False, True) else: raise ValueError("Unsupported bits-per-sample") self.__ossaudio__.channels(channels) self.__ossaudio__.speed(sample_rate) elif (not self.compatible(sample_rate=sample_rate, channels=channels, channel_mask=channel_mask, bits_per_sample=bits_per_sample)): #output has been initialized to a different format self.close() self.set_format(sample_rate=sample_rate, channels=channels, channel_mask=channel_mask, bits_per_sample=bits_per_sample)
def __init__(self): #self.type = OSS #if self.options.has_key('device'): # self.mixer = ossaudiodev.openmixer(self.options['device']) #else: self.mixer = ossaudiodev.openmixer() #if self.options.has_key('control'): # self.volume = eval("ossaudiodev.%s" % (self.options['control'])) if self.mixer.controls() & (1 << ossaudiodev.SOUND_MIXER_PCM): self.volume = ossaudiodev.SOUND_MIXER_PCM elif self.mixer.controls() & (1 << ossaudiodev.SOUND_MIXER_VOLUME): self.volume = ossaudiodev.SOUND_MIXER_VOLUME else: raise Exception, "No volume control found!"
def open_rec_dev(): """Open and return the audio recording device""" if DEBUG: print 'Opening audio device...' rec_dev = ossaudiodev.open( REC_DEV, 'r' ) rec_dev.setparameters( ossaudiodev.AFMT_S16_LE, 1, RATE ) # adjust mixer level for inputs to maximum volume inputs = [ ossaudiodev.SOUND_MIXER_RECLEV ] mixer=ossaudiodev.openmixer() for i in inputs: # if the recording device has such a channel, boost its level if mixer.controls() & (1 << i): mixer.set( i, (100,100) ) mixer.close() return rec_dev
def __init__(self, remote_ip): threading.Thread.__init__(self) self.remote_ip = remote_ip self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.mixer = ossaudiodev.openmixer('/dev/mixer1') self.mixer.set(ossaudiodev.SOUND_MIXER_MIC, (1,1)) print('set up mixer') print('{0:08b}'.format(self.mixer.stereocontrols())) print('{0:08b}'.format(self.mixer.reccontrols())) self.dsp = ossaudiodev.open('/dev/dsp1', 'r') self.dsp.setfmt(ossaudiodev.AFMT_S16_LE) self.dsp.channels(1) self.dsp.speed(44100) print('set up audio device file')
def __init__(self, device=None, control='Vol'): Mixer.__init__(self) if device is None: # If no device is given, use the first one on the device list self._device = get_devices('OSS')[0] elif isinstance(device, str): self._device = device else: raise ValueError("Invalid device '{0}'".format(str(device))) # Try to open the mixer try: self._mixer = ossaudiodev.openmixer(self._device) except (IOError, ossaudiodev.OSSAudioError) as oe: raise MixerError("Error opening mixer: {0}".format(str(oe))) # Set the control self._control = control self._control_idx = self._control_to_idx(control)
def __init__(self): self.mixfd = None self.muted = 0 # If you're using ALSA or something and you don't set the mixer, # why are we trying to open it? if config.MIXER_DEVICE: try: self.mixfd = ossaudiodev.openmixer(config.MIXER_DEVICE) except IOError: self.reason = 'Couldn\'t open mixer "%s"' % config.MIXER_DEVICE return # init here plugin.DaemonPlugin.__init__(self) self.plugin_name = 'MIXER' self.default_step = config.MIXER_VOLUME_STEP if 0: self.mainVolume = 0 self.pcmVolume = 0 self.lineinVolume = 0 self.micVolume = 0 self.igainVolume = 0 self.ogainVolume = 0 if config.MIXER_MAJOR_CTRL == 'VOL': self.setMainVolume(config.MIXER_VOLUME_DEFAULT) if config.MIXER_CONTROL_ALL: self.setPcmVolume(config.MIXER_VOLUME_MAX) self.setOgainVolume(config.MIXER_VOLUME_MAX) elif config.MIXER_MAJOR_CTRL == 'PCM': self.setPcmVolume(config.MIXER_VOLUME_DEFAULT) if config.MIXER_CONTROL_ALL: self.setMainVolume(config.MIXER_VOLUME_MAX) self.setOgainVolume(config.MIXER_VOLUME_MAX) else: _debug_("No appropriate audio channel found for mixer") if config.MIXER_CONTROL_ALL: self.setLineinVolume(0) self.setMicVolume(0)
def __init__(self): self.mixfd = None self.muted = 0 # If you're using ALSA or something and you don't set the mixer, # why are we trying to open it? if config.MIXER_DEVICE: try: self.mixfd = ossaudiodev.openmixer(config.MIXER_DEVICE) except IOError: self.reason = 'Couldn\'t open mixer "%s"' % config.MIXER_DEVICE return # init here plugin.DaemonPlugin.__init__(self) self.plugin_name = 'MIXER' self.default_step = config.MIXER_VOLUME_STEP if 0: self.mainVolume = 0 self.pcmVolume = 0 self.lineinVolume = 0 self.micVolume = 0 self.igainVolume = 0 self.ogainVolume = 0 if config.MIXER_MAJOR_CTRL == 'VOL': self.setMainVolume(config.MIXER_VOLUME_DEFAULT) if config.MIXER_CONTROL_ALL: self.setPcmVolume(config.MIXER_VOLUME_MAX) self.setOgainVolume(config.MIXER_VOLUME_MAX) elif config.MIXER_MAJOR_CTRL == 'PCM': self.setPcmVolume(config.MIXER_VOLUME_DEFAULT) if config.MIXER_CONTROL_ALL: self.setMainVolume(config.MIXER_VOLUME_MAX) self.setOgainVolume(config.MIXER_VOLUME_MAX) else: logger.debug("No appropriate audio channel found for mixer") if config.MIXER_CONTROL_ALL: self.setLineinVolume(0) self.setMicVolume(0)
def __init__(self): self.mixfd = None self.muted = 0 # If you're using ALSA or something and you don't set the mixer, # why are we trying to open it? if config.DEV_MIXER: try: self.mixfd = ossaudiodev.openmixer(config.DEV_MIXER) except IOError: print 'Couldn\'t open mixer "%s"' % config.DEV_MIXER return # init here plugin.DaemonPlugin.__init__(self) self.plugin_name = 'MIXER' if 0: self.mainVolume = 0 self.pcmVolume = 0 self.lineinVolume = 0 self.micVolume = 0 self.igainVolume = 0 self.ogainVolume = 0 if config.MAJOR_AUDIO_CTRL == 'VOL': self.setMainVolume(config.DEFAULT_VOLUME) if config.CONTROL_ALL_AUDIO: self.setPcmVolume(config.MAX_VOLUME) self.setOgainVolume(config.MAX_VOLUME) elif config.MAJOR_AUDIO_CTRL == 'PCM': self.setPcmVolume(config.DEFAULT_VOLUME) if config.CONTROL_ALL_AUDIO: self.setMainVolume(config.MAX_VOLUME) self.setOgainVolume(config.MAX_VOLUME) else: _debug_("No appropriate audio channel found for mixer") if config.CONTROL_ALL_AUDIO: self.setLineinVolume(0) self.setMicVolume(0)
def set_format(self, sample_rate, channels, channel_mask, bits_per_sample): """initializes the output stream for the given format if the output stream has already been initialized, this will close and reopen the stream for the new format""" if (self.__ossaudio__ is None): import ossaudiodev AudioOutput.set_format(self, sample_rate, channels, channel_mask, bits_per_sample) #initialize audio output device and setup framelist converter self.__ossaudio__ = ossaudiodev.open('w') self.__ossmixer__ = ossaudiodev.openmixer() if (self.bits_per_sample == 8): self.__ossaudio__.setfmt(ossaudiodev.AFMT_S8_LE) self.__converter__ = lambda f: f.to_bytes(False, True) elif (self.bits_per_sample == 16): self.__ossaudio__.setfmt(ossaudiodev.AFMT_S16_LE) self.__converter__ = lambda f: f.to_bytes(False, True) elif (self.bits_per_sample == 24): from .pcm import from_list self.__ossaudio__.setfmt(ossaudiodev.AFMT_S16_LE) self.__converter__ = lambda f: from_list( [i >> 8 for i in list(f)], self.channels, 16, True).to_bytes(False, True) else: raise ValueError("Unsupported bits-per-sample") self.__ossaudio__.channels(channels) self.__ossaudio__.speed(sample_rate) else: self.close() self.set_format(sample_rate=sample_rate, channels=channels, channel_mask=channel_mask, bits_per_sample=bits_per_sample)
if os.path.isfile(os.path.expanduser(ORIENTATION_FILE)): orientation = open(os.path.expanduser(ORIENTATION_FILE)).readline().strip() else: orientation = "horizontal" try: # os.path.exists("%s/.config/pysiv" % os.path.expanduser("~") ) if not os.path.exists(os.path.expanduser(SETTINGS_DIR)): os.makedirs(os.path.expanduser(SETTINGS_DIR)) except Exception, e: print e # Open a handle to the mixer device try: mixer = ossaudiodev.openmixer() mixertype = "oss" except: import alsaaudio mixertype = "alsa" mixer = alsaaudio.Mixer("Master", 0) if mixertype == "oss": # Check if the mixer device has a PCM control, if so we will use that, otherwise use the "Master" volume. # This IF/ELSE is to catch devices without a PCM control. # I prefer to change the value of the PCM control, however if one prefers to use the Master Control, they # can swap the order of ths IF/ELSE, or statically assign it, or skip assigning it here and just use the # ossaudiodev.SOUND_MIXER_MASTER constant when referencing the control.. if mixer.controls() & (1 << ossaudiodev.SOUND_MIXER_PCM): mixer_device = ossaudiodev.SOUND_MIXER_PCM
from __future__ import absolute_import import os import ossaudiodev oss_audio_device = type(ossaudiodev.open('r')) oss_mixer_device = type(ossaudiodev.openmixer(os.devnull))
def _init_oss(self): self.device_mask = getattr(ossaudiodev, "SOUND_MIXER_%s" % self.device.upper(), None) if self.device_mask is None: self.device_mask = getattr(ossaudiodev, "SOUND_MIXER_VOLUME") self.mixer = ossaudiodev.openmixer()