You are not logged in.

#1 2020-12-02 21:32:54

altermetax
Member
Registered: 2016-03-19
Posts: 74

[SOLVED] Muting PulseAudio module-loopback from command line

My ~/.config/pulse/default.pa looks like this:

.include /etc/pulse/default.pa

load-module module-null-sink sink_name=virtual1 sink_properties=device.description="virtual1-hearshare"
load-module module-null-sink sink_name=virtual2 sink_properties=device.description="virtual2-share"

load-module module-loopback source=virtual1.monitor latency_msec=1 sink=[SPEAKERS]
load-module module-loopback source=virtual1.monitor sink=virtual2 latency_msec=1
load-module module-loopback source=[MICROPHONE] sink=virtual2 latency_msec=1

(/etc/pulse/default.pa) is the default file provided by the Arch package).

I need this in order to share an application's sound (like Firefox) while talking in a voip call (like Discord).
It redirects Firefox's output into the input of Discord, mixing it together with the microphone at the same time, and allowing me to also hear Firefox's output.
So "virtual1-hearshare" gets the stuff I want to hear and share (Firefox output), while "virtual2-share" gets the stuff I want to share (virtual1 plus my microphone). From pavucontrol I can configure what application is connected to what null sink.

Now, sometimes I might need to temporarily disable (and not unload) the third of the three loopback modules, in order to disable the microphone but not Firefox audio sharing. I'm able to do this on pavucontrol, but I can't seem to find a way with pactl. I need to do it from the command line so I can set a keyboard shortcut. Is there a way to do it?

Last edited by altermetax (2020-12-04 17:29:06)

Offline

#2 2020-12-03 11:24:43

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,776

Re: [SOLVED] Muting PulseAudio module-loopback from command line

Check the name of the relevant sink with pacmd list-sinks (... or sources (or source-outputs/sink-inputs) depending on where you want to hook in) and use that to mute. Post the relevant outputs in doubt.

Online

#3 2020-12-03 23:37:40

altermetax
Member
Registered: 2016-03-19
Posts: 74

Re: [SOLVED] Muting PulseAudio module-loopback from command line

Okay, I found the loopback I want to mute at index 2 when running `pacmd list-source-outputs`. How can I refer to it with something better than the index, though? The index might change, so hardcoding that in a script would not be the best idea. Is there a way to give it a name when loading it?

➜  ~ pacmd list-source-outputs 
15 source output(s) available.
    index: 0
	driver: <module-loopback.c>
	flags: START_CORKED 
	state: RUNNING
	source: 7 <virtual1.monitor>
	volume: front-left: 65536 / 100% / 0,00 dB,   front-right: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 0,00 ms
	requested latency: 2,50 ms
	sample spec: s16le 2ch 44100Hz
	channel map: front-left,front-right
	            Stereo
	resample method: (null)
	owner module: 28
	properties:
		media.role = "abstract"
		module-stream-restore.id = "source-output-by-media-role:abstract"
		media.name = "Loopback to KLIM Impact Digital Stereo (IEC958)"
		media.icon_name = "audio-card-usb"
    index: 1
	driver: <module-loopback.c>
	flags: START_CORKED 
	state: RUNNING
	source: 7 <virtual1.monitor>
	volume: front-left: 65536 / 100% / 0,00 dB,   front-right: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 0,00 ms
	requested latency: 2,50 ms
	sample spec: s16le 2ch 44100Hz
	channel map: front-left,front-right
	            Stereo
	resample method: (null)
	owner module: 29
	properties:
		media.role = "abstract"
		module-stream-restore.id = "source-output-by-media-role:abstract"
		media.name = "Loopback to virtual2-share"
		media.icon_name = "audio-card"
    index: 2
	driver: <module-loopback.c>
	flags: START_CORKED 
	state: RUNNING
	source: 2 <alsa_input.usb-0c76_KLIM_Impact-00.mono-fallback>
	volume: front-left: 65536 / 100% / 0,00 dB,   front-right: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 0,00 ms
	requested latency: 2,50 ms
	sample spec: s16le 2ch 44100Hz
	channel map: front-left,front-right
	            Stereo
	resample method: speex-float-1
	owner module: 30
	properties:
		media.role = "abstract"
		module-stream-restore.id = "source-output-by-media-role:abstract"
		media.name = "Loopback to virtual2-share"
		media.icon_name = "audio-card"
    index: 4
	driver: <protocol-native.c>
	flags: DONT_MOVE 
	state: RUNNING
	source: 1 <alsa_output.usb-0c76_KLIM_Impact-00.iec958-stereo.monitor>
	volume: mono: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 8,00 ms
	requested latency: 40,00 ms
	sample spec: float32le 1ch 25Hz
	channel map: mono
	            Mono
	resample method: peaks
	owner module: 14
	client: 16 <PulseAudio Volume Control>
	properties:
		media.name = "Peak detect"
		application.name = "PulseAudio Volume Control"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "34"
		application.id = "org.PulseAudio.pavucontrol"
		application.icon_name = "audio-card"
		application.version = "4.0"
		application.process.id = "18619"
		application.process.user = "altermetax"
		application.process.host = "alterarch"
		application.process.binary = "pavucontrol"
		application.language = "en_US.UTF-8"
		window.x11.display = ":1"
		application.process.machine_id = "ecb8959887ae44019ad174b74781724c"
		module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol"
    index: 5
	driver: <protocol-native.c>
	flags: DONT_MOVE 
	state: RUNNING
	source: 2 <alsa_input.usb-0c76_KLIM_Impact-00.mono-fallback>
	volume: mono: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 0,00 ms
	requested latency: 40,00 ms
	sample spec: float32le 1ch 25Hz
	channel map: mono
	            Mono
	resample method: peaks
	owner module: 14
	client: 16 <PulseAudio Volume Control>
	properties:
		media.name = "Peak detect"
		application.name = "PulseAudio Volume Control"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "34"
		application.id = "org.PulseAudio.pavucontrol"
		application.icon_name = "audio-card"
		application.version = "4.0"
		application.process.id = "18619"
		application.process.user = "altermetax"
		application.process.host = "alterarch"
		application.process.binary = "pavucontrol"
		application.language = "en_US.UTF-8"
		window.x11.display = ":1"
		application.process.machine_id = "ecb8959887ae44019ad174b74781724c"
		module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol"
    index: 6
	driver: <protocol-native.c>
	flags: DONT_MOVE 
	state: RUNNING
	source: 3 <alsa_output.pci-0000_00_1f.3.analog-stereo.monitor>
	volume: mono: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 19,93 ms
	requested latency: 40,00 ms
	sample spec: float32le 1ch 25Hz
	channel map: mono
	            Mono
	resample method: peaks
	owner module: 14
	client: 16 <PulseAudio Volume Control>
	properties:
		media.name = "Peak detect"
		application.name = "PulseAudio Volume Control"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "34"
		application.id = "org.PulseAudio.pavucontrol"
		application.icon_name = "audio-card"
		application.version = "4.0"
		application.process.id = "18619"
		application.process.user = "altermetax"
		application.process.host = "alterarch"
		application.process.binary = "pavucontrol"
		application.language = "en_US.UTF-8"
		window.x11.display = ":1"
		application.process.machine_id = "ecb8959887ae44019ad174b74781724c"
		module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol"
    index: 7
	driver: <protocol-native.c>
	flags: DONT_MOVE 
	state: RUNNING
	source: 4 <alsa_input.pci-0000_00_1f.3.analog-stereo>
	volume: mono: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 0,00 ms
	requested latency: 40,00 ms
	sample spec: float32le 1ch 25Hz
	channel map: mono
	            Mono
	resample method: peaks
	owner module: 14
	client: 16 <PulseAudio Volume Control>
	properties:
		media.name = "Peak detect"
		application.name = "PulseAudio Volume Control"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "34"
		application.id = "org.PulseAudio.pavucontrol"
		application.icon_name = "audio-card"
		application.version = "4.0"
		application.process.id = "18619"
		application.process.user = "altermetax"
		application.process.host = "alterarch"
		application.process.binary = "pavucontrol"
		application.language = "en_US.UTF-8"
		window.x11.display = ":1"
		application.process.machine_id = "ecb8959887ae44019ad174b74781724c"
		module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol"
    index: 8
	driver: <protocol-native.c>
	flags: DONT_MOVE 
	state: RUNNING
	source: 5 <alsa_output.platform-snd_aloop.0.analog-stereo.monitor>
	volume: mono: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 19,11 ms
	requested latency: 40,00 ms
	sample spec: float32le 1ch 25Hz
	channel map: mono
	            Mono
	resample method: peaks
	owner module: 14
	client: 16 <PulseAudio Volume Control>
	properties:
		media.name = "Peak detect"
		application.name = "PulseAudio Volume Control"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "34"
		application.id = "org.PulseAudio.pavucontrol"
		application.icon_name = "audio-card"
		application.version = "4.0"
		application.process.id = "18619"
		application.process.user = "altermetax"
		application.process.host = "alterarch"
		application.process.binary = "pavucontrol"
		application.language = "en_US.UTF-8"
		window.x11.display = ":1"
		application.process.machine_id = "ecb8959887ae44019ad174b74781724c"
		module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol"
    index: 9
	driver: <protocol-native.c>
	flags: DONT_MOVE 
	state: RUNNING
	source: 6 <alsa_input.platform-snd_aloop.0.analog-stereo>
	volume: mono: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 0,00 ms
	requested latency: 40,00 ms
	sample spec: float32le 1ch 25Hz
	channel map: mono
	            Mono
	resample method: peaks
	owner module: 14
	client: 16 <PulseAudio Volume Control>
	properties:
		media.name = "Peak detect"
		application.name = "PulseAudio Volume Control"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "34"
		application.id = "org.PulseAudio.pavucontrol"
		application.icon_name = "audio-card"
		application.version = "4.0"
		application.process.id = "18619"
		application.process.user = "altermetax"
		application.process.host = "alterarch"
		application.process.binary = "pavucontrol"
		application.language = "en_US.UTF-8"
		window.x11.display = ":1"
		application.process.machine_id = "ecb8959887ae44019ad174b74781724c"
		module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol"
    index: 10
	driver: <protocol-native.c>
	flags: DONT_MOVE 
	state: RUNNING
	source: 7 <virtual1.monitor>
	volume: mono: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 0,00 ms
	requested latency: 40,00 ms
	sample spec: float32le 1ch 25Hz
	channel map: mono
	            Mono
	resample method: peaks
	owner module: 14
	client: 16 <PulseAudio Volume Control>
	properties:
		media.name = "Peak detect"
		application.name = "PulseAudio Volume Control"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "34"
		application.id = "org.PulseAudio.pavucontrol"
		application.icon_name = "audio-card"
		application.version = "4.0"
		application.process.id = "18619"
		application.process.user = "altermetax"
		application.process.host = "alterarch"
		application.process.binary = "pavucontrol"
		application.language = "en_US.UTF-8"
		window.x11.display = ":1"
		application.process.machine_id = "ecb8959887ae44019ad174b74781724c"
		module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol"
    index: 11
	driver: <protocol-native.c>
	flags: DONT_MOVE 
	state: RUNNING
	source: 8 <virtual2.monitor>
	volume: mono: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 1,34 ms
	requested latency: 40,00 ms
	sample spec: float32le 1ch 25Hz
	channel map: mono
	            Mono
	resample method: peaks
	owner module: 14
	client: 16 <PulseAudio Volume Control>
	properties:
		media.name = "Peak detect"
		application.name = "PulseAudio Volume Control"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "34"
		application.id = "org.PulseAudio.pavucontrol"
		application.icon_name = "audio-card"
		application.version = "4.0"
		application.process.id = "18619"
		application.process.user = "altermetax"
		application.process.host = "alterarch"
		application.process.binary = "pavucontrol"
		application.language = "en_US.UTF-8"
		window.x11.display = ":1"
		application.process.machine_id = "ecb8959887ae44019ad174b74781724c"
		module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol"
    index: 12
	driver: <protocol-native.c>
	flags: DONT_MOVE 
	state: RUNNING
	source: 9 <alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor>
	volume: mono: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 21,07 ms
	requested latency: 40,00 ms
	sample spec: float32le 1ch 25Hz
	channel map: mono
	            Mono
	resample method: peaks
	owner module: 14
	client: 16 <PulseAudio Volume Control>
	properties:
		media.name = "Peak detect"
		application.name = "PulseAudio Volume Control"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "34"
		application.id = "org.PulseAudio.pavucontrol"
		application.icon_name = "audio-card"
		application.version = "4.0"
		application.process.id = "18619"
		application.process.user = "altermetax"
		application.process.host = "alterarch"
		application.process.binary = "pavucontrol"
		application.language = "en_US.UTF-8"
		window.x11.display = ":1"
		application.process.machine_id = "ecb8959887ae44019ad174b74781724c"
		module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol"
    index: 13
	driver: <protocol-native.c>
	flags: DONT_MOVE 
	state: RUNNING
	source: 1 <alsa_output.usb-0c76_KLIM_Impact-00.iec958-stereo.monitor>
	volume: mono: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 8,00 ms
	requested latency: 40,00 ms
	sample spec: float32le 1ch 25Hz
	channel map: mono
	            Mono
	resample method: peaks
	owner module: 14
	client: 16 <PulseAudio Volume Control>
	direct on input: 0
	properties:
		media.name = "Peak detect"
		application.name = "PulseAudio Volume Control"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "34"
		application.id = "org.PulseAudio.pavucontrol"
		application.icon_name = "audio-card"
		application.version = "4.0"
		application.process.id = "18619"
		application.process.user = "altermetax"
		application.process.host = "alterarch"
		application.process.binary = "pavucontrol"
		application.language = "en_US.UTF-8"
		window.x11.display = ":1"
		application.process.machine_id = "ecb8959887ae44019ad174b74781724c"
		module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol"
    index: 14
	driver: <protocol-native.c>
	flags: DONT_MOVE 
	state: RUNNING
	source: 8 <virtual2.monitor>
	volume: mono: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 1,34 ms
	requested latency: 40,00 ms
	sample spec: float32le 1ch 25Hz
	channel map: mono
	            Mono
	resample method: peaks
	owner module: 14
	client: 16 <PulseAudio Volume Control>
	direct on input: 1
	properties:
		media.name = "Peak detect"
		application.name = "PulseAudio Volume Control"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "34"
		application.id = "org.PulseAudio.pavucontrol"
		application.icon_name = "audio-card"
		application.version = "4.0"
		application.process.id = "18619"
		application.process.user = "altermetax"
		application.process.host = "alterarch"
		application.process.binary = "pavucontrol"
		application.language = "en_US.UTF-8"
		window.x11.display = ":1"
		application.process.machine_id = "ecb8959887ae44019ad174b74781724c"
		module-stream-restore.id = "source-output-by-application-id:org.PulseAudio.pavucontrol"
    index: 15
	driver: <protocol-native.c>
	flags: DONT_MOVE 
	state: RUNNING
	source: 8 <virtual2.monitor>
	volume: mono: 65536 / 100% / 0,00 dB
	       balance 0,00
	muted: no
	current latency: 1,34 ms
	requested latency: 40,00 ms
	sample spec: float32le 1ch 25Hz
	channel map: mono
	            Mono
	resample method: peaks
	owner module: 14
	client: 16 <PulseAudio Volume Control>
	direct on input: 2
	properties:
		media.name = "Peak detect"
		application.name = "PulseAudio Volume Control"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "34"
		application.id = "org.PulseAudio.pavucontrol"
		application.icon_name = "audio-card"
		application.version = "4.0"
		application.process.id = "18619"
		application.process.user = "altermetax"
		application.process.host = "alterarch"
		application.process.binary = "pavucontrol"
		application.language = "en_US.UTF-8"
		window.x11.display = ":1"
		application.process.machine_id = "ecb8959887ae44019ad174b74781724c"
		module-stream-resto

Offline

#4 2020-12-04 15:33:13

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,776

Re: [SOLVED] Muting PulseAudio module-loopback from command line

inputs/outputs don't have identifiable names  afaik. But I'd say the index is pretty stable here. You are doing this setup before any other outputs/inputs even have a chance to be available, you should always  get 2 here, if you don't unload and reload the loopback arbitrarily.

What you could do if that is insufficient is declare an additional intermediate  source that you plug the mic source into then you can name the source and switch the mic off/on that. Speaking of which, are you using the mic for anything else DURING that ? Why not just mute the literal mic source?

Untested proposal for my example:

load-module module-null-sink sink_name=virtual1 sink_properties=device.description="virtual1-hearshare"
load-module module-null-sink sink_name=virtual2 sink_properties=device.description="virtual2-share"

load-module module-loopback source=virtual1.monitor latency_msec=1 sink=[SPEAKERS]
load-module module-loopback source=virtual1.monitor sink=virtual2 latency_msec=1

load-module module-virtual-source source_name=Virtual_Source  master=[MICROPHONE] use_volume_sharing=no
load-module module-loopback source=Virtual_Source sink=virtual2 latency_msec=1

Mute the Virtual_Source as wanted and have discord record off of it (you could also do that with a null-source and the relevant loopback dance, but  imo the virtual-sink / virtual-source is a bit more intuitive)

Online

#5 2020-12-04 17:28:55

altermetax
Member
Registered: 2016-03-19
Posts: 74

Re: [SOLVED] Muting PulseAudio module-loopback from command line

You're right in that the indexes stay constant. I'll use hardcoded indexes then, to keep things simple.
Thanks a lot for your help.

Offline

Board footer

Powered by FluxBB