Raising ALSA cards_limit

#1

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!

0 Likes

#2

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:

1 Like

#3

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.

0 Likes

#4

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

#5

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

0 Likes

#6

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

#7

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