Living in a shell

Since I started working for my new employer the amount of time I’m spending inside a terminal window is rapidly increasing. And I like it. I’m learning more in a few months than I did in the past 5 years. I’m discovering superhandy commands and utilities that I had never used or even heard of before. Utilities like w, last and the various *stat utilities. And I’m becoming better and better in using utilities that I already know but that always remained hard to grasp simply because I didn’t use them extensively. Think of Vim, screen and sed. Or on a lower level, the Bash shell itself.

I’m particularly starting to develop a fondness for Vim. I’ve worked myself through a complete Vim book and when I finished it I was like, Vim is not arcane at all, it’s actually quite simple. It’s all about terseness, doing things in the fastest, most efficient way, memorizing the most important commands and forcing myself to use it for things I would normally do in say, gedit. So now I find myself easily copying whole blocks of text, commenting and uncommenting multiple lines with just a few keystrokes, using markers and buffers and browsing faster through files than possible with a mouse.

Currently I’m reading a book on Bash and it already provided me with a lot of new insights and ideas that I could use in my daily work. My scripting skills are a bit feeble so hopefully this book will help me to improve these. Luckily I have great colleagues that are very knowledgeable when it come to things like Bash and Vim so I’m coming along just fine. But I want to be able to purge a Sendmail mail queue filled with spam like I saw one of my colleagues do recently. What he did on top of his head was just amazing:

for i in `ls | grep qfr`; do w=`grep example.org $i | wc -l`; if [ "$w" != "0" ]; 
then echo $i | sed -e 's/^qfr//'; fi;  done | sed -e 's/^/*/' | xargs -n 50000;

This allowed him to create a list of all spam messages which he simply ran through rm. It’s no rocket science but I’d really like to be that proficient too. Another colleague of mine is just awesome with regular expressions and Vi. For example, I recently asked him how I could delete all text between parentheses including the parentheses, for example a list of packages I copied from /var/log/apt/history.log, and he immediately replied %s/([^)]*)//g. Yes, I’m blessed that I can work in such an inspiring environment.

Living in a shell

A month on a Mac

During the second job interview with my new employer I was asked if I’d like to use a Mac or a Windows PC with the assurance I’d get a Linux workstation after my probation time. Just put me behind a Mac then, that’s closer to Linux than Windows and from what I recalled it comes with a native terminal that does SSH. And what do I need more?

So there I am in front of a big, glossy screen and a tiny keyboard that lacks some familiar keys. My findings so far? Kind of neutral. I’ve got my terminal and I can run SSH from the CLI so I’m happy. There are some quirks that annoy me though (in no particular order):

  • No Compose key and I had to jump through quite some hoops to map a key as a Compose key.
  • No easy way to map a keyboard shortcut for opening a terminal. I had to resort to something called ‘Automator’ to get it working. And it still doesn’t work the way I want too. When there are no windows open pressing the shortcut doesn’t do anything. When there are open windows it works but why does it open two terminals when pressing the shortcut for the first time? Not a real big deal as I need multiple terminals anyway (I just can’t get used to tabbed terminals).
  • I prefer non-glare monitors to glossy ones.
  • No Home, End, PageDown and PageUp keys. Not a real big deal either, in fact, it’s a real good incentive to start getting accustomed to Vi(m) shortcuts since I kind of live inside Vim these days. I even bought this, great stuff.
  • Can’t get used to the default window management settings. For instance when you minimize a window and Alt+Tab to it the window doesn’t open. So I’m not minimizing any windows anymore since this is really annoying. Haven’t looked into changing this behaviour though, it’s probably something relatively simple.
  • Annoying pop-ups from updates and programs that are downloaded from the internet (“blabla” is an application downloaded from the Internet. Are you sure you want to open it?). Especially the latter ones are annoying. Disabling the pop-ups has to be done from a terminal. Wow, so much for a “user-friendly” OS.
  • Clicking the close button of an application doesn’t quit it. Cmd+Q does. This is something I won’t get used to either. Actually I don’t want to get used to the Cmd button at all.
  • I prefer a panel with a window list on it. I don’t know how other folks do it but this Alt+Tab stuff is counter-efficient in my case.

Are there things I particularly like about Mac OS X or the Mac itself? Actually no, can’t think of anything. Yeah, the keyboard feel is really nice but that pro gets nulled out because of the missing keys, ~ being placed next to the left Shift key and the Fn keys being mapped to the F1/F12 keys. Add to this the meaningless keys with all kinds of arrows on them and this key with a crossed square. No idea what they do. On a software level MacPorts is nice, it allowed me to install some of my favorite tools that I found were missing. Other than that I can’t wait to have my own workstation with Linux on it. The plan is that I get a Dell XPS 15 with a dual monitor setup. Something to look forward to.

And yes, I have to deal with quite some Windows servers now. I’m not going to dedicate a blogpost to my findings on that OS. Just one word. Meh.

A month on a Mac

Jack2 on Android

This mail just popped up on jack-devel:

Hello, I have news of JACK2 in android world!

Recently, Samsung released professional audio sdk on android platform which based on JACK2. It is a part of latest Samsung Mobile SDK: http://developer.samsung.com/samsung-mobile-sdk#professional-audio

Source code of JACK2 was retrieved from Samsung’s Open Source Release Center(OSRC) at http://opensource.samsung.com/. You can find current repository & more information at below link: https://github.com/KimJeongYeon/jack2_android

Additionally, SAMSUNG DEVELOPER CONFERENCE(October 28-29, 2013) will be held in San Francisco that one of sessions prepared to introduced professional audio on Samsung’s android mobile products: http://www.samsungdevcon.com/
Session : “Leveraging the Latest Features in Professional Audio Framework in Your App”

Thanks,
KimJeongYeon

Message says it all I guess. Apparently Samsung has developed a way to do pro audio on Android based on JACK Audio Connection Kit! Can’t wait to get my hands on this, stoked.

Jack2 on Android

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

Raspberry Jam Review

Last Thursday the first Dutch Raspberry Jam took place at the Ordina HQ in Nieuwegein. I offered to do a presentation slash demonstration about realtime audio and the the Raspberry Pi so I promised myself to be there at least an hour before the scheduled starting time of my demo. That way I could also join Gert van Loo‘s presentation. When I arrived at 19:15 there was no Gert van Loo though so that should’ve triggered some alarms. Also I didn’t look out for members of the organization as soon as I came in. Instead I chose to dot the i’s and cross the t’s with regards to my demo.

Wrong decision.

About half an hour later the event was closed.

WTF?

I approached the person who closed the event and introduced myself. He replied that they thought I wasn’t coming anymore. Apparently they misinterpreted my e-mail I sent earlier that day that I didn’t manage to produce something workable for the laser show guy. They took it for a cancellation. But immediately the event got kind of reopened and I set up my stuff. We had some audio issues but in the end everything went quite well actually. I showed off what is possible with a Raspberry Pi and realtime audio with the use of some of my favorite software. Guitarix featured of course. I grabbed my guitar, fired up guitarix on the RPi and played some stuff. Hooked up my MIDI foot controller and showed how to select different presets. I also demonstrated the use of the RPi as a piano with the help of LinuxSampler and the awesome Salamander Grand Piano samplepack and did some drumming by using drumkv1. Before the realtime audio demo I presented an overview of the Linux audio ecosystem and talked about the alternatives of how to get sound in and out of your Raspberry Pi. These alternatives are not bound to the onboard sound and USB, since recently it is also possible to hook up an external audio codec to the I2S bus of the Raspberry Pi. I got one in myself this week, a MikroElektronika Audio Codec PROTO board based on the WM8731 codec, so more on that soon. It’d be awesome if I can get that codec to work reliably at lower latencies.

So it all turned out well, I had a great time doing my presentation and judging by the interest shown by some attendants who came up to me after the presentation I hope I got some more people enthusiastic about doing realtime audio with the Raspberry Pi and Linux. So thanks Ordina for offering this opportunity and thanks everyone who stuck around!

Raspberry Jam Review

The wait is almost over

For years users have been asking for a ZynAddSubFX or Yoshimi plug-in with a GUI for Linux. It seems the wait is almost over thanks to the great work of Filipe Coelho aka falkTX.

ZynAddSubFX-LV2 Test #1 (Qtractor)

According to falkTX work on the plug-in is almost 90% done. Parameters can be restored too as the following video shows.

ZynAddSubFX-LV2 Test #2 (Ardour)

Apparently the developer of ZynAddSubFX is working on exposing all parameters so in the future it should also be possible to automate Zyn’s most relevant parameters. Needless to say this stuff is still highly experimental so use at your own risk. I’ve done quite some tests and the plug-in keeps up well, also if you use many of them within a project (I’ve tested with a project with about 15 ZynAddSubFX-LV2 instances). But this doesn’t mean the plug-in doesn’t have any flaws, closing its GUI could crash your DAW for instance. Further tests should reveal all the obvious bugs so everyone, get that code and test it! Build instructions can be found in the aforementioned forum thread.

Many, many thanks to falkTX for making this possible!

The wait is almost over

Carla on the Raspberry Pi

Last week I managed to get Carla running on my RPi. Carla is a really nice plugin host that supports the most important plugin frameworks available for Linux (LV2, DSSI, LADSPA and VST) with some awesome extra features like a built-in ZynAddSubFX synth and support for SF2, SFZ and GIG files. The latter didn’t work until yesterday but I managed to compile LinuxSampler (which is needed by Carla in order to be able to load SFZ and GIG files) for the RPi with the help of Paul Brossier aka piem from the Aubio project.

I just wrote him a mail:

Hello Paul,

I’m trying to package LinuxSampler for Raspberry Pi but I’m running into an issue when compiling which fails with a message related to RTMath.h. After some googling I ended up here:
http://bb.linuxsampler.org/viewtopic.php?f=2&t=514#p3156
So I started scouring the interwebs and found this:
http://packages.qa.debian.org/l/linuxsampler/news/20050806T210205Z.html
Where there is a reference to a possible fix. But the diff.gz that contains the patch is untraceable. I know this announcement is almost 8 years old but do you think you still have the diff or maybe an idea what changes you made to the code?

Thanks in advance and keep up the good work with Aubio!

Best regards,

Jeremy Jongepier

And guess what, he replied almost instantly! He gave me some pointers where to add some extra code and even though I’m not a coder I started trying things out. But then I stumbled upon actual patches to resolve this issue. I needed both the ARM and atomic patch and after applying those LinuxSampler compiled flawlessly in my Raspbian ARM chroot. The few lines of code I cooked up myself were almost identical so I got quite far actually. I should really pick up learning how to code, I think I’d learn fast.

So after compiling LinuxSampler I could rebuild Carla against the freshly created LinuxSampler libs. Installed the deb on my RPi and loaded some SFZ’s. It all worked like a charm. Carla is like a Swiss Army Knife, I’m really starting to appreciate this piece of software. Kudos to falkTX! And thanks to Paul Brossier for responding so quickly and helping me to get on the right track.


text-align: center;

Carla running on the Raspberry Pi

Carla on the Raspberry Pi

Open AV Productions: Fabla

Who recalls the times when Linux audio users were craving for a sampler LV2 plugin? Soon we will have even more choice besides drumkv1 and samplv1, enter Fabla! No idea what Fabla stands for but it sure looks fablalous.


Fabla by Open AV Productions uses the same release model as used with Sorcer recently. Instead of a year it took 9 days to push back the release date of Sorcer and hopefully the same thing will happen with Fabla. I’d love to get my hands on this plugin so I’ve done my part to speed up the release date.

Edit: Fabla has been released within 8 days!

Open AV Productions: Fabla

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

New notebook: minor issues

“My keyboard seems a bit loose on the lower left side, is that something that could be fixed?”
“We’ll take a look at it, should be no problem.”

So I paid a visit to BTO again, had to be at a Horus meeting anyway, and within 15 minutes the tech guy returned with my notebook from the workshop.

“Could you try it out?”
“It’s perfect, no loose spots anymore, what did you do?”
“Oh, I just replaced the keyboard with a new one.”

He just replaced the keyboard with a new one. Now that’s what I call service. With any mainstream brand you will have to do without your notebook for at least 3 weeks and in the worst case they’ll start nagging the faulty keyboard is not a warranty case. Not at BTO. Fixed within 15 minutes, ready while you wait.

At the Horus meeting one of the items on the agenda was “Jeremy’s new monster notebook”. Did I really have to show off my notebook? Yes I had and soon 2 or 3 people were like I’m going to get a BTO too and told me I should become a sales rep. More on the Horus meeting in a separate blog post.

I did find out the card reader doesn’t work. But fortunately System76 apparently uses Clevo parts too so after installing their dkms package the reader immediately started working as the udisks package already contains the needed udev rule for this card reader.

New notebook: minor issues