[SOLVED] alsa/timidity doesn't recognize default device

Kernels & Hardware, configuring network, installing services

[SOLVED] alsa/timidity doesn't recognize default device

Postby samuele » 2020-05-27 11:12

In Debian 10, When I start timidity as alsa sequencer with a normal user, no problem at all. It works flawlessy.

Code: Select all
samuele@INSPIRON-17:~$ timidity -Os -iA
Requested buffer size 32768, fragment size 8192
ALSA pcm 'default' set buffer size 32768, period size 8192 bytes
TiMidity starting in ALSA server mode
Opening sequencer port: 128:0 128:1 128:2 128:3


When I switch to root user, it dosen't works anymore:

Code: Select all
root@INSPIRON-17:~# timidity -Os -iA
ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
Can't open pcm device 'default'.
Couldn't open ALSA pcm device (`s')


It seems it cannot finde the "default" device. I know I can forcing it creating an ~/.asoundrc file or a global /etc/asound.conf, but the normal user dosen't need it. It seems it's accessing the global /usr/share/alsa/alsa.conf, while root dosen't.

So my question is: how i can fix that without writing a new config file? Is it possible to let root access the global file, or I'm missing something?
Last edited by samuele on 2020-05-27 17:02, edited 1 time in total.
samuele
 
Posts: 6
Joined: 2016-02-26 08:57

Re: alsa/timidity doesn't recognize default device

Postby samuele » 2020-05-27 12:32

i think i found something.

According to /usr/share/alsa/alsa.conf, all conf from /etc/alsa/conf.d are loaded. There we have a 99-pulse.conf, linked to /usr/share/alsa/pulse-alsa.conf.
In this last file, pulse is set as default alsa device when pulseaudio is started.

So the reason tmidity it's working in the user' session is because it is using the pulse device.

The root user is not able to access pulseaudio, so there we are.. it's not working.

So a solution can be to enable root user to use pulse. Maybe starting as systemwide... (not so secure) or maybe allowing the root user in another way...
samuele
 
Posts: 6
Joined: 2016-02-26 08:57

Re: alsa/timidity doesn't recognize default device

Postby CwF » 2020-05-27 12:53

Code: Select all
# pulseaudio --start
W: [pulseaudio] main.c: This program is not intended to be run as root (unless --system is specified).
# pulseaudio --system
W: [pulseaudio] main.c: Running in system mode, but --disallow-exit not set.
W: [pulseaudio] main.c: Running in system mode, but --disallow-module-loading not set.
N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode.
N: [pulseaudio] main.c: Running in system mode, forcibly disabling exit idle time.
W: [pulseaudio] main.c: OK, so you are running PA in system mode. Please note that you most likely shouldn't be doing that.
W: [pulseaudio] main.c: If you do it nonetheless then it's your own fault if things don't work as expected.
W: [pulseaudio] main.c: Please read http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/WhatIsWrongWithSystemWide/ for an explanation why system mode is usually a bad idea.
W: [pulseaudio] authkey.c: Failed to open cookie file '/var/run/pulse/.config/pulse/cookie': No such file or directory
W: [pulseaudio] authkey.c: Failed to load authentication key '/var/run/pulse/.config/pulse/cookie': No such file or directory
W: [pulseaudio] authkey.c: Failed to open cookie file '/var/run/pulse/.pulse-cookie': No such file or directory
W: [pulseaudio] authkey.c: Failed to load authentication key '/var/run/pulse/.pulse-cookie': No such file or directory
W: [pulseaudio] protocol-native.c: Denied access to client with invalid authentication data.
CwF
 
Posts: 812
Joined: 2018-06-20 15:16

Re: alsa/timidity doesn't recognize default device

Postby samuele » 2020-05-27 13:10

I believe the real solution it's to change the way timidity daemon is started, changing it from system-wide to user, after pulseaudio is started, instead of changing pulseaudio.

timidity file is /etc/init.d/timidity. How i can do that? How can i change this scripts making it as a service in /usr/lib/systemd/user like pulseaudio.service and be sure at the same time that it spawns after pulseaudio? or maybe the correct solution involves changing permissions? i really don't know. Any idea?
samuele
 
Posts: 6
Joined: 2016-02-26 08:57

Re: alsa/timidity doesn't recognize default device

Postby CwF » 2020-05-27 14:25

My answer is to not use root.
CwF
 
Posts: 812
Joined: 2018-06-20 15:16

Re: alsa/timidity doesn't recognize default device

Postby samuele » 2020-05-27 14:45

yes... as i said i want to start it as a service...
samuele
 
Posts: 6
Joined: 2016-02-26 08:57

Re: alsa/timidity doesn't recognize default device

Postby Head_on_a_Stick » 2020-05-27 16:12

samuele wrote:timidity file is /etc/init.d/timidity. How i can do that? How can i change this scripts making it as a service in /usr/lib/systemd/user like pulseaudio.service and be sure at the same time that it spawns after pulseaudio?

You don't need to change the service file at all, just call it in the ExecStart= line of a custom systemd user service with Requires=pulseaudio.service and After=pulseaudio.service in the [Unit] section. See also http://0pointer.de/blog/projects/system ... ins-3.html

EDIT: or just add the timidity command to ~/.profile (for console sessions) or ~/.xsessionrc (for graphical sessions).
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 12777
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: alsa/timidity doesn't recognize default device

Postby samuele » 2020-05-27 17:02

Head_on_a_Stick wrote:
samuele wrote:timidity file is /etc/init.d/timidity. How i can do that? How can i change this scripts making it as a service in /usr/lib/systemd/user like pulseaudio.service and be sure at the same time that it spawns after pulseaudio?

You don't need to change the service file at all, just call it in the ExecStart= line of a custom systemd user service with Requires=pulseaudio.service and After=pulseaudio.service in the [Unit] section. See also http://0pointer.de/blog/projects/system ... ins-3.html

EDIT: or just add the timidity command to ~/.profile (for console sessions) or ~/.xsessionrc (for graphical sessions).


ok this is very useful, thank you!! And this works without breaking anything. Sadly i didn't waited for your answer and i configured pulseaudio as system-wide :roll:

I tested the system-wide version while waiting. So i post both the soultions here if some may need them.


The simplest and less invasive solution is the one you said: Just install all the base packages:

Code: Select all
sudo apt-get install timidity fluid-soundfont-gm


then create (with sudo) a systemd unit file, located under /usr/lib/systemd/user/timidity.service, with this content

Code: Select all
[Unit]
Description=Timidity
After=pulseaudio.service

[Service]
Type=simple
ExecStart=/usr/bin/timidity -Os -iA

[Install]
WantedBy=pulseaudio.service


now install and enable it

Code: Select all
systemctl --user enable timidity.service
systemctl --user start timidity.service


And it's done, started per-user.

The other solution, in order to get pulse/timidity to work as root system-wide, those are the steps:

To get it system-wide, follow the following steps (inspired by https://raven4.cz/wp/pulseaudio-in-system-wide-mode/)

first install base packages

Code: Select all
sudo apt-get install timidity timidity-daemon fluid-soundfont-gm


edit (with sudo) /etc/pulse/daemon.conf, search the row

Code: Select all
; system-instance = no


uncomment it and set it to yes

Code: Select all
system-instance = yes


now make a backup of the files /etc/pulse/system.pa and /etc/pulse/default.pa, just in case you want to rollback, then symlink default.pa as system.pa

Code: Select all
sudo mv /etc/pulse/system.pa /etc/pulse/system.pa.bak
sudo cp /etc/pulse/default.pa /etc/pulse/default.pa.bak
sudo ln -s /etc/pulse/default.pa /etc/pulse/system.pa


now edit (sudo) /etc/pulse/default.pa, find the row

Code: Select all
load-module module-native-protocol-unix


and change it this way

Code: Select all
load-module module-native-protocol-unix auth-group-enable=true auth-group=pulse-access socket=/tmp/pulse-socket


now edit (sudo) /etc/pulse/client.conf, find the row

Code: Select all
; default-server =


uncomment it and set it this way

Code: Select all
default-server = unix:/tmp/pulse-socket


now we need to add every user we want have access to pulseaudio in the account pulse-access. timidity will run as his own user, so we need to add it too. In my case i want the user root and my main user, samuele, so i'll do:

Code: Select all
usermod -a -G pulse-access root
usermod -a -G pulse-access samuele
usermod -a -G pulse-access timidity


now we need to create the custom pulseaudio.service file. so create a file in /etc/systemd/system/pulseaudio.service with this content

Code: Select all
[Unit]
Description=Pulseaudio

[Service]
User=root
Type=forking
ExecStart=/bin/pulseaudio --realtime --daemonize
Restart=always

[Install]
WantedBy=graphical.target


Now it's time to fix timidity.

Check if it's working with

Code: Select all
aconnect -lo | grep -i timidity


if not, start it

Code: Select all
sudo service timidity start


check again, if everything it's working, whe have a generated service file in /run/systemd/generator.late/timidity.service

copy it to /etc/systemd/system

Code: Select all
sudo cp /run/systemd/generator.late/timidity.service /etc/systemd/system/timidity.service


now edit it (sudo) and in the file beginning search for

Code: Select all
After=remote-fs.target


and change it this way

Code: Select all
After=remote-fs.target pulseaudio.service


In file ending add those two lines to make it installable

Code: Select all
[Install]
WantedBy=multi-user.target


Now it's time for cleaning. stop timidity and remove it from init.d

Code: Select all
sudo service timidity stop
sudo update-rc.d -f timidity remove


stop the per-user pulseaudio, disable it and clean your userdir config

Code: Select all
systemctl --user stop pulseaudio.socket
systemctl --user stop pulseaudio.service
systemctl --user disable pulseaudio.socket
systemctl --user disable pulseaudio.service
rm -Rf ~/.config/pulse/


now enable the new services

Code: Select all
sudo systemctl enable /etc/systemd/system/pulseaudio.service
sudo systemctl enable /etc/systemd/system/timidity.service


restart the machine aaaand.. it's done!
samuele
 
Posts: 6
Joined: 2016-02-26 08:57


Return to System configuration

Who is online

Users browsing this forum: morgon and 11 guests

fashionable