summaryrefslogtreecommitdiff
path: root/voctocore/lib/audiomix.py
blob: e3075270732dd3965b3630d3e6453877bbbe9078 (plain)
  1. #!/usr/bin/python3
  2. import logging
  3. from gi.repository import Gst
  4. from enum import Enum
  5. from lib.config import Config
  6. class AudioMix(object):
  7. log = logging.getLogger('AudioMix')
  8. mixingPipeline = None
  9. caps = None
  10. names = []
  11. selectedSource = 0
  12. def __init__(self):
  13. self.caps = Config.get('mix', 'audiocaps')
  14. self.names = Config.getlist('mix', 'sources')
  15. self.log.info('Configuring Mixer for %u Sources', len(self.names))
  16. pipeline = """
  17. audiomixer name=mix !
  18. {caps} !
  19. interaudiosink channel=audio_mix
  20. """.format(
  21. caps=self.caps
  22. )
  23. for idx, name in enumerate(self.names):
  24. pipeline += """
  25. interaudiosrc channel=audio_{name}_mixer !
  26. {caps} !
  27. mix.
  28. """.format(
  29. name=name,
  30. caps=self.caps
  31. )
  32. self.log.debug('Creating Mixing-Pipeline:\n%s', pipeline)
  33. self.mixingPipeline = Gst.parse_launch(pipeline)
  34. self.log.debug('Initializing Mixer-State')
  35. self.updateMixerState()
  36. self.log.debug('Launching Mixing-Pipeline')
  37. self.mixingPipeline.set_state(Gst.State.PLAYING)
  38. def updateMixerState(self):
  39. self.log.info('Updating Mixer-State')
  40. for idx, name in enumerate(self.names):
  41. volume = int(idx == self.selectedSource)
  42. self.log.debug('Setting Mixerpad %u to volume=%0.2f', idx, volume)
  43. mixerpad = self.mixingPipeline.get_by_name('mix').get_static_pad('sink_%u' % idx)
  44. mixerpad.set_property('volume', volume)
  45. def setAudioSource(self, source):
  46. self.selectedSource = source
  47. self.updateMixerState()