Cannot find valid sound driver

MOC version: 
2.7-alpha3, r. 2933

I am a long-time user of Music-on-Console, however have just installed it on my new laptop to find that M.O.C. fails to detect the audio driver, failing with the error message "FATAL_ERROR: No valid sound driver!". M.O.C. is the only application with this problem; Firefox, V.L.C., aplay, etc., all work perfectly with my plain A.L.S.A. set-up.

I am somewhat-surprised that M.O.C. has any difficulty detecting the speaker configuration, as it is fairly standard. Below is the output of aplay -L (I want to output to PCH "default"):

null Discard all samples (playback) or generate zero samples (capture) hdmi:CARD=HDMI,DEV=0 HDA Intel HDMI, Generic Digital HDMI Audio Output default:CARD=PCH HDA Intel PCH, ALC283 Analog Default Audio Device sysdefault:CARD=PCH HDA Intel PCH, ALC283 Analog Default Audio Device front:CARD=PCH,DEV=0 HDA Intel PCH, ALC283 Analog Front speakers surround21:CARD=PCH,DEV=0 HDA Intel PCH, ALC283 Analog 2.1 Surround output to Front and Subwoofer speakers surround40:CARD=PCH,DEV=0 HDA Intel PCH, ALC283 Analog 4.0 Surround output to Front and Rear speakers surround41:CARD=PCH,DEV=0 HDA Intel PCH, ALC283 Analog 4.1 Surround output to Front, Rear and Subwoofer speakers surround50:CARD=PCH,DEV=0 HDA Intel PCH, ALC283 Analog 5.0 Surround output to Front, Center and Rear speakers surround51:CARD=PCH,DEV=0 HDA Intel PCH, ALC283 Analog 5.1 Surround output to Front, Center, Rear and Subwoofer speakers surround71:CARD=PCH,DEV=0 HDA Intel PCH, ALC283 Analog 7.1 Surround output to Front, Center, Side, Rear and Woofer speakers

My system is Gentoo x86_64 running kernel 4.19.86. M.O.C. was compiled with A.L.S.A. and F.L.A.C. support. Unfortunately, I cannot get any more verbose output from M.O.C., as running it when compiled with the "debug" flag leads to an instant segmentation fault.

Any help or a point in the right direction would be greatly appreciated; I really don't want to have to move to another music player.

Ashley.

I am somewhat-surprised that M.O.C. has any difficulty detecting the speaker configuration, as it is fairly standard.

So are we.

Unfortunately, I cannot get any more verbose output from M.O.C., as running it when compiled with the "debug" flag leads to an instant segmentation fault.

That is also surprising. It's something we're also going to have to investigate as we may well need it to address your primary problem.

At this stage I'd usually suggest checking that you have all the required ALSA packages installed, but given that other applications are finding it I'm guessing they probably are.

Unfortunately, the Gentoo MOC package maintainer has not responded to us in the past. I will alert another knowledgable Gentoo user to see if he can help.

Although I'm not knowledgeable enough with the code-base of M.O.C. to offer a patch, it seems the segfault is caused by the recursive call to clone_popt_options in main.c. Seems as though the array opts array is overstepped when passed to memcmp. Trace:

Breakpoint 1 at 0x170cd: file main.c, line 696. Starting program: /home/ash/personal/documents/moc-2.6-alpha3/mocp [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Breakpoint 1, clone_popt_options (opts=0x5555555bcaa0 <mocp_opts>) at main.c:696 696 assert (opts); 699 memcmp (&opts[count - 1], &specials[2], sizeof (struct poptOption)); 700 count += 1); #0 clone_popt_options (opts=0x5555555bcaa0 <mocp_opts>) at main.c:700 #1 0x000055555556b61a in render_popt_command_line () at main.c:825 #2 0x0000555555564a4b in log_popt_command_line () at main.c:1168 #3 main (argc=<optimized out>, argv=<optimized out>) at main.c:1224 Continuing. Breakpoint 1, clone_popt_options (opts=0x5555555bd0e0 <general_opts>) at main.c:696 696 assert (opts); 699 memcmp (&opts[count - 1], &specials[2], sizeof (struct poptOption)); #0 clone_popt_options (opts=0x5555555bd0e0 <general_opts>) at main.c:699 #1 0x000055555556b36a in clone_popt_options (opts=<optimized out>) at main.c:720 #2 0x000055555556b61a in render_popt_command_line () at main.c:825 #3 0x0000555555564a4b in log_popt_command_line () at main.c:1168 #4 main (argc=<optimized out>, argv=<optimized out>) at main.c:1224 700 count += 1); 699 memcmp (&opts[count - 1], &specials[2], sizeof (struct poptOption)); 700 count += 1); 699 memcmp (&opts[count - 1], &specials[2], sizeof (struct poptOption)); Continuing. Program received signal SIGSEGV, Segmentation fault. clone_popt_options (opts=0x5555555bd0e0 <general_opts>) at main.c:699 699 memcmp (&opts[count - 1], &specials[2], sizeof (struct poptOption));

I think this one is fixed in r2948 (also see Debian Bug#855125).

You mention offering a patch which makes me think you have the knowledge to apply that commit as a one-off patch and see if it helps. Contact mocmaint by e-mail if you can't get the patch from SVN.

Applying the patch https://github.com/jonsafari/mocp/commit/156d79d80887a91aeb034e050197a953b3fe931a.diff to the current Gentoo/Portage release of M.O.C. does fix the segfault --- I'll commit this in a bit when I have a some time. Thanks for your help thus far.

Unfortunately, the original issue still remains.
Ashley.

I'm using MOC on Gentoo with plain ALSA setup on multiple machines. Now that you solved the segfault you could post more debug info about problem with ALSA - maybe the problem is just related to .asoundrc file or ALSADevice option in .moc/config? You can also look at http://moc.daper.net/node/2648 where problems with device names are discussed.

Also, if you managed to apply the patch, consider switching to current SVN code as it contains many fixes which didn't make it into released versions. Myself, I run my custom branch of MOC with many experimental changes, some of them related to ALSA. I don't think that they are relevant though, but you are free to try it if you feel adventurous: https://gitlab.com/tomaszg/mocp.

BTW. You can get some basic "debug" output even without debug USE flag just by running moc via "mocp -SF"

I just cloned your GitLab repo and compiled it from source (I already had all the dependencies from emerge resolving them previously for the "official" Gentoo M.O.C.). It all works perfectly, as expected, meaning the version in the Gentoo repo is at fault here. I suppose this stops being a M.O.C. issue and becomes more of a Gentoo issue.

Ashley.

It would be good if you would clone and check also official MOC repo and see if it also resolves your problem. Maybe Gentoo just needs a new MOC snapshot in portage.

Another possibility that comes to my mind is related to Allow24bitOutput MOC option which defaults to "no" for some obscure reason. Maybe your card just needs 24 bit mode to work. My code changed defaults in that respect.

I cloned the official M.O.C. repo and it didn't work. Passing Allow24bitOutput=yes makes it work fine though; thanks a lot for your help, seems as though your change was the fix. I've seen a lot of people on other forums complaining about the same error I had initially... maybe the Allow24bitOutput should be enabled by default in the *official* tree ? Seems weird not to, is there any reason to have it disabled by default ?

I don't know of any reason, I think it is old code and there was no good reason to change it, so conservative approach kept it the way it is.

Do you have any special soundcard, like USB DAC or something like that?

Nothing particularly non-standard: Realtek ALC283.

Oh, apparently Allow24bitOutput was causing some issues with certain sound cards (see the NEWS file for version 2.4.2).

Yeah, some undefined problem back in 2007 :) Well, I think that at least official version should have more verbose error reporting.

I still find it curious that your soundcard fails to work in 16-bit (or 8-bit) mode. From what I was able to understand about ALSA, it does its own mixing and resampling via "dmix", so it should by default accept a wide range of audio formats unless you explicitly ask to bypass it by using one of "hw:something" devices. Could you post part of "mocp -SF" identifying card capabilities? On my system it reports:

gru 7 14:37:36.913850: alsa.c:550 alsa_init(): Initialising ALSA device: default gru 7 14:37:36.914847: alsa.c:443 alsa_init_mixer_channel(): Opened mixer (PCM), perceptive volume range: -5100-0dB, min_norm: 0,141254 gru 7 14:37:36.914868: alsa.c:443 alsa_init_mixer_channel(): Opened mixer (Master), perceptive volume range: -6400-0dB, min_norm: 0,085770 gru 7 14:37:36.917246: audio.c:1068 print_output_capabilities(): Sound driver capabilities: channels 1 - 10000, sample rate 48000 - 48000, formats: 8-bit signed, 8-bit unsigned, 16-bit signed, 16-bit unsigned, 24-bit signed (as 32-bit samples), 24-bit unsigned (as 32-bit samples), 24-bit signed (in 3bytes format), 24-bit unsigned (in 3bytes format), 32-bit signed, 32-bit unsigned little-endian (native)

Or maybe you have something weird in your .asoundrc?

Output from mocp -SF below. Seems as though it is having some issues opening the P.C.M. and Master mixers.

main.c:1202 main(): This is Music On Console (version 2.6-alpha3) main.c:1206 main(): Configured: main.c:1216 main(): Running on: Linux 4.19.82-gentoo x86_64 main.c:1168 log_command_line(): mocp -SF main.c:1182 log_popt_command_line(): mocp --server --foreground decoder.c:700 load_plugins(): Loaded 2 decoders: ffmpeg flac server.c:361 server_init(): Starting MOC Server log.c:233 log_init_stream(): Writing log to: stdout server.c:301 log_process_stack_size(): Process's stack size: 8388608 server.c:318 log_pthread_stack_size(): PThread's stack size: 8388608 alsa.c:550 alsa_init(): Initialising ALSA device: default alsa.c:430 alsa_init_mixer_channel(): ERROR: Can't find mixer PCM server.c:677 add_event_all(): No events have been added because there are no clients alsa.c:430 alsa_init_mixer_channel(): ERROR: Can't find mixer Master server.c:677 add_event_all(): No events have been added because there are no clients audio.c:1068 print_output_capabilities(): Sound driver capabilities: channels 1 - 10000, sample rate 48000 - 48000, formats: 8-bit signed, 8-bit unsigned, 16-bit signed, 16-bit unsigned, 24-bit signed (as 32-bit samples), 24-bit unsigned (as 32-bit samples), 24-bit signed (in 3bytes format), 24-bit unsigned (in 3bytes format), 32-bit signed, 32-bit unsigned little-endian (native) out_buf.c:103 read_thread(): entering output buffer thread softmixer.c:60 softmixer_init(): Softmixer initialized equalizer.c:511 equalizer_init(): Equalizer initialized tags_cache.c:695 reader_thread(): Tags reader thread started tags_cache.c:720 reader_thread(): All queues empty, waiting server.c:436 server_init(): Running OnServerStart server.c:1810 server_loop(): MOC server started, pid: 5670

/etc/asound.conf

defaults.pcm.card 1 defaults.pcm.device 0

Ashley.

Mighty weird. Nothing suspicious here. Maybe the problem is rather related to lack of a mixer channel which would make it related to this commit. Not sure why Allow24bitOutput would fix it in official MOC.

I'm not entirely sure why the mixer isn't available ? It is able to play audio, and other applications, such as alsamixer, seem to have no issues.

Ashley.

Maybe just the name of mixer channel is different. Does "amixer" show channels like "Master" and "PCM"?

Yeah, 'PCM', 'Master', 'Headphone', etc., etc.
Everything you'd expect

Simple mixer control 'Master',0 Capabilities: pvolume pvolume-joined pswitch pswitch-joined Playback channels: Mono Limits: Playback 0 - 87 Mono: Playback 50 [57%] [-27.75dB] [on] Simple mixer control 'Headphone',0 Capabilities: pvolume pswitch Playback channels: Front Left - Front Right Limits: Playback 0 - 87 Mono: Front Left: Playback 87 [100%] [0.00dB] [on] Front Right: Playback 87 [100%] [0.00dB] [on] Simple mixer control 'Speaker',0 Capabilities: pvolume pswitch Playback channels: Front Left - Front Right Limits: Playback 0 - 87 Mono: Front Left: Playback 87 [100%] [0.00dB] [on] Front Right: Playback 87 [100%] [0.00dB] [on] Simple mixer control 'PCM',0 Capabilities: pvolume Playback channels: Front Left - Front Right Limits: Playback 0 - 255 Mono: Front Left: Playback 255 [100%] [0.00dB] Front Right: Playback 255 [100%] [0.00dB] Simple mixer control 'Mic',0 Capabilities: pvolume pswitch Playback channels: Front Left - Front Right Limits: Playback 0 - 31 Mono: Front Left: Playback 0 [0%] [-34.50dB] [off] Front Right: Playback 0 [0%] [-34.50dB] [off] Simple mixer control 'Mic Boost',0 Capabilities: volume Playback channels: Front Left - Front Right Capture channels: Front Left - Front Right Limits: 0 - 3 Front Left: 0 [0%] [0.00dB] Front Right: 0 [0%] [0.00dB] Simple mixer control 'Capture',0 Capabilities: cvolume cswitch Capture channels: Front Left - Front Right Limits: Capture 0 - 63 Front Left: Capture 39 [62%] [12.00dB] [on] Front Right: Capture 39 [62%] [12.00dB] [on] Simple mixer control 'Auto-Mute Mode',0 Capabilities: enum Items: 'Disabled' 'Enabled' Item0: 'Enabled' Simple mixer control 'Internal Mic Boost',0 Capabilities: volume Playback channels: Front Left - Front Right Capture channels: Front Left - Front Right Limits: 0 - 3 Front Left: 0 [0%] [0.00dB] Front Right: 0 [0%] [0.00dB] Simple mixer control 'Loopback Mixing',0 Capabilities: enum Items: 'Disabled' 'Enabled' Item0: 'Disabled'

Seems that it is something jcf needs to look into and maybe pull some patches from my branch :)

I'm not entirely sure why the mixer isn't available?

A recent problem gave me a clue, but fixing (and therefore confirming) it may require a non-trival reorganisation of MOC's ALSA sound driver with the potential to introduce more problems than bogus error message in a place few people look. That error message is part of a bigger picture.

... is there any reason to have it [the 'Allow24bitOutput' option] disabled by default?

The reason is a very good one: changing the default value may end up silently breaking MOC on more systems (where 24-bit is not supported) than it fixes. We just don't know how many that would be and therefore the safer approach is not to monkey with options which are more than merely user preferences.

However, I have now come up with a possible solution which we can check out.

I wonder if M.O.C. could automatically query the sound card's capabilities to determine which option would be best ? Just a thought--- I might familiarise myself with the M.O.C. code-base over xmas when I have some time. I suppose it wholly depends on the quality of the A.L.S.A. A.P.I., which, I must confess, I know next-to-nothing nothing about.

MOC does just that. The lines from the log you posted show what was the result. Since apparently ALSA reported that it can work with 16-bit samples, it is difficult to guess what is the problem. It would be interesting to check in debug log what sound format was really chosen to play the audio. And compare that with results of official MOC code to see where the difference is.

Having now looked at the appropriate portions of the code, it is obvious that something doesn't add up with what we have so far.

Could you please checkout a copy of the current HEAD (available from SVN or Git). Build and run it with the '-D -O "Allow24bitOutput=no"' command line options and, if it fails, post the mocp_server_log messages leading up to the failure. Then try that again with the options '-D -O "Allow24bitOutput=yes"' and report that result.

The current HEAD from the Git works in neither situation.
Disallowing 24-bit:

Dec 7 21:01:42.422603: main.c:1191 main(): This is Music On Console (version 2.6-alpha3) Dec 7 21:01:42.422639: main.c:1195 main(): Configured: '--without-ffmpeg' '--without-oss' '--without-curl' '--without-samplerate' '--without-magic' Dec 7 21:01:42.422644: main.c:1205 main(): Running on: Linux 4.19.82-gentoo x86_64 Dec 7 21:01:42.422734: main.c:1157 log_command_line(): ./mocp --no-config -D -O Allow24bitOutput=no Dec 7 21:01:42.422778: main.c:1171 log_popt_command_line(): ./mocp --no-config --debug --set-option='Allow24bitOutput=no' Dec 7 21:01:42.424181: decoder.c:700 load_plugins(): Loaded 2 decoders: ffmpeg/libav flac Dec 7 21:01:42.424460: server.c:360 server_init(): Starting MOC Server Dec 7 21:01:42.424579: log.c:233 log_init_stream(): Writing log to: mocp_server_log Dec 7 21:01:42.424644: server.c:300 log_process_stack_size(): Process's stack size: 8388608 Dec 7 21:01:42.424651: server.c:317 log_pthread_stack_size(): PThread's stack size: 8388608 Dec 7 21:01:42.424662: alsa.c:477 alsa_init(): Initialising ALSA device: default Dec 7 21:01:42.425178: alsa.c:365 alsa_init_mixer_channel(): ERROR: Can't find mixer PCM Dec 7 21:01:42.425185: server.c:672 add_event_all(): No events have been added because there are no clients Dec 7 21:01:42.425189: alsa.c:365 alsa_init_mixer_channel(): ERROR: Can't find mixer Master Dec 7 21:01:42.425192: server.c:672 add_event_all(): No events have been added because there are no clients Dec 7 21:01:42.425209: audio.c:926 find_working_driver(): FATAL ERROR: No valid sound driver!

And allowing 24-bit:

Dec 7 21:01:42.422603: main.c:1191 main(): This is Music On Console (version 2.6-alpha3) Dec 7 21:01:42.422639: main.c:1195 main(): Configured: '--without-ffmpeg' '--without-oss' '--without-curl' '--without-samplerate' '--without-magic' Dec 7 21:01:42.422644: main.c:1205 main(): Running on: Linux 4.19.82-gentoo x86_64 Dec 7 21:01:42.422734: main.c:1157 log_command_line(): ./mocp --no-config -D -O Allow24bitOutput=no Dec 7 21:01:42.422778: main.c:1171 log_popt_command_line(): ./mocp --no-config --debug --set-option='Allow24bitOutput=no' Dec 7 21:01:42.424181: decoder.c:700 load_plugins(): Loaded 2 decoders: ffmpeg/libav flac Dec 7 21:01:42.424460: server.c:360 server_init(): Starting MOC Server Dec 7 21:01:42.424579: log.c:233 log_init_stream(): Writing log to: mocp_server_log Dec 7 21:01:42.424644: server.c:300 log_process_stack_size(): Process's stack size: 8388608 Dec 7 21:01:42.424651: server.c:317 log_pthread_stack_size(): PThread's stack size: 8388608 Dec 7 21:01:42.424662: alsa.c:477 alsa_init(): Initialising ALSA device: default Dec 7 21:01:42.425178: alsa.c:365 alsa_init_mixer_channel(): ERROR: Can't find mixer PCM Dec 7 21:01:42.425185: server.c:672 add_event_all(): No events have been added because there are no clients Dec 7 21:01:42.425189: alsa.c:365 alsa_init_mixer_channel(): ERROR: Can't find mixer Master Dec 7 21:01:42.425192: server.c:672 add_event_all(): No events have been added because there are no clients Dec 7 21:01:42.425209: audio.c:926 find_working_driver(): FATAL ERROR: No valid sound driver!

Sorry, the below is the correct log when allowing 24-bit output.

Dec 7 21:01:56.680967: main.c:1191 main(): This is Music On Console (version 2.6-alpha3) Dec 7 21:01:56.681054: main.c:1195 main(): Configured: '--without-ffmpeg' '--without-oss' '--without-curl' '--without-samplerate' '--without-magic' Dec 7 21:01:56.681072: main.c:1205 main(): Running on: Linux 4.19.82-gentoo x86_64 Dec 7 21:01:56.681340: main.c:1157 log_command_line(): ./mocp --no-config -D -O Allow24bitOutput=yes Dec 7 21:01:56.681483: main.c:1171 log_popt_command_line(): ./mocp --no-config --debug --set-option='Allow24bitOutput=yes' Dec 7 21:01:56.683071: decoder.c:700 load_plugins(): Loaded 2 decoders: ffmpeg/libav flac Dec 7 21:01:56.683302: server.c:360 server_init(): Starting MOC Server Dec 7 21:01:56.683449: log.c:233 log_init_stream(): Writing log to: mocp_server_log Dec 7 21:01:56.683525: server.c:300 log_process_stack_size(): Process's stack size: 8388608 Dec 7 21:01:56.683534: server.c:317 log_pthread_stack_size(): PThread's stack size: 8388608 Dec 7 21:01:56.683546: alsa.c:477 alsa_init(): Initialising ALSA device: default Dec 7 21:01:56.684155: alsa.c:365 alsa_init_mixer_channel(): ERROR: Can't find mixer PCM Dec 7 21:01:56.684164: server.c:672 add_event_all(): No events have been added because there are no clients Dec 7 21:01:56.684169: alsa.c:365 alsa_init_mixer_channel(): ERROR: Can't find mixer Master Dec 7 21:01:56.684172: server.c:672 add_event_all(): No events have been added because there are no clients Dec 7 21:01:56.684190: audio.c:926 find_working_driver(): FATAL ERROR: No valid sound driver!

Ah, now it makes sense. I don't know why it can't open mixer channel but my guess is that you need something like

defaults.ctl.card 1

in your .asoundrc. MOC was probably trying to access mixer on a different card, which was HDMI and didn't probably have volume control.

I still however believe that it is a bug in MOC as MOC should work even when no mixer controls are available. This behaviour was changed in my fork and that's the reason that you got it to work.

I wonder if MOC should also try somehow to access correct mixer channels on other card, maybe something is wrong in alsa.c. I don't know if ALSA API allows for that though.

Yes, adding defaults.ctl.card 1 to the asound file seems to fix it.
From what I remember (and this is from many years ago), the official M.O.C. used to allow you to open it without available mixer controls, did it not ? Or maybe I'm just imagining things...