You are not logged in.

#1 2023-11-02 00:28:25

ipyakuza
Member
Registered: 2013-06-24
Posts: 47

How do I set default volume for firefox in pulse audio?

Hello in a nutshell I am running alsa + pulse audio + ladspa eq module.  Pulse audio is running as a userlevel service autospawned whenever a client requests access.  Everything works fine the problem is I am trying to figure out how to set the default volume level for audio clients (in this case Firefox) as a playback source. 

My scenario is that whenever I run Amazon Music in Firefox, everytime a new song comes on it resets the playback volume to 100% which causes distortion.  The best setting I run with is my output device volume is 100% and my playback/client/source volume is best around 70%. 

analog-stereo is my main audio.  Any insights or tips on how I can configure ~/.config/pulse/client.conf or default.pa with some setting to force firefox (or I guess if I have to settle for all clients/playbacks) to be 75% that would be fine. 

My ALSA config:

cat /etc/asound.conf
pcm.!default {
    type hw
    card 0
}

ctl.!default {
    type hw
    card 0
}

My sinks:

pactl list short sinks
0	alsa_output.pci-0000_01_00.1.hdmi-stereo	module-alsa-card.c	s16le 2ch 44100Hz	IDLE
1	alsa_output.pci-0000_00_1f.3.analog-stereo	module-alsa-card.c	s16le 2ch 44100Hz	RUNNING
2	ladspa_output.mbeq_1197.mbeq	module-ladspa-sink.c	float32le 2ch 44100Hz	IDLE

My sources:

pactl list short sources
0	alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor	module-alsa-card.c	s16le 2ch 44100Hz	RUNNING
1	alsa_input.usb-Roland_UVC-01_0008C33DAC000-03.analog-stereo	module-alsa-card.c	s16le 2ch 48000Hz	RUNNING
2	alsa_input.usb-046d_HD_Pro_Webcam_C920_92D27BAF-02.analog-stereo	module-alsa-card.c	s16le 2ch 32000Hz	RUNNING
3	alsa_output.pci-0000_00_1f.3.analog-stereo.monitor	module-alsa-card.c	s16le 2ch 44100Hz	RUNNING
4	ladspa_output.mbeq_1197.mbeq.monitor	module-ladspa-sink.c	float32le 2ch 44100Hz	RUNNING

The firefox client:

Sink Input #60
	Driver: protocol-native.c
	Owner Module: 11
	Client: 5
	Sink: 2
	Sample Specification: float32le 2ch 44100Hz
	Channel Map: front-left,front-right
	Format: pcm, format.sample_format = "\"float32le\""  format.rate = "44100"  format.channels = "2"  format.channel_map = "\"front-left,front-right\""
	Corked: no
	Mute: no
	Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
	        balance 0.00
	Buffer Latency: 28684 usec
	Sink Latency: 7648 usec
	Resample method: n/a
	Properties:
		media.name = "AudioCallbackDriver"
		application.name = "Firefox"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "35"
		application.process.id = "3485"
		application.process.user = "ipyakuza"
		application.process.host = "rig"
		application.process.binary = "firefox"
		application.language = "en_US.UTF-8"
		window.x11.display = ":0"
		application.process.machine_id = "cb0af80de268470c9c6a9632f40b2e4c"
		application.process.session_id = "2"
		application.icon_name = "firefox"
		module-stream-restore.id = "sink-input-by-application-name:Firefox"

Offline

#2 2023-11-02 01:00:04

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 23,430

Re: How do I set default volume for firefox in pulse audio?

That's the main reason I can't use firefox seriously. It actively and intentionally "remembers" volumes internally and actively configures the stream it creates with it's internal value which is basically always wrong (or rather, non-existent and thus 100% on audio sources not offering a volume control), instead of letting pulse take care of it like every other program ever.

You can try and enforce a certain volume on the pulse side via a client matching regex and the module-match logic

So

load-module module-match

somewhere at the end of your /etc/pulse/default.pa

Where ~/.pulse/match.table contains

^Firefox 45875

to force it to a guaranteed 75%  but that would of course force that specific volume for every stream, instead of remembering individually.

Side note, that ALSA config is in direct conflict with pulseaudio and will break should you ever encounter an actual ALSA client. You should remove it and install pulseaudio-alsa instead.

Last edited by V1del (2023-11-02 01:02:19)

Offline

#3 2023-11-02 01:07:40

ipyakuza
Member
Registered: 2013-06-24
Posts: 47

Re: How do I set default volume for firefox in pulse audio?

Ah glad someone knew what I was struggling with and thank you for the workaround.  I have a similar situation in i3 where I had to use regex matching for applications to behave a certain way.  I'll give this a whirl and update the thread with results.

Last edited by ipyakuza (2023-11-02 01:08:04)

Offline

#4 2023-11-15 16:13:45

Espionage
Member
Registered: 2023-11-15
Posts: 1

Re: How do I set default volume for firefox in pulse audio?

I'm having the exact same problem and the same issue as OP but with Youtube Music. The default for Firefox is 70% for some reason on my install and I want to set it to 20%.

I thought I was on to something with https://github.com/rhaas80/pa_volume but V1Del is 100% spot on that the application just decides not to listen to you and to set it at the default.

I haven't been able to get your solution to work though, part of the annoying thing about how its working with these streaming services is every time a new song is playing it creates a new input sink, so the output of:

pacmd list-sink-inputs

Will be this in the first instance:

2 sink input(s) available.
    index: 0
	driver: <module-ladspa-sink.c>
	flags: START_CORKED
	state: RUNNING
	sink: 2 <alsa_output.pci-0000_0c_00.4.analog-stereo>
	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: 6.94 ms
	sample spec: float32le 2ch 44100Hz
	channel map: front-left,front-right
	             Stereo
	resample method: copy
	module: 27
	properties:
		media.name = "LADSPA Stream"
		media.role = "filter"
		module-stream-restore.id = "sink-input-by-media-role:filter"
    index: 10
	driver: <protocol-native.c>
	flags: START_CORKED
	state: RUNNING
	sink: 4 <ladspa_output.mbeq_1197.mbeq>
	volume: front-left: 46185 /  70% / -9.12 dB,   front-right: 46185 /  70% / -9.12 dB
	        balance 0.00
	muted: no
	current latency: 111.68 ms
	requested latency: 75.01 ms
	sample spec: float32le 2ch 44100Hz
	channel map: front-left,front-right
	             Stereo
	resample method: (null)
	module: 15
	client: 1 <Firefox>
	properties:
		media.name = "YouTube Music"
		application.name = "Firefox"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "35"
		application.process.id = "2110"
		application.process.user = "[private]"
		application.process.host = "[private]"
		application.process.binary = "firefox"
		application.language = "en_AU.UTF-8"
		window.x11.display = ":1"
		application.process.machine_id = "35a59c6c31c34752bb7b76d67e895772"
		application.icon_name = "firefox"
		module-stream-restore.id = "sink-input-by-application-name:Firefox"

Then you change song and it will be all of the sudden:

2 sink input(s) available.
    index: 0
	driver: <module-ladspa-sink.c>
	flags: START_CORKED
	state: RUNNING
	sink: 2 <alsa_output.pci-0000_0c_00.4.analog-stereo>
	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: 6.94 ms
	sample spec: float32le 2ch 44100Hz
	channel map: front-left,front-right
	             Stereo
	resample method: copy
	module: 27
	properties:
		media.name = "LADSPA Stream"
		media.role = "filter"
		module-stream-restore.id = "sink-input-by-media-role:filter"
    index: 4
	driver: <protocol-native.c>
	flags: START_CORKED
	state: RUNNING
	sink: 4 <ladspa_output.mbeq_1197.mbeq>
	volume: front-left: 46185 /  70% / -9.12 dB,   front-right: 46185 /  70% / -9.12 dB
	        balance 0.00
	muted: no
	current latency: 111.09 ms
	requested latency: 75.01 ms
	sample spec: float32le 2ch 44100Hz
	channel map: front-left,front-right
	             Stereo
	resample method: (null)
	module: 15
	client: 4 <Firefox>
	properties:
		media.name = "YouTube Music"
		application.name = "Firefox"
		native-protocol.peer = "UNIX socket client"
		native-protocol.version = "35"
		application.process.id = "2110"
		application.process.user = "[private]"
		application.process.host = "[private]"
		application.process.binary = "firefox"
		application.language = "en_AU.UTF-8"
		window.x11.display = ":1"
		application.process.machine_id = "35a59c6c31c34752bb7b76d67e895772"
		application.icon_name = "firefox"
		module-stream-restore.id = "sink-input-by-application-name:Firefox"

So you see it jumping from index 10 to index 4, and in the process resetting to the default.

No luck with your solution yet, I havent been able to change it from its default 70%

EDIT: This seems related: https://bugzilla.mozilla.org/show_bug.cgi?id=1422637

Last edited by Espionage (2023-11-15 16:34:40)

Offline

#5 2024-05-31 23:53:46

ipyakuza
Member
Registered: 2013-06-24
Posts: 47

Re: How do I set default volume for firefox in pulse audio?

Following up on this old post I ran across an interesting app level fix.

If you open firefox, to go about:config then search for key media.volume_scale set the default value down to 0.50 (which is 50%). This seems to translate in pulse audio to 79% which causes every spawn of the pulse audio client audio volume to 79% which is good.   So this is essentially an app level config change which makes more sense then having pulse try to poll for app class/name and try to control the default volume level.  Just another workaround.

Offline

Board footer

Powered by FluxBB