Raising ALSA cards_limit

Hi there, I am using your wonderful Patchbox OS to do MIDI routing.
I have some mididings scripts, but mainly just using the included “Patchage” app is great for my needs.

As my studio is growing, I hit the default ALSA cards_limit of 8 (I think).

In /var/log/syslog, this looks like this:

Nov 24 10:48:54 patchbox kernel: [96241.011034] usb 1-1.2.2.1.4: Product: Launch Control XL
Nov 24 10:48:54 patchbox kernel: [96241.011039] usb 1-1.2.2.1.4: Manufacturer: Focusrite A.E. Ltd
Nov 24 10:48:54 patchbox kernel: [96241.013601] snd-usb-audio 1-1.2.2.1.4:1.0: cannot find the slot for index -1 (range 0-7), error: -19
Nov 24 10:48:54 patchbox kernel: [96241.013624] usb 1-1.2.2.1.4: cannot create card instance 7

I see that my USB MIDI devices are all using snd-usb-audio. I could not find a cards_limit or similar driver options for that (modinfo -p snd-usb-audio) so I guess I would have to configure ALSA itself.

cat /sys/module/snd/parameters/cards_limit is 1 - which I do not understand as 7 USB MIDI devices (2 of which are also audio devices) have been loaded successfully.

From https://alsa.opensrc.org/MultipleCards I tried to add a /etc/modprobe.d/alsa.conf with

options snd cards_limit=16

But that would not change anything (/sys/module/snd/parameters/cards_limit is 16, though). I suspect it does not apply to snd-usb-audio devices?

Any pointers are appreciated!

According to this: https://www.raspberrypi.org/forums/viewtopic.php?t=177458 the number seems to be hardcoded at compile time. Patchbox OS has a custom ‘realtime’ kernel built for it, but we haven’t changed these options, we’ll include higher limits in the next release of Patchbox OS.

See this article for information on how to build the RPi kernel manually: https://www.raspberrypi.org/documentation/linux/kernel/building.md

The kernel building scripts we used for Patchbox OS are here: https://github.com/BlokasLabs/rpi-kernel-rt, if you want to run it, you may want to edit build.sh to change rpi-4.19.y-rt to rpi-4.14.y-rt, as 4.19 RT kernel does not boot with older RPi versions that RPi4, as well as commenting out the last build_kernel line that’s meant to build the kernel for RPi4.

However, editing the config before building may be tricky if using the build.sh script, it would be easier to follow the steps manually.

Let us know if you manage to resolve the issue and how you did it. :slight_smile:

2 Likes

Thank you very much for your insight and for raising it in future versions! I’ll try to compile another Kernel tonight.

Btw, regarding my modprobe change from above: that was the wrong way, as each subdriver seems to be a “card”. My change also yields a Kernel panic on shutdown.

Thank you! That worked and problem solved :slight_smile:
:musical_keyboard: :musical_keyboard: :musical_note: :dancer:

Very helpful and easy to follow compiling manual, by the way!

1 Like

By the way, could you share the config changes you did so we can replicate it easily? :slight_smile:

Sure :slight_smile:

I followed https://www.raspberrypi.org/documentation/linux/kernel/building.md (Local building on the Raspberry). I followed your advice using --branch rpi-4.14.y at the git clone command for my Pi 3 (maybe Pi 3+, I am not sure).

When it comes to configuring the Kernel I had a peek at https://www.raspberrypi.org/documentation/linux/kernel/configuring.md but did not use the menu system but edited the .config file directly.

I set

CONFIG_SND_DYNAMIC_MINORS=y 
CONFIG_SND_MAX_CARDS=16

there and continued further in the building manual (the make ..._defconfig step, then make ..., sudo make module-install, sudo cp...). Backing up the /boot/ directory before might be a good idea but I was too eager to try it out and just went ahead :slight_smile:

What am I doing with the Raspberry / Patchbox OS?
I then happily connected 12 ALSA devices. My studio shall let me make music without any other computer. I connect a laptop to record the music from my 12 channel USB-mixer/interface just for recording.

The Raspberry is purely for MIDI routing.

I use JACK (quite uncommon) in a networked configuration. When it cannot reach the master laptop, it still is a jack MIDI router. I use the simple app Patchage to make connections and some mididings scripts for filtering/translating of MIDI events. When it (automatically) connects to the laptop’s JACK, I can route MIDI through the network to and from the laptop. The 2 devices are connected via LAN of course. ping is 0.5ms (min 0.3, max 0.8) and I am fine with the overall latency/jitter which is not noticable. The main latency in my setup is from the sound interface which runs at 48k/256/3.

I would like to have Pianoteq running on the Raspberry, but its just not powerful enough for sampling rates above 12k. I am thinking about an upgrade or a Pisound if that would run Pianoteq at 48k.

1 Like

Thank you!

Pianoteq does run better via the I²S based audio cards, compared to USB ones, the default config for it in Patchbox OS image uses 48kHz rate for Jack audio, and 24kHz for the Engine rate. It might be able to run a little better on RPi4.

1 Like

I just reinstalled Patchbox OS (v2020-03-14) and I encountered the same old limit of 8 cards.

Is there anything I can do to help get that change into the next release of the OS?

CONFIG_SND_DYNAMIC_MINORS=y 
CONFIG_SND_MAX_CARDS=16

Hey, that’s odd, I thought we already added that in our config: https://github.com/BlokasLabs/rpi-linux-rt/commit/1c96b7e1ff4453d2505603dbb70cb70657fd2970

What is the output of uname -a?

1 Like

It is

Linux patchbox 4.19.71-rt24-v7+ #1 SMP PREEMPT RT Wed Mar 11 16:54:08 EET 2020 armv7l GNU/Linux`

Try updating the system:

sudo apt update && sudo apt upgrade

I have tried creating 12 dummy sound cards, and it succeeded, showing the card limit is definitely above 8. The same doesn’t work on regular Raspberry Pi kernel, as expected.

1 Like

Thank you!
That snd_dummy test went fine for me, too.
I am sorry I only tried connecting all devices after updating. It worked without problems. I guess the problem I had was unrelated.
amidi -l lists all devices now.

Sorry to resurrect this old thread. Using the current release (2020-11-23) with the stock kernel results in the 7 USB audio/midi device limit.

When running the realtime kernel, I’m running into the issue of no USB devices showing up, as described here (I am using a Raspberry Pi 4, 4GB).

It seems like I have two options, neither of which are particularly appealing:

  1. recompile a kernel with the appropriate config to increase the USB audio device limit
  2. include a boot option that tricks the Pi into thinking it has 3GB of RAM

If somebody has found another way to solve this problem, I’m all ears.

This is quite straightforward, I do it all the time. :slightly_smiling_face:, just follow this guide: Raspberry Pi Documentation - The Linux kernel

Modify your config after having run make bcm2711_defconfig command.

1 Like