summaryrefslogtreecommitdiff
path: root/voctocore/lib/audiomix.py
blob: 1be32d4ca71cd298d5a37ec67e7fe41f336c2df5 (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. queue !
  20. tee name=tee
  21. tee. ! queue ! interaudiosink channel=audio_mix_out
  22. """.format(
  23. caps=self.caps
  24. )
  25. if Config.getboolean('previews', 'enabled'):
  26. pipeline += """
  27. tee. ! queue ! interaudiosink channel=audio_mix_preview
  28. """
  29. for idx, name in enumerate(self.names):
  30. pipeline += """
  31. interaudiosrc channel=audio_{name}_mixer !
  32. {caps} !
  33. mix.
  34. """.format(
  35. name=name,
  36. caps=self.caps
  37. )
  38. self.log.debug('Creating Mixing-Pipeline:\n%s', pipeline)
  39. self.mixingPipeline = Gst.parse_launch(pipeline)
  40. self.log.debug('Initializing Mixer-State')
  41. self.updateMixerState()
  42. self.log.debug('Launching Mixing-Pipeline')
  43. self.mixingPipeline.set_state(Gst.State.PLAYING)
  44. def updateMixerState(self):
  45. self.log.info('Updating Mixer-State')
  46. for idx, name in enumerate(self.names):
  47. volume = int(idx == self.selectedSource)
  48. self.log.debug('Setting Mixerpad %u to volume=%0.2f', idx, volume)
  49. mixerpad = self.mixingPipeline.get_by_name('mix').get_static_pad('sink_%u' % idx)
  50. mixerpad.set_property('volume', volume)
  51. def setAudioSource(self, source):
  52. self.selectedSource = source
  53. self.updateMixerState()