Optimizing USB MIDI out latency in KXStudio+LMMS

Optimize your system for ultimate performance.

Moderators: MattKingUSA, khz

Post Reply
blst
Established Member
Posts: 4
Joined: Thu Jan 01, 2015 1:12 pm

Optimizing USB MIDI out latency in KXStudio+LMMS

Post by blst »

Hi,

after some expensive and unproductive tests with Windows and VSTis, I came to the conclusion that I need real hardware and the possbility to switch between instrument patches quickly via jog dial etc. or switching the arp on/off with an extra button... I want to to a kind of "music prototyping/creation" - developing new ideas and create something like a demo mix based on these ideas... :) As a teenager my father had a big stage piano with sequencer, which I loved. When I look at the old files I hear humble first tries which improve to (comparably) musically and technically far more advanced arrangements in the most recent files.... After leaving my parent's house I tried to archive similar results and spent money for a MIDI USB keyboard, sequencers and VSTis like Native Instruments Kompakt. But i barely used that and never got comparable results to the stage piano times. :(

In the end I came to the conclusion that I need more real hardware. Doing everything on my "general purpose" PC (which also had some office photo gps mp3 video cad etc software installed) kind of blocked my creativity... In earlier days I could go to the stage piano and just try some chords / cadences. And if they sounded cool, I called the sequencer and started to create the arrangement. :D

During the last months, I planned to spend around 1000 Euros for something like an Roland FA-06. But now I've found a better approach I think. Last year I read about MIDI live setups and bought a Casio XW-G1 (special offer). I also intended to replace my old USB master keyboard with the Casio. The current approach is using the Casio with its patches also as basic main instrument (I think its sound is a little bit underrated in most reviews, with some tweaking you can get modern electropop mixes out of it...).
Second idea:
By using the Casio also as instrument, I don't really need VSTis anymore... So I don't need Windows or a Mac. At the beginning I tried to use a MPC 500 for sequencing, but Its note editing capabilities are not quite intuitive... I decided to buy a cheap Laptop with basic sequencing software. Because I don't use big commercial sample libraries, I can use Linux with ALSA or Jackaudio included which perform better than DirectSound and are better integrated into the system (compared to third-party ASIO by Steinberg). There are no issues like vendor lock-in, expensive virtual instruments not running on future OS versions etc. And it's cheaper than a Mac. :)



My configuration is now:

-Cheap 300 Euro laptop dedicated for sequencing (Pentium 4-Core)
-KX Studio installed on it
-Casio XW-G1 connected to the laptop via USB, alternatively connected via ESI Midimate II.

Basically everything works fine and as intended. Most problems which prevent the creation of nice arrangements I had with music software on my general purpose PC are gone! 8)

But there's one technical issue: I get timing problems when I send a looped bar with line of 1/16 notes (shaker, hihats...) from LMMS to the Casio, or a series of the same bar with 1/16 notes. There seems to be a kind of "gap" between the bars which varies in length. Sometimes a series of the bar sounds correct, sometimes there are tiny gaps. In a recording of one arrangement I even have a misplaced 1/4 kickdrum in one bar. This happens both with a direct USB connection and using the ESI MIDImate and the MIDI in of the Casio. These problems don't appear when the Casio is controlled by the MPC.

I've read some info about MIDI and USB and latencys and suppose that the main problem might be the USB protocol? Are there possibilities to tweak this? Perhaps I can configure my Linux that one of the CPU cores uses 100% CPU power for polling the USB interface..?

I've already played around with the LMMS buffer size and got different results. The setting 128 frames seems to be the best for me.

I'm also wondering why a single bar with 1/16 notes usually plays fine. The problem is that sometimes the following repeating of the bar seems to start too late. Could that be a LMMS problem?
DepreTux
Established Member
Posts: 135
Joined: Tue Jul 23, 2013 9:36 am

Re: Optimizing USB MIDI out latency in KXStudio+LMMS

Post by DepreTux »

Hi,

I haven't got experience driving external MIDI hardware with linux, but as far as timing issues go, I've had best results with a custom kernel with

CONFIG_HZ_1000=y
CONFIG_SND_RTCTIMER=m
CONFIG_SND_SEQ_RTCTIMER_DEFAULT=y
CONFIG_IRQ_TIME_ACCOUNTING=y

Once you've got your kernel set up like this, you can create a file "rtctimer.conf" inside /etc/modprobe.d/ and set the timer frequency to 8192 (the maximum for this timer), like this:

Code: Select all

options snd_rtctimer rtctimer_freq=8192
The hrtimer provides better precission but is more unstable, and jitters when you stress the processor (in my experience). I'm running a 3.4 kernel, other versions have other interesting options.
rghvdberg
Established Member
Posts: 1067
Joined: Mon May 12, 2014 7:11 am
Has thanked: 15 times
Been thanked: 36 times

Re: Optimizing USB MIDI out latency in KXStudio+LMMS

Post by rghvdberg »

LMMS is more designed to work as a all-in-one, stand alone program.
It appears to me that LMMS, for your way of recording/sequencing, is not really the appropiate software. I use LMMS quite a lot but rarely ever record with it, it's more a 'music production' program.

I think you'll get better results with qtractor or rosegarden. (I prefer qtractor)
blst
Established Member
Posts: 4
Joined: Thu Jan 01, 2015 1:12 pm

Re: Optimizing USB MIDI out latency in KXStudio+LMMS

Post by blst »

Now I've replaced the Linux Kernel with Version 3.19 lowlatency.

The timing of 1/16..1/32 midi notes on external gear has improved a lot, now it's quite good :) (but not perfect)...

On the downside, booting up the computer takes a longer time and I get some error messages. And the system doesn't shut down properly anymore. It ends up showing the KXStudio logo and blowing the fan fullspeed for a short time once a minute. I have to use the power button to switch it off.

I also upgraded to 3.19 since the Zoom R16 interface is supported there for the first time.
glowrak guy
Established Member
Posts: 2547
Joined: Sat Jun 21, 2014 8:37 pm
Been thanked: 320 times

Re: Optimizing USB MIDI out latency in KXStudio+LMMS

Post by glowrak guy »

There is a halt command you can use. Maybe install/run htop and see if undesired things
are running. You might try scripting power management to stop, when qjackctl is started,
and resume when it is stopped. It's gui has spots for such scripts.
Nice that Zoom is working. The new Casio's are pretty fine. Lots of useful features,
and good sounds, without the paying workstation prices 8)
Post Reply