One small improvement to solutions here. First, the problem: you may need to adjust the volume of the playback (monitor) of the application while listening to other audio, but not the recording volume. The module-null-sink works if no output is desired, but what if some is needed or this needs to be controlled on-the-fly?
The problem is that PulseAudio does not allow separate adjustment of a single "slave" or output separately from the sink volume. In other words, you could adjust the application (which will affect everything below in the chain, so that's not good) or the sink the application has been connected to, but the end result in both cases is that playback and recording volume will both be affected - regardless if the recording software connects to the application or the sink.
One solution is: we need to add at least one more sink to the chain.
A solution:
SLAVE_FOR_PLAYBACK=alsa_output.pci-0000_2f_00.4.iec958-stereo
VOLCTRL_SINK_NAME=rec-mon-vol
RECMON_SINK_NAME=rec-n-play
pacmd load-module module-combine-sink sink_name=$VOLCTRL_SINK_NAME slaves=$SLAVE_FOR_PLAYBACK sink_properties=device.description="Recording-Monitor-Volume"
pacmd load-module module-combine-sink sink_name=$RECMON_SINK_NAME slaves=$VOLCTRL_SINK_NAME sink_properties=device.description="Record-and-Monitor"
Solution here is obvious: by adding one more sink into chain to allow decreasing volume after the recording step without affecting recording. I.e. a simple diagram for the above setup:
APP -> REC -> MON -> MASTER_SINK (speakers)
(\--->recording software)
This way we can adjust playback volume at MON
separately from volume incoming to REC
and other applications (music, voice chat etc.) connected to MASTER_SINK
(=speakers).
Alternative solution:
But in case REC volume has been decreased and one wants to increase it at MON, some bitdepth will be lost (if I guess correctly how PulseAudio works). Another (perhaps more elegant solution?) would hence be:
APP -> REC_AND_MONITOR ---> REC (---> recording software)
\--> MONITOR -> MASTER_SINK (speakers)
But this requires a third sink. But now both recording and playback volume can be genuinely adjusted separately without affecting each other (the first solution works nicely only if the volume needs to be decreased only). Like so:
pactl load-module module-null-sink sink_name=rec_monitor sink_properties=device.description="Recording_monitor_volume"
pactl load-module module-null-sink sink_name=rec sink_properties=device.description="Record_with_no_monitoring"
pactl load-module module-combine-sink sink_name=rec-n-monitor sink_properties=device.description="Record_with_monitoring" slaves=rec,rec_monitor
pactl load-module module-loopback source=rec_monitor.monitor sink=${SLAVE_FOR_PLAYBACK} latency_msec=${DESIRED_LATENCY}
Now connect your applications output to rec-n-monitor
, recording software with rec
and can adjust volume of monitor by adjusting rec_monitor
and recording volume by adjusting rec
.
For monitor latency, set DESIRED_LATENCY
for whatever you want. I use 20 (unit is ms). Of course, it depends on your system what the actual latency will be; also see pactl man page. There are other general tricks for lowering Pulseaudio latency, but that is out of scope for this question...