Issues with starting SCServer + Volume/Distortion on Ubuntu 20.04.2 LTS and ThinkPad X1 Carbon 7th Generation

Hello!

I’m fairly new to SuperCollider, especially on Linux, so please forgive me if there is some documentation on my issue already.

I’ve been having lots of issues with both starting up the SC server and volume/distortion issues that make using SC unreasonable at times.

When I first tried to boot the SC server with the IDE, it would not work, so I went down a path of understanding how jack was meant to be used.

I installed qjackctl and when I tried to start jack with default options, I got the following errors:

18:51:37.243 Statistics reset.
18:51:37.246 ALSA connection change.
18:51:37.249 D-BUS: Service is available (org.jackaudio.service aka jackdbus).
18:51:37.283 JACK connection change.
18:51:37.299 Client activated.
18:51:37.299 Patchbay deactivated.
18:51:47.786 Client deactivated.
18:51:55.355 D-BUS: JACK server could not be started. Sorry
Fri Mar 12 18:51:55 2021: Starting jack server...
Fri Mar 12 18:51:55 2021: JACK server starting in realtime mode with priority 10
Fri Mar 12 18:51:55 2021: self-connect-mode is "Don't restrict self connect requests"
Fri Mar 12 18:51:55 2021: Acquired audio card Audio0
Fri Mar 12 18:51:55 2021: creating alsa driver ... hw:sofhdadsp|hw:sofhdadsp|1024|2|44100|0|0|nomon|swmeter|-|32bit
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Fri Mar 12 18:51:55 2021: configuring for 44100Hz, period = 1024 frames (23.2 ms), buffer = 2 periods
Fri Mar 12 18:51:55 2021: ALSA: final selected sample format for capture: 24bit little-endian
Fri Mar 12 18:51:55 2021: ERROR: ALSA: cannot set period size to 1024 frames for capture
Fri Mar 12 18:51:55 2021: ERROR: ALSA: cannot configure capture channel
Fri Mar 12 18:51:55 2021: Released audio card Audio0
Fri Mar 12 18:51:55 2021: ERROR: Cannot initialize driver
Fri Mar 12 18:51:55 2021: ERROR: JackServer::Open failed with -1
Fri Mar 12 18:51:55 2021: ERROR: Failed to open server
Fri Mar 12 18:51:56 2021: Saving settings to "/home/jo/.config/jack/conf.xml" ...
18:52:07.613 Could not connect to JACK server as client. - Overall operation failed. - Unable to connect to server. Please check the messages window for more info.
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

Trying jack straight from the command line would produce similar errors:

(base) ➜  ~ jackd -d alsa
jackdmp 1.9.12
Copyright 2001-2005 Paul Davis and others.
Copyright 2004-2016 Grame.
Copyright 2016-2017 Filipe Coelho.
jackdmp comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details
no message buffer overruns
no message buffer overruns
no message buffer overruns
JACK server starting in realtime mode with priority 10
self-connect-mode is "Don't restrict self connect requests"
audio_reservation_init
Acquire audio card Audio0
creating alsa driver ... hw:0|hw:0|1024|2|48000|0|0|nomon|swmeter|-|32bit
configuring for 48000Hz, period = 1024 frames (21.3 ms), buffer = 2 periods
ALSA: final selected sample format for capture: 24bit little-endian
ALSA: cannot set period size to 1024 frames for capture
ALSA: cannot configure capture channel
Released audio card Audio0
audio_reservation_finish
Cannot initialize driver
JackServer::Open failed with -1
Failed to open server

It started to look like it was something about setting the period size was the problem:

ALSA: cannot set period size to 1024 frames for capture

After some lucky Googling, I came across this post that said I had to use a period size of 1008 for my audio driver on this machine/OS (I’m on a Thinkpad Carbon X1 (7th gen) running Ubuntu 20.04.2 LTS).

Bug #1872244 “Jack audio not working on Ubuntu 20.04 running on ...” : Bugs : jackd-defaults package : Ubuntu ← last post

That seemed to get qjackctl running which seemed like a win. Now when I boot my server in the SC IDE, I get all green. I started to generate some simple sounds, e.g.

{Pulse.ar([100, 120], 0.5, SinOsc.kr(10, 0, 0.5, 0.5))}.play;

with the volume set at 0.0 db, and it was both excruciatingly loud and also very very distorted. I ended up installing the SafetyNet quark to help with that. Now the issue of volume is solved, but the signal itself still sounds very distorted. If I had to describe it in non-technical, layman’s terms, it sounds like a warping or like an overloaded cycling. If I turned the db level down to -60 db, I can actually hear the signal without this distortion happening.

This has been a decent fix as now I can start playing and experimenting with SC, but I don’t think its a long-term viable solution, especially now when I try to record out from SC with sc.record, the volume is so low you can barely hear anything.

Rarely, if I start jack, then boot the SC server, THEN quit jack (which stops the SC server), and THEN boot the sc server again, the sound works as expected and I can turn the volume up to 0.0 db with no distortion at all. But this doesn’t happen all the time and I’m not sure how best to reproduce it.

Does anyone have any idea what’s going on or what I can do to fix it? I hope I was able to explain my problem well, and if not I’m happy to provide more information. Thank you so much for any help you can provide!

Ah right, the 1008 hardware block size.

The server’s control block size must divide the hardware block size evenly. And the control block size must be a power of two.

Usually the hardware buffer size is also a power of two, in which case, everything is fine because, if m < n and m and n are both integers, then 2^n / 2^m = 2^(n-m) which is always an integer. Ok.

Recent ThinkPads mess that up by forcing the internal soundcard to use a hardware block of 1008 = 16×63 :confounded:

The largest power of two that evenly divides 1008 is 16.

So try setting s.options.blockSize = 16 before starting the server.

It’s quite unfortunate… but, external soundcards should still support standard block sizes though.

hjh

Thank you for your reply! That s.options.blockSize = 16 bit was also mentioned in the forum post I found that clued me into to using a period size of 1008 to start up jack. Unfortunately it didn’t seem to solve my problem when I tried. I can try restarting and being mindful of the order of operations, but simply quitting the server, running that line, and booting it back up again doesn’t seem to solve my volume/distortion issues…

One possible explanation for this is if the sound card’s endianness is wrong. I have never seen this with the internal sound card of any Linux machine I’ve used. I did see this with the mic/line inputs of one USB sound card (but not the outputs) – the distortion was wretched in that case.

Typically (I think) soundcards don’t accept floating-point samples – they expect either 16-bit or 24-bit integer samples. The bytes can be arranged in big endian or little endian order. If a 16-bit integer could be represented as:

0010 0101 0011 1100
FEDC BA98 7654 3210 -- indices

… then big endian would pass the bits in order FEDC BA98 7654 3210, and little endian would do 7654 3210 FEDC BA98.

If the driver and the soundcard disagree, then small changes in signal amplitude (bits 76543210) would be promoted to the most-significant position. That would be a pretty gross form of distortion.

With that one USB soundcard, this would happen maybe 5% of the time (somehow, usually on stage, just before a performance). I never found a solution other than to disconnect and reconnect the USB cable, and hope it would work after that. Obviously that won’t help you with an internal soundcard.

If it happens most of the time with your internal sound card, that would be strange – but it’s also strange for the soundcard to insist on a 1008-sample hardware block.

That’s a long way around to say… I don’t know how to make the hardware behave.

hjh