summaryrefslogtreecommitdiff
path: root/voctocore/lib/audiomix.py
blob: 857600ff98de7afbbd807931a5dfea5c26df0c77 (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. def __init__(self):
  8. self.log = logging.getLogger('AudioMix')
  9. self.selectedSource = 0
  10. self.caps = Config.get('mix', 'audiocaps')
  11. self.names = Config.getlist('mix', 'sources')
  12. self.log.info('Configuring Mixer for %u Sources', len(self.names))
  13. pipeline = """
  14. audiomixer name=mix !
  15. {caps} !
  16. queue !
  17. tee name=tee
  18. tee. ! queue ! interaudiosink channel=audio_mix_out
  19. """.format(
  20. caps=self.caps
  21. )
  22. if Config.getboolean('previews', 'enabled'):
  23. pipeline += """
  24. tee. ! queue ! interaudiosink channel=audio_mix_preview
  25. """
  26. for idx, name in enumerate(self.names):
  27. pipeline += """
  28. interaudiosrc channel=audio_{name}_mixer !
  29. {caps} !
  30. mix.
  31. """.format(
  32. name=name,
  33. caps=self.caps
  34. )
  35. self.log.debug('Creating Mixing-Pipeline:\n%s', pipeline)
  36. self.mixingPipeline = Gst.parse_launch(pipeline)
  37. self.log.debug('Initializing Mixer-State')
  38. self.updateMixerState()
  39. self.log.debug('Launching Mixing-Pipeline')
  40. self.mixingPipeline.set_state(Gst.State.PLAYING)
  41. def updateMixerState(self):
  42. self.log.info('Updating Mixer-State')
  43. for idx, name in enumerate(self.names):
  44. volume = int(idx == self.selectedSource)
  45. self.log.debug('Setting Mixerpad %u to volume=%0.2f', idx, volume)
  46. mixerpad = self.mixingPipeline.get_by_name('mix').get_static_pad('sink_%u' % idx)
  47. mixerpad.set_property('volume', volume)
  48. def setAudioSource(self, source):
  49. self.selectedSource = source
  50. self.updateMixerState()