Problem starting Fluidsynth on a headless RPi

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem starting Fluidsynth on a headless RPi

George Poulson
Hi guys, I'm new to this list so please be gentle! :-)
Apologies in advance if this has been covered before but despite endless searching I've still not found a way forward

I've recently bought a Nektar MIDI keyboard controller to allow me to learn to play while keeping a link to my 50+ years experience in computers. I can plug the keyboard into my laptop and can use <insert software name here> to listen, via PC speakers, headphones, whatever.

To avoid having to use my laptop every time I just want to practice on the keyboard for 20 mins or so I have used an RPi3b from my parts box, loaded up raspbian, fluidsynth and such and if I connect with SSH from my laptop I can start fluidsynth with the appropriate settings and it all works.

My problem is that I want fluidsynth to start at boot time so that the RPi becomes a simple 'black box' between my keyboard and headphones, and I am failing miserably when it comes to getting fluidsynth to start without manual intervention.

My command line to start fluidsynth is:

/home/george/fluidsynth -s -i -m alsa_seq -o midi.autoconnect=1 -a alsa -g 4 /home/george/GeneralUser_GS_v1.471.sf2

[fluidsynth is only in my home directory as it is a local compile because the repository version is too old]

I have tried using [/etc/rc.local], [cron and @reboot] but I can't make the *$£*&% thing work as I need it to. Cron/@reboot would be my preferred way and when I do this, I can log in after booting, see from 'ps waux' that fluidsynth is running yet there is no audio output. Stopping and starting fluidsynth manually from a command prompt gets it working fine and the 'ps' output looks identical!!
=======
$ps waux | grep fluid
george    1115 11.8  5.5  89472 52460 pts/1    SLl+ 14:00   0:00 /home/george/fluidsynth -s -i -m alsa_seq -o midi.autoconnect 1 -a alsa -g 4 /home/george/GeneralUser_GS_v1.471.sf2
=======

I'm thinking that it perhaps could be because the audio connection (alsa) isn't being made when fluidsynth is run without a shell, but with little or no verbose logging from fluidsynth or alsa I am totally stumped!

Please can someone try to help me shed some light on this? I can obviously provide more diagnostic info if anyone here feels that they can help.

Thanks in anticipation.
George




_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem starting Fluidsynth on a headless RPi

Marcus Weseloh
Hi George,

you can try to find out what's going on by redirecting fluidsynth output on stderr and stdout to a file. For example, to log both errors and normal output to a single file /tmp/fluidsynth.log, you can use:

/home/george/fluidsynth -s -i -m alsa_seq -o midi.autoconnect=1 -a alsa -g 4 /home/george/GeneralUser_GS_v1.471.sf2 2>&1 > /tmp/fluidsynth.log

The 2>&1 redirects stderr to stdout and > redirects stdout into a file.
Then restart your RPi and check the log file.

I have the suspicion that fluidsynth might works as expected, but that your MIDI keyboard is not yet fully registered as a MIDI device when fluidsynth starts. You can check that by issuing the following command: aconnect -l 

Issue this twice: once when you started fluidsynth via SSH and once when you had it start on boot. Then compare the outputs.

Cheers
Marcus

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem starting Fluidsynth on a headless RPi

George Poulson
@Marcus - many thanks for your help.

I tried directing the output from fluidsynth to a file but it was too brief to reveal anything.
I also used 'aconnect -l' to determine whether it was the midi connection from my keyboard that was not being made correctly but everything was as expected;
Next I tried using aconnect to manually disconnect and re-make the midi connections with fluidsynth in both its 'not working' and 'working' states but again the outcome did not change. Removing the midi.autoconnect command-line switch and connecting using aconnect once fluidsynth had started also made no difference

This kind of made me think that the issue was not with the midi connection so I went back to looking at whether it could be the alsa audio connection.

I had received another [email-only] reply (thanks Alberto!) suggesting that I try setting my Pi to automatically create a login as root at boot time and to use the root .profile to run fluidsynth. I decided to give this a try and the first attempt failed again but I could at least see that fluidsynth was now running with an attached tty.
Purely by accident I ran 'sudo su' on another SSH session (and thus inadvertently started another instance of fluidsynth) and suddenly somehow fluidsynth started producing audio!!

To cut a long story short after more 'tinkering in the dark' I now have my system working as I need it to (albeit with a nasty root-login security hole - unimportant to me as this is going to be a stand-alone box).

So I now have :
1) a '/home/george/startfs' shell script which contains:
==========
/home/george/fluidsynth -s -i -o midi.autoconnect=1 -m alsa_seq -a alsa -g 1 /home/george/GeneralUser_GS_v1.471.sf2 &
==========


3) root's .profile contains:
==========
/home/george/startfs
sleep 2
killall fluidsynth
/home/george/startfs
==========

Somewhat bizarrely fluidsynth only produces audio via alsa having been started once, killed and restarted, but this approach does now work reliably.

When I get chance I may investigate using jackd or a different audio connection method, but for now I have what I need - albeit a bit of a nasty hack!!

Thanks guys for the help.
Kind regards,
George
((Somerset, UK))



_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem starting Fluidsynth on a headless RPi

Ceresa Jean-Jacques

Hello Georges,

 

After reading your issue about no Alsa audio when starting FluidSynth from root .profile.

This sounds like if Alsa hadn't started (or not yet finished its initialization) before FluidSynth starts.

May be could you validate this supposing trying to start Alsa player (aplay) from root .profile by requesting it playing an audio file

instead of starting FluidSynth ?.

 

Regards

jjc

> Message du 29/01/20 13:25

> De : "George Poulson" <[hidden email]>
> A : "FluidSynth mailing list" <[hidden email]>
> Copie à :
> Objet : Re: [fluid-dev] Problem starting Fluidsynth on a headless RPi
>
>
 
@Marcus - many thanks for your help.

>
I tried directing the output from fluidsynth to a file but it was too brief to reveal anything.
I also used 'aconnect -l' to determine whether it was the midi connection from my keyboard that was not being made correctly but everything was as expected;
>
Next I tried using aconnect to manually disconnect and re-make the midi connections with fluidsynth in both its 'not working' and 'working' states but again the outcome did not change. Removing the midi.autoconnect command-line switch and connecting using aconnect once fluidsynth had started also made no difference
>

>
This kind of made me think that the issue was not with the midi connection so I went back to looking at whether it could be the alsa audio connection.

>
I had received another [email-only] reply (thanks Alberto!) suggesting that I try setting my Pi to automatically create a login as root at boot time and to use the root .profile to run fluidsynth. I decided to give this a try and the first attempt failed again but I could at least see that fluidsynth was now running with an attached tty.
>
Purely by accident I ran 'sudo su' on another SSH session (and thus inadvertently started another instance of fluidsynth) and suddenly somehow fluidsynth started producing audio!!

>
To cut a long story short after more 'tinkering in the dark' I now have my system working as I need it to (albeit with a nasty root-login security hole - unimportant to me as this is going to be a stand-alone box).

>
So I now have :
>
1) a '/home/george/startfs' shell script which contains:
==========
/home/george/fluidsynth -s -i -o midi.autoconnect=1 -m alsa_seq -a alsa -g 1 /home/george/GeneralUser_GS_v1.471.sf2 &
==========
>

>

>
3) root's .profile contains:
==========
>
/home/george/startfs
> sleep 2
> killall fluidsynth
> /home/george/startfs
==========
>

>
Somewhat bizarrely fluidsynth only produces audio via alsa having been started once, killed and restarted, but this approach does now work reliably.
>

>
When I get chance I may investigate using jackd or a different audio connection method, but for now I have what I need - albeit a bit of a nasty hack!!

>
Thanks guys for the help.
Kind regards,
George
((Somerset, UK))

>

>


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem starting Fluidsynth on a headless RPi

George Poulson
Hi Jean-Jacques.
I have tried what you suggested by updating /root/.profile like this:

========
aplay /usr/share/sounds/alsa/Front_Left.wav
/home/george/startfs
sleep 2
aplay /usr/share/sounds/alsa/Front_Right.wav
killall fluidsynth
sleep 2
/home/george/startfs
aplay /usr/share/sounds/alsa/Front_Left.wav
========

.. and ALL of these files play OK in left-right-left sequence and fluidsynth plays from the midi input correctly at the end.

if I change the file like this:

========
aplay /usr/share/sounds/alsa/Front_Left.wav
### /home/george/startfs
sleep 2
aplay /usr/share/sounds/alsa/Front_Right.wav
### killall fluidsynth
sleep 2
/home/george/startfs
aplay /usr/share/sounds/alsa/Front_Left.wav
========

.. this time the wav files are again all played correctly but fluidsynth does not play the midi input!!

So there is something happening in my environment such that fluidsynth has to be started, stopped and restarted for it to play correctly.

So my little project is working and I am happy - but as an 'old school' engineer I'd still like to know just what is going on :-)

George



On Wed, 29 Jan 2020 at 13:15, Ceresa Jean-Jacques <[hidden email]> wrote:

Hello Georges,

 

After reading your issue about no Alsa audio when starting FluidSynth from root .profile.

This sounds like if Alsa hadn't started (or not yet finished its initialization) before FluidSynth starts.

May be could you validate this supposing trying to start Alsa player (aplay) from root .profile by requesting it playing an audio file

instead of starting FluidSynth ?.

 

Regards

jjc

> Message du 29/01/20 13:25

> De : "George Poulson" <[hidden email]>
> A : "FluidSynth mailing list" <[hidden email]>
> Copie à :
> Objet : Re: [fluid-dev] Problem starting Fluidsynth on a headless RPi
>
>
 
@Marcus - many thanks for your help.

>
I tried directing the output from fluidsynth to a file but it was too brief to reveal anything.
I also used 'aconnect -l' to determine whether it was the midi connection from my keyboard that was not being made correctly but everything was as expected;
>
Next I tried using aconnect to manually disconnect and re-make the midi connections with fluidsynth in both its 'not working' and 'working' states but again the outcome did not change. Removing the midi.autoconnect command-line switch and connecting using aconnect once fluidsynth had started also made no difference
>

>
This kind of made me think that the issue was not with the midi connection so I went back to looking at whether it could be the alsa audio connection.

>
I had received another [email-only] reply (thanks Alberto!) suggesting that I try setting my Pi to automatically create a login as root at boot time and to use the root .profile to run fluidsynth. I decided to give this a try and the first attempt failed again but I could at least see that fluidsynth was now running with an attached tty.
>
Purely by accident I ran 'sudo su' on another SSH session (and thus inadvertently started another instance of fluidsynth) and suddenly somehow fluidsynth started producing audio!!

>
To cut a long story short after more 'tinkering in the dark' I now have my system working as I need it to (albeit with a nasty root-login security hole - unimportant to me as this is going to be a stand-alone box).

>
So I now have :
>
1) a '/home/george/startfs' shell script which contains:
==========
/home/george/fluidsynth -s -i -o midi.autoconnect=1 -m alsa_seq -a alsa -g 1 /home/george/GeneralUser_GS_v1.471.sf2 &
==========
>

>

>
3) root's .profile contains:
==========
>
/home/george/startfs
> sleep 2
> killall fluidsynth
> /home/george/startfs
==========
>

>
Somewhat bizarrely fluidsynth only produces audio via alsa having been started once, killed and restarted, but this approach does now work reliably.
>

>
When I get chance I may investigate using jackd or a different audio connection method, but for now I have what I need - albeit a bit of a nasty hack!!

>
Thanks guys for the help.
Kind regards,
George
((Somerset, UK))

>

>


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem starting Fluidsynth on a headless RPi

fluid-dev mailing list
A few thoughts from my side...

> I have the suspicion that your MIDI keyboard is not yet fully registered as a MIDI device when fluidsynth starts.

This shouldn't matter. As soon as a new MIDI port is made available in
alsa_seq, fluidsynth receives an event about a new port becoming
available and automatically connects to it (provided it's a readable
port). In this case, fluidsynth prints a message to stdout:
"Connection of PORTNAME succeeded"

There is something else you could test: When starting fluidsynth, pass
the -v flag. This will activate synth.verbose causing the synth to
print all incoming messages, like noteons and CCs to stdout. That way
we could be sure that fluidsynth is receiving MIDI messages at all.

If you need some debug logging, you'll need to compile fluidsynth in
Debug mode, e.g. by passing -DCMAKE_BUILD_TYPE=Debug to cmake. (I
think I should make this a runtime option for the next release...)


Tom

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem starting Fluidsynth on a headless RPi

George Poulson
@Tom, thanks for your input.

As I mentioned in my last post to the list I am satisfied that the problem is not connected to MIDI connections. I can see the [automatic] connection confirmation messages and manually disconnecting and re-connecting the midi inputs using aconnect makes no difference to the lack of audio output.

I'm pretty sure that it is audio-path related but I'm no expert on alsa so I'm pretty much 'poking around in the dark' with a problem that may just not exist in a different environment. 

George. 



On Thu, 30 Jan 2020, 05:51 Tom M. via fluid-dev, <[hidden email]> wrote:
A few thoughts from my side...

> I have the suspicion that your MIDI keyboard is not yet fully registered as a MIDI device when fluidsynth starts.

This shouldn't matter. As soon as a new MIDI port is made available in
alsa_seq, fluidsynth receives an event about a new port becoming
available and automatically connects to it (provided it's a readable
port). In this case, fluidsynth prints a message to stdout:
"Connection of PORTNAME succeeded"

There is something else you could test: When starting fluidsynth, pass
the -v flag. This will activate synth.verbose causing the synth to
print all incoming messages, like noteons and CCs to stdout. That way
we could be sure that fluidsynth is receiving MIDI messages at all.

If you need some debug logging, you'll need to compile fluidsynth in
Debug mode, e.g. by passing -DCMAKE_BUILD_TYPE=Debug to cmake. (I
think I should make this a runtime option for the next release...)


Tom

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem starting Fluidsynth on a headless RPi

Marcus Weseloh
Hi George,

just out of curiosity: could you post the output of fluidsynth that got logged to the file when you redirected the stderr and stdout output?

Cheers
Marcus

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev