Ubuntu – way to control the JACK Output volume via terminal or get a PulseAudio Input

alsajackpulseaudiosoundvolume-control

I have a bit of a specific question:

Being a musician, I use Ubuntu for software monitoring and I would like to control my output master volume with my mouse wheel.

For this purpose, I currently use EasyStroke with the commands amixer -D pulse sset Master 5%+ (Mouse wheel up) and amixer -D pulse sset Master 5%- (Mouse wheel down), which works fine.

The problem is that I use some programs that have a direct JACK output, such as Reaper, my DAW, and also some media players.

As long as the software uses the PulseAudio JACK Sink output, I can control the output volume via mouse wheel, but when the software does not use PulseAudio, it is directly connected to JACK and always at max volume.

If you refer to the screenshot: I am able to manipulate the master volume of the red-marked output (PulseAudio JACK Sink), but I actually need to access the one marked green to control all sound (system out).

Unfortunately, I can not control my ALSA master volume via amixer -q sset Master X, because ALSA does not offer any controls for my only USB sound card.

Is there any way to control the JACK Output volume via terminal that I could replace my mouse button commands with?

Or alternatively, is there a way to add a PulseAudio input module to the right side of the JACK connections to connect Reaper and all other JACK software and route them through the PulseAudio JACK Sink?
(PulseAudio JACK Source is only used for microphones and won't play back the input.)

enter image description here

Best Answer

Based on this example we can solve the problem.

If your sound card can't control the volume on the hardware side or the driver doesn't support this feature of your sound card, a possible workaround is to define a new virtual pcm device in the ~/.asoundrc file, which controls the volume on the software side.

First we need to know the name of our soundcard, thus

 aplay -L

is the helpful command here. The actual card name will be displayed after CARD= and the device name (number) after DEV=.

We can test the device with

speaker-test -D <card name> -c <channel count> -twav

Now we create a new softvol device by adding

pcm.softvol {
    type            softvol
    slave {
    pcm         "<card name>,<device name>"
    }
    control {
        name        "<control name>"
        card        "<card name>"
    }
}

to ~/.asoundrc. (If the file doesn't exist, we have to create the file)

In this case should be Master, please see additional information on control names in the link above.

Now we test the new device with

speaker-test -D softvol -c <channel count> -twav

Open alsamixer, you should see the new control Master now and should be able to change the volume using alsamixer.

It may be necessary to additionally set the device as default in /etc/asound.conf with:

pcm.!default {
    type   hw
    card   <card name>
}
ctl.!default {
    type   hw
    card   <card name>
}

Note that this is different from the suggestion in the link above, but that's what OP reported to work.

Now we need to set Jack interface device to softvol and can use e.g.

amixer -q sset Master 5%+
amixer -q sset Master 5%-
amixer -q sset Master 50%

to increase or decrease the output volume by 5% respectively or set to 50%, fixed.

Amixer needs to "open" the device the first time before the Master volume commands are accessible. Start a sound-test with speaker-test -D softvol -c <channel count> -twav while jackd is not running and then use sudo alsactl store to save the Master-volume state. Otherwise, a sound must be played through softvol after each reboot for the volume control to work.

Related Question