Resolved JACK issues on notebook

Finally got around troubleshooting the issues I was facing with JACK on my notebook, a BTO that is actually a Clevo W170ER. Somehow I couldn’t go lower than -p128 with USB audio interfaces. When I thought I had tried every option, even disabling hyperthreading, I noticed two unidentified entries in my lsusb output:

Bus 001 Device 003: ID 8087:07da Intel Corp. 
Bus 002 Device 003: ID 5986:0401 Acer, Inc

The first entry is a Bluetooth adapter and the second entry is a webcam. Both devices are unnecessary when making music so I thought, why not unbind them. First I had to figure out their respective bus ID’s:

$ tree /sys/bus/usb/drivers/usb
/sys/bus/usb/drivers/usb
??? 1-1 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1
??? 1-1.3 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.3
??? 2-1 -> ../../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1
??? 2-1.6 -> ../../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.6
??? bind
??? uevent
??? unbind
??? usb1 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1
??? usb2 -> ../../../../devices/pci0000:00/0000:00:1d.0/usb2
??? usb3 -> ../../../../devices/pci0000:00/0000:00:14.0/usb3
??? usb4 -> ../../../../devices/pci0000:00/0000:00:14.0/usb4

Since the Bluetooth adapter sits on bus 1 and the webcam on bus two their respective ID’s should be 1-1 and 2-1. So I echoed the ID’s to the unbind file in the same directory:

$ echo -n "1-1" | sudo tee /sys/bus/usb/drivers/usb/unbind
$ echo -n "2-1" | sudo tee /sys/bus/usb/drivers/usb/unbind

Good riddance:

$ lsusb
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Then I started JACK again with -p64 using an USB audio interface connected to bus 3 (so no rate matching hub in between) and no more xruns, not even with a generic kernel and using WiFi and all. Next hurdle is the onboard sound. Below -p128 I get bursts of massive xruns and so far I didn’t manage to pinpoint the culprit.

Edit #1: I’ve found out that the Bluetooth adapter is the main bottleneck. Also, by echoing the aformentioned ID’s (1-1 and 2-1) you disable the whole USB bus apparently. To disable just the USB device echo the last ID in the respective path names, so for the Bluetooth adapter that’s 1-1.3 and for the webcam 2-1.6. This way you can still use the USB bus on which these devices are residing. In my case disabling the whole bus is not an option, this would mean I’d have to connect all my USB interfaces to bus 3 (bus 4 doesn’t have any external inputs) which could result in these devices getting in each other’s way with regard to bandwidth. After echoing the ID’s the output of the tree command looks like this:

$ tree /sys/bus/usb/drivers/usb
/sys/bus/usb/drivers/usb
??? 1-1 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1/1-1
??? 2-1 -> ../../../../devices/pci0000:00/0000:00:1d.0/usb2/2-1
??? bind
??? uevent
??? unbind
??? usb1 -> ../../../../devices/pci0000:00/0000:00:1a.0/usb1
??? usb2 -> ../../../../devices/pci0000:00/0000:00:1d.0/usb2
??? usb3 -> ../../../../devices/pci0000:00/0000:00:14.0/usb3
??? usb4 -> ../../../../devices/pci0000:00/0000:00:14.0/usb4

The lsusb command still shows the devices though.

Edit #2: unbinding drivers like described above won’t persist across reboots. If you’d like to make the unbinding persistent you could add the unbind command to /etc/rc.local or create a script that runs at login. There are other options of course like blacklisting the Bluetooth drivers.

Resolved JACK issues on notebook

Using a Raspberry Pi as a piano

Recently I posted about my successful attempt to get LinuxSampler running on the Raspberry Pi. I’ve taken this a bit further and produced a script that turns the Raspberry Pi into a fully fledged piano. Don’t expect miracles, the sample library I used is good quality so the RPi might choke on it every now and then with regard to disk IO. But it’s usable if you don’t play too many notes at once or make extensive use of a sustain pedal. I’ve tested the script with a Class 4 SD though so a faster SD card could improve stability.

Edit: finally got around buying a better SD card and the difference is huge! I bought a SanDisk Extreme Class 10 SD card and with this SD card I can run LinuxSampler at lower latencies and I can play more notes at once.

Before you can run the script on your Raspberry Pi you will need to tweak your Raspbian installation so you can do low latency audio. How to achieve this is all described in the Raspberry Pi wiki article I’ve put up on wiki.linuxaudio.org. After you’ve set up your RPi you will need to install JACK and LinuxSampler with sudo apt-get install jackd1 linuxsampler. Next step is to get the Salamander Grand Piano sample pack on your RPi:

cd
mkdir LinuxSampler
cd LinuxSampler
wget -c http://download.linuxaudio.org/lau/SalamanderGrandPianoV2
/SalamanderGrandPianoV2_44.1khz16bit.tar.bz2
wget -c http://dl.dropbox.com/u/16547648/sgp44.1khz_V2toV3.tar.bz2
tar jxvf SalamanderGrandPianoV2/SalamanderGrandPianoV2_44.1khz16bit.tar.bz2
tar jxvf sgp44.1khz_V2toV3.tar.bz2 -C SalamanderGrandPianoV2_44.1khz16bit
--strip-components=1

Please note that decompressing the tarballs on the RPi could take some time. Now that you’ve set up the Salamander Grand Piano sample library you can download the script and the LinuxSampler config file:

cd
mkdir bin
wget -c https://raw.github.com/AutoStatic/scripts/rpi/piano -O /home/pi/bin/piano
chmod +x bin/piano
wget -c https://raw.github.com/AutoStatic/configs/rpi/home/pi/LinuxSampler
/SalamanderGrandPianoV3.lscp -O
/home/pi/LinuxSampler/SalamanderGrandPianoV3.lscp

Almost there. We’ve installed the necessary software and downloaded the sample library, LinuxSampler config and piano script. Now we need to dot the i’s and cross the t’s because the script assumes some defaults that might be different in your setup. Let’s dissect the script:

#!/bin/bash

if ! pidof jackd &> /dev/null
then
  sudo killall ifplugd &> /dev/null
  sudo killall dhclient-bin &> /dev/null
  sudo service ntp stop &> /dev/null
  sudo service triggerhappy stop &> /dev/null
  sudo service ifplugd stop &> /dev/null
  sudo service dbus stop &> /dev/null
  sudo killall console-kit-daemon &> /dev/null
  sudo killall polkitd &> /dev/null
  killall gvfsd &> /dev/null
  killall dbus-daemon &> /dev/null
  killall dbus-launch &> /dev/null
  sudo mount -o remount,size=128M /dev/shm &> /dev/null
  echo -n performance
| sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor &> /dev/null
  if ip addr | grep wlan &> /dev/null
  then
    echo -n "1-1.1:1.0" | sudo tee /sys/bus/usb/drivers/smsc95xx/unbind &> /dev/null
  fi
  jackd -P84 -p128 -t2000 -d alsa -dhw:UA25 -p512 -n2 -r44100 -s -P -Xseq
&> /dev/null &
fi

This is the first section of the script. An if clause that checks if JACK is already running and if that’s not the case the system gets set up for low latency use, a simple check is done if there is an active WiFi adapter and if so the ethernet interface is disabled and then on the last line JACK is invoked. Notice the ALSA name used, hw:UA25, this could be different on your RPi, you can check with aplay -l.

jack_wait -w &> /dev/null

jack_wait is a simple app that does nothing else but checking if JACK is active, the -w option means to wait for JACK to become active.

if ! pidof linuxsampler &> /dev/null
then
  linuxsampler --instruments-db-location $HOME/LinuxSampler/instruments.db
&> /dev/null &
  sleep 5
netcat -q 3 localhost 8888
< $HOME/LinuxSampler/SalamanderGrandPianoV3.lscp &> /dev/null &
fi

This stanza checks if LinuxSampler is running, if not LinuxSampler is started and 5 seconds later the config file is pushed to the LinuxSampler backend with the help of netcat.

while [ "$STATUS" != "100" ]
do
  STATUS=$(echo "GET CHANNEL INFO 0" | netcat -q 3 localhost 8888
| grep INSTRUMENT_STATUS | cut -d " " -f 2 | tr -d 'rn')
done

A simple while loop that checks the load status of LinuxSampler. When the load status has reached 100% the script will move on.

jack_connect LinuxSampler:0 system:playback_1 &> /dev/null
jack_connect LinuxSampler:1 system:playback_2 &> /dev/null
#jack_connect alsa_pcm:MPK-mini/midi_capture_1 LinuxSampler:midi_in_0 &> /dev/null
jack_connect alsa_pcm:USB-Keystation-61es/midi_capture_1 LinuxSampler:midi_in_0
&> /dev/null

This part sets up the necessary JACK connections. The portnames of the MIDI devices can be different on your system, you can look them up with jack_lsp which will list all available JACK ports.

jack_midiseq Sequencer 176400 0 69 20000 22050 57 20000 44100 64 20000 66150 67 20000 &
sleep 4
jack_connect Sequencer:out LinuxSampler:midi_in_0
sleep 3.5
jack_disconnect Sequencer:out LinuxSampler:midi_in_0
killall jack_midiseq

This is the notification part of the script that will play four notes. It’s based on jack_midiseq, another JACK example tool that does nothing more but looping a sequence of notes. It’s an undocumented utility so I’ll explain how it is invoked:

jack_midiseq

<command> <JACK port name> <loop length> <start value> <MIDI note value> <length value>

Example:
jack_midiseq Sequencer 176400 0 69 20000 22050 57 20000 44100 64 20000 66150 67 20000

JACK port name: Sequencer
Loop length: 4 seconds at 44.1 KHz (176400/44100)
Start value of first note: 0
MIDI note value of first note: 69 (A4)
Length value: 20000 samples, so that's almost half a second
Start value of second note: 22050 (so half a second after the first note)
MIDI note value of second note: 57 (A3)
Length value: 20000 samples
Start value of third note: 44100 (so a second after the first note)
MIDI note value of second note: 64 (E4)
Length value: 20000 samples
Start value of third note: 66150 (so one second and a half after the first note)
MIDI note value of second note: 67 (G4)
Length value: 20000 samples

Now the script is finished, the last line calls exit with a status value of 0 which means the script was run successfully.

exit 0

After making the script executable with chmod +x ~/bin/piano and running it you can start playing piano with your Raspberry Pi! Again, bear in mind that the RPi is not made for this specific purpose so it could happen that audio starts to stutter every now and then, especially when you play busy parts or play more than 4 notes at once.


Using a Raspberry Pi as a piano: quick demo

Using a Raspberry Pi as a piano

Bricking the UG802 Android TV stick

Pulled out my soldering iron, soldered a reset button and a switch to boot into recovery on the PCB and connected my UG802 clone/revision to my TV. Nothing. lsusb. Crap, it boots in flash mode. Let’s try reflashing the whole bloody thing. Well that works so the NAND is not defective or anything. Reboot. Nothing, lsusb still reports the device is in flash mode. So I removed all my soldering efforts which I really regretted because it was quite nicely done given my poor soldering skills and tried again. Still nothing. Arrrggghhhh. Enjoyed a cold Warsteiner and let it rest.

Today I brought the device with me to the office. Hooked it up to a Windows machine, ran the ROM flash tool from Finless’ custom ROM package for this device and powered it up. I was greeted with the most ugly Android boot animation I had ever seen. But at least the device works again so thanks Finless!

So now I can move on again. I had Jack1 running on it so it should be possible to turn this device into a very cheap, yet powerful alternative to do real-time, low-latency audio. Compared to the Raspberry Pi JACK already consumed way less CPU (12% on the RPi compared to 2% on the RK3066 device with the same JACK settings) and I noticed the device has some more IRQ’s so if I could get all of those threaded that should give me some more flexibility to get everything working in a more stable way. I did have to disable WiFi otherwise the whole USB stack crashed after starting JACK. Also tried with an external WiFi dongle, same issue. I can even generate xruns when pressing keys on an attached keyboard. So it’d be really nice if I had serial console access to this thing. But I’ll figure that out too. And maybe the USB part of the kernel can be tweaked to improve things on the USB level.

Bricking the UG802 Android TV stick

Raspberry Pi als virtuele gitaarversterker

M’n Raspberry Pi in actie als virtuele gitaarversterker. Er draait Raspbian op met een gepatchte versie van Jack1 en de laatste versie van guitarix. Als geluidskaart gebruik ik m’n good old Edirol UA-25. Systeemlatency is 256/48000×3 = 16ms. Ik kan nog wat lager (8ms) maar dan trekt de RPi de preset die ik in dit videootje gebruik niet meer.

De gepatchte versie van Jack1 en de laatste versie van guitarix kun je in mijn RPi audio repository vinden. Staan ook nog wat andere pakketjes in die of nog niet beschikbaar zijn in de standaard repositories van Raspbian of die wat meer up to date zijn dan de  Raspbian pakketten. Hoe je die repository kunt toevoegen kun je terugvinden in mijn Wiki artikel Raspberry Pi and real-time, low-latency audio op linuxaudio.org.

Ben erachter gekomen dat ik niet de enige ben die hier mee bezig is, er is zelfs iemand die er een complete site aan het wijden is: Amp Brownie – Building a Raspberry Pi Guitar Rig

Raspberry Pi als virtuele gitaarversterker

Als je het over de duivel hebt…

Trap je ‘m op zijn staart! Vandaag is er dus een nieuwe release beschikbaar van Qtractor, 0.4.3 oftewel Fussy Doula. Zit ik moeilijk te doen met pakketjes te fabrieken voor versie 0.4.2 met checkinstall, heeft de goede man gewoon de hele rambam al kant en klaar staan:

Qtractor 0.4.3 voor Ubuntu Jaunty Jackalope (64-bits)

Librubberband 1.4.0 voor Ubuntu Jaunty Jackalope (64-bits)

Rubberband 1.4.0 voor Ubuntu Jaunty Jackalope (64-bits)

Rubberband-LADSPA 1.4.0 voor Ubuntu Jaunty Jackalope (64-bits)

Misschien maar wat vaker op ctrl+F5 drukken of een RSS feed bookmarken. Heb gelijk wat geld gedoneerd via Sourceforge.

Als je het over de duivel hebt…