Electronic drumkit Midi - Latency

Talk about your MIDI interfaces, microphones, keyboards...

Moderators: MattKingUSA, khz

Post Reply
cy_coe
Established Member
Posts: 8
Joined: Thu Jan 12, 2017 7:58 am

Electronic drumkit Midi - Latency

Post by cy_coe »

Hi!

I have an electronic drum kit connected with a midi adapter to my PC. My headphones connected to the PC.

The midi adapter is a cheap one and my soundcard is a builtin.

Code: Select all

sudo lspci -v |grep Audio
00:1b.0 Audio device: Intel Corporation 8 Series/C220 Series Chipset High Definition Audio Controller (rev 04)
        Subsystem: Gigabyte Technology Co., Ltd 8 Series/C220 Series Chipset High Definition Audio Controller
01:00.1 Audio device: NVIDIA Corporation GF108 High Definition Audio Controller (rev a1)
        Subsystem: NVIDIA Corporation GF108 High Definition Audio Controller
The sounds of my drumkit are not really good so I wanted to use better sounding drumkits with hydrogen. I got this working but there is a latency that makes it impossible to play for me.

1. How can I measure the latency so I have values to work with when trying to improve latency? There is jack_midi_latency_test but I don't know how to use it...
2. Should I buy a better soundcard and midi adapter - would that improve latency?

I made my first tests with my desktop system: Debian testing with standard kernel
Then I installed KXStudio on another partition but that didn't make a difference (at least I couldn't hear a difference).

realTimeConfigQuickScan of my Debian:

Code: Select all

perl ./realTimeConfigQuickScan.pl                                                                                                                                                                       
== GUI-enabled checks ==                                                                                                                                                                                                                     
Checking if you are root... no - good                                                                                                                                                                                                        
Checking filesystem 'noatime' parameter... 4.8.0 kernel - good                                                                                                                                                                               
(relatime is default since 2.6.30)                                                                                                                                                                                                           
Checking CPU Governors... CPU 0: 'performance' CPU 1: 'performance' CPU 2: 'performance' CPU 3: 'performance' CPU 4: 'performance' CPU 5: 'performance' CPU 6: 'performance' CPU 7: 'performance'  - good                                    
Checking swappiness... 1 - good                                                                                                                                                                                                              
Checking for resource-intensive background processes... none found - good                                                                                                                                                                    
Checking checking sysctl inotify max_user_watches... >= 524288 - good                                                                                                                                                                        
Checking access to the high precision event timer... readable - good                                                                                                                                                                         
Checking access to the real-time clock... readable - good                                                                                                                                                                                    
Checking whether you're in the 'audio' group... yes - good                                                                                                                                                                                   
Checking for multiple 'audio' groups... no - good                                                                                                                                                                                            
Checking the ability to prioritize processes with chrt... yes - good                                                                                                                                                                         
Checking kernel support for high resolution timers... found - good                                                                                                                                                                           
Kernel with Real-Time Preemption... not found - not good                                                                                                                                                                                     
Kernel without real-time capabilities found
For more information, see http://wiki.linuxaudio.org/wiki/system_configuration#installing_a_real-time_kernel
Checking if kernel system timer is high-resolution... found - good
Checking kernel support for tickless timer... found - good
== Other checks ==
Checking filesystem types... 
** Warning: do not use /mnt/win7x64 for audio files.
   fuseblk is not a good filesystem type for realtime use and large files.
   For more information, see http://wiki.linuxaudio.org/wiki/system_configuration#filesystems
not found.
** Warning: no tmpfs partition mounted on /tmp
   For more information, see:
   - http://wiki.linuxaudio.org/wiki/system_configuration#tmpfs
   - http://lowlatency.linuxaudio.org
** Set $SOUND_CARD_IRQ to the IRQ of your soundcard to enable more checks.
   Find your sound card's IRQ by looking at '/proc/interrupts' and lspci.
I think realTimeConfigQuickScan of KX Studio isn't necessary because it is well known!?
rghvdberg
Established Member
Posts: 1067
Joined: Mon May 12, 2014 7:11 am
Has thanked: 15 times
Been thanked: 36 times

Re: Electronic drumkit Midi - Latency

Post by rghvdberg »

First I would try installing a real time or low latency kernel. I've heard good things about the Liquorish kernel for Debian.
Ubuntu/KX has RT and low latency in their repos.

AFAIK when using jack midi the latency of midi is the same as audio latency.
Tweak jack settings, experiment with periods and buffer to get a low latency.

http://libremusicproduction.com/article ... arted-jack

I'm not sure how this works with alsa midi.
j_e_f_f_g
Established Member
Posts: 2032
Joined: Fri Aug 10, 2012 10:48 pm
Been thanked: 357 times

Re: Electronic drumkit Midi - Latency

Post by j_e_f_f_g »

The software you're using can make a big difference. I think you should give my program eDrummer a try, because it's main purpose is to provide exactly what you want (a sampled kit for a drummer to play live via pads). It already got a thumbs up from a drummer who, like you, wanted lower latency than he was getting from other linux apps.

viewtopic.php?f=24&t=11024&p=40441#p40441

You can get eDrummer at https://sourceforge.net/p/edrummer-live ... ster/tree/

Author of BackupBand at https://sourceforge.net/projects/backupband/files/
My fans show their support by mentioning my name in their signature.

cy_coe
Established Member
Posts: 8
Joined: Thu Jan 12, 2017 7:58 am

Re: Electronic drumkit Midi - Latency

Post by cy_coe »

@rghvdberg: KX Studio has a RT Kernel already. I tried that and that was not really an improvement...

by the way, KX Studio is based on Ubuntu trusty, iirc. Does anyone know if the repo of KX provides a newer version for a distupgrade?

@j_e_f_f_g: I'll give it a try. I already read about your eDrummer. Will try it with KX Studio.

//Edit: eDrummer starts but I cannot connect midi:
ALSA lib rawmidi_hw.c:233:(snd_rawmidi_hw_open) open /dev/snd/midiC1D0 failed: No such file or directory



Thank you for the links, I will check that.

//2nd Edit: made some changes in Jack configuration as recommended in the link from rghvdberg. YEESSSS! Latency is now good enough to play. But I also want to try out eDrummer...
j_e_f_f_g
Established Member
Posts: 2032
Joined: Fri Aug 10, 2012 10:48 pm
Been thanked: 357 times

Re: Electronic drumkit Midi - Latency

Post by j_e_f_f_g »

cy_coe wrote:eDrummer. Will try it with KX Studio.
Don't do that. Use your debian install. (I use plain debian myself). KX Studio is a jack-centric distro, and includes/enables software "bridges" that attempt to reroute ALSA MIDI and audio devices to jack. This can cause problems with software that directly routes to ALSA MIDI/audio devices, like eDrummer. (eDrummer can be set to use jack. But from your error message, I see that you're setting eDrummer to directly access your MIDI interface. To do this, you need to disable those "bridges". Better off using a distro that doesn't have them).

Author of BackupBand at https://sourceforge.net/projects/backupband/files/
My fans show their support by mentioning my name in their signature.

User avatar
GMaq
Established Member
Posts: 2774
Joined: Fri Sep 25, 2009 1:42 pm
Has thanked: 520 times
Been thanked: 555 times

Re: Electronic drumkit Midi - Latency

Post by GMaq »

rghvdberg wrote:First I would try installing a real time or low latency kernel. I've heard good things about the Liquorish kernel for Debian.
Ubuntu/KX has RT and low latency in their repos.

AFAIK when using jack midi the latency of midi is the same as audio latency.
Tweak jack settings, experiment with periods and buffer to get a low latency.

http://libremusicproduction.com/article ... arted-jack

I'm not sure how this works with alsa midi.
Just to be clear. I don't think KX/Ubuntu have actual RT kernels, Ubuntu abandoned them years ago, unless something changed there are only optional lowlatency ones. AV Linux RT kernels work with both Debian and KXStudio however Debian has it's own repository RT kernels if you are using Testing or Sid.
cy_coe
Established Member
Posts: 8
Joined: Thu Jan 12, 2017 7:58 am

Re: Electronic drumkit Midi - Latency

Post by cy_coe »

Ok, I should go with Debian, got that. But with RT Kernels in my Debian testing I have the problem that I use a nvidia graphics card. And I cannot install the graphics driver (dkms) for the RT Kernel...

My Debian testing is optimized for desktop use. So I installed KX Studio that is optimized for audio...

Perhaps I will compile a RT Kernel for my Debian and check if I can install nvidia drivers with that kernel.

But I tested hydrogen with this kernel:

Code: Select all

uname -a
Linux butux 4.8.0-2-amd64 #1 SMP Debian 4.8.15-2 (2017-01-04) x86_64 GNU/Linux
This works with quite good latency using jack. There are xruns, but I try to optimize a bit more...
I'll test eDrummer with the standard kernel at first.

//Edit: Again I get:

Code: Select all

ALSA lib rawmidi_hw.c:233:(snd_rawmidi_hw_open) open /dev/snd/midiC0D0 failed: No such file or directory
I killed pulseaudio (configured it to not respawn).
Now I am a bit lost... I need at step by step tutorial for running eDrummer now I guess. :-(

//Edit2: I managed to install a PREEMT Kernel from liquorix repository with nvidia drivers.

Code: Select all

Linux butux 4.9.0-3.2-liquorix-amd64 #1 ZEN SMP PREEMPT liquorix 4.9-5 (2017-01-14) x86_64 GNU/Linux

Code: Select all

 ./realTimeConfigQuickScan.pl 
== GUI-enabled checks ==
Checking if you are root... no - good
Checking filesystem 'noatime' parameter... 4.9.0 kernel - good
(relatime is default since 2.6.30)
Checking CPU Governors... CPU 0: 'performance' CPU 1: 'performance' CPU 2: 'performance' CPU 3: 'performance' CPU 4: 'performance' CPU 5: 'performance' CPU 6: 'performance' CPU 7: 'performance'  - good
Checking swappiness... 1 - good
Checking for resource-intensive background processes... none found - good
Checking checking sysctl inotify max_user_watches... >= 524288 - good
Checking access to the high precision event timer... readable - good
Checking access to the real-time clock... readable - good
Checking whether you're in the 'audio' group... yes - good
Checking for multiple 'audio' groups... no - good
Checking the ability to prioritize processes with chrt... yes - good
Checking kernel support for high resolution timers... found - good
Kernel with Real-Time Preemption... not found - not good
Kernel without real-time capabilities found
For more information, see http://wiki.linuxaudio.org/wiki/system_configuration#installing_a_real-time_kernel
Checking if kernel system timer is high-resolution... found - good
Checking kernel support for tickless timer... found - good
== Other checks ==
Checking filesystem types... 
** Warning: do not use /mnt/win7x64 for audio files.
   fuseblk is not a good filesystem type for realtime use and large files.
   For more information, see http://wiki.linuxaudio.org/wiki/system_configuration#filesystems
not found.
** Warning: no tmpfs partition mounted on /tmp
   For more information, see:
   - http://wiki.linuxaudio.org/wiki/system_configuration#tmpfs
   - http://lowlatency.linuxaudio.org
** Set $SOUND_CARD_IRQ to the IRQ of your soundcard to enable more checks.
   Find your sound card's IRQ by looking at '/proc/interrupts' and lspci.

Code: Select all

cat /boot/config-4.9.0-3.2-liquorix-amd64 |grep CONFIG_HZ
# CONFIG_HZ_PERIODIC is not set
# CONFIG_HZ_100 is not set
# CONFIG_HZ_250 is not set
# CONFIG_HZ_300 is not set
CONFIG_HZ_1000=y
CONFIG_HZ=1000

Code: Select all

cat /boot/config-4.9.0-3.2-liquorix-amd64 |grep CONFIG_PREEMPT
CONFIG_PREEMPT_RCU=y
CONFIG_PREEMPT_NOTIFIERS=y
# CONFIG_PREEMPT_NONE is not set
# CONFIG_PREEMPT_VOLUNTARY is not set
CONFIG_PREEMPT=y
CONFIG_PREEMPT_COUNT=y
# CONFIG_PREEMPT_TRACER is not set

Code: Select all

grep -e "CONFIG_IRQ_FORCED_THREADING=y" -e "CONFIG_PREEMPT=y" /boot/config-`uname -r`
CONFIG_IRQ_FORCED_THREADING=y
CONFIG_PREEMPT=y
So far, so good. It's not a RT Kernel but at least PREEMPT.

Still get the error when trying to connect eDrummer with the usb midi device.
cy_coe
Established Member
Posts: 8
Joined: Thu Jan 12, 2017 7:58 am

Re: Electronic drumkit Midi - Latency

Post by cy_coe »

Just in case someone has the same problem installing a RT kernel in Debian with the need of nvidia drivers:

It is a kernel bug and there is already a patch if you want to compile a RT kernel yourself.
Post Reply