Latency question

Did anyone try this ?
In this file
config.sh

Changing the JACKD_OPTIONS to include -S ? Perhaps that would make the zynthian unstable.
What if the buffersize of say 64 and a samplerate of 192K is called directly when JACKD is started in that service ?

export JACKD_OPTIONS="-P 70 -t 2000 -s -d alsa -d hw:Headphones -r 44100 -o 2 -p 512 -n 3 -X raw"

I was reading this trying to figure out if anything could be shaved of the latency
https://support.hifiberry.com/hc/en-us/community/posts/360014591758-Latency-on-hifiberry-DAC-ADC-Pro

I edited this file
https://github.com/zynthian/zynthian-sys/blob/testing/etc/zynaddsubfxXML.cfg

I set the samplerate to 192khz and buffers down to 64.

The unit had no trouble handling mda electric piano or the effects .
I took a lop at the linux “top” command while using it and the CPU wasnt having any problems.

There seems to be a fair amount of delay in and out of the buffer.

Looking at this
https://wiki.linuxaudio.org/wiki/jack_latency_results

I am guessing that around 4 or 6 milliseconds is possible . It really feels closer to 10 milliseconds playing the synth and using the effect.

I have an electrosmith daisy which when running as an audio effect feels way snappier than the zynthian.

Its such a cool little box would be great to find a way to modify the OS to speed it up if that’s possible.

I need to read the code a lot more I know.
Sean

2 Likes

aah spoke to soon I think that flag is already turned on here

https://github.com/zynthian/zynthian-sys/blob/testing/config/zynthian_envars_V5.sh

what about -R ?

I hacked that file and started jackd like this

export JACKD_OPTIONS="-P 70 -t 2000 -s -d alsa -d hw:sndrpihifiberry -S -R 192000 -p 64 -n 2 -X raw"

I thought it made quite a noticeable difference.

Why is -r used ?

https://linux.die.net/man/1/jackd

-R, --realtime

Use realtime scheduling (default = true). This is needed for reliable low-latency performance. On many systems, it requires jackd to run with special scheduler and memory allocation privileges, which may be obtained in several ways.
-r, --no-realtime

Sean

I am following this discussion with interest because PianoteQ has a bit of latency on my home-built Zynthian… and as long as it is a Pad, you may not even notice it, but on a percussive instrument like the piano it is very noticeable… I anxiously await Guru Riban’s opinion.

I think you’ve missed the flags are contextual

Yes -r is no realtime in the global setting but also for the alsa backend options you have

-r, --rate int Specify the sample rate. The default is 48000.

It depends where you put it on the line.

I’m pretty sure your -R 192000 isn’t doing anything.

Or at least try -R -r 192000

1 Like

Also, use webconf HARDWARE->Audio to set the jack parameters rather than hacking at files. This is the user configuration tool for Zynthian. Otherwise be sure that your changes have actually applied by running ps ax | grep jackd. Remember to reboot between changes.

Zynthian is resource constrained. We are continually working to improve its efficiency and whenever we can we reduce the latency but by default it is configured with a sample rate of 44100, buffer size of 256 frames and 2 buffers. This gives a theoretical latency of 12 * 256 / 44100 = 11.6ms. There are other delays, e.g. in the hardware but they tend to be insignificant compared with this headline figure. It is fine to increase samplerate to 48000 to give a latency of 10.7ms (I think this should be the default) but any other changes may cause issues with some engines. Note that Pianoteq’s internal samplerate is configured to half the jackd samplerate to avoid it running into issues.

2 Likes

Hi @seanwayland

As a newcomer, I wouldn’t recommend to tweak the configuration by hand. You can set the JACKD_OPTIONS from the webconf.

Regarding latency itself, the default configuration is a good compromise for the average use-case. If you really need smaller latency, you can try reducing the buffer or increasing the clock frequency.

Anyway, remember that the latency that matters is the latency you feel, not some numbers. It’s a perception that depends of a lot of factors, including the kind of sound you are going to play. The internal jackd latency is just one of these factors. You should play a little bit first and evaluate the real latency you feel and compare with your computer. I like to remember that distance to speakers/monitors also affects real latency and some people (probably not you) forget about it: 1 meter = 3 ms

Regards,

2 Likes



I decided to test it before changing the settings .
This result is with these settings

## in zynthian_envars_V5.sh
export JACKD_OPTIONS="-P 70 -t 2000 -s -d alsa -d hw:sndrpihifiberry -S -R 192000 -p 64 -n 2 -X raw"

### in zynaddsubfxXML.cfg
<CONFIGURATION>
<par name="sample_rate" value="192000" />
<par name="sound_buffer_size" value="64" />
<par name="oscil_size" value="1024" /

**TOP image is test file **
**Middle image is ZYNTHIAN **
**bottom image is NORD STAGE 4 **
tldr: zynthian looks like its adding over 10 ms latency at 192khz buffersize 64
I loaded up mda epiano in cubase.
Using a quantised midi file I bounced it to audio.
Then I used the midi file and sent midi to the zynthian using the midi out port of the rme interface
I recorded the audio coming back using the zynthian
Then I put the midi cable into my nord stage 4 compact 73 .
ran the same midi file into the keyboard and recorded the audio .

looking at the resultant wave files in cubase. I didnt see anything that looked like jitter.

The values are in seconds .
Note starts at 4.75
nord stage arrives back at 4.757
zynthian arrives back at 4.77

I know the rme is and the whole trip is probably around 4 or 5 milliseconds

Nord stage seems super fast but perhaps the sample is starting a little earlier than in the mda ?

there is another 13 milliseconds before the zynthian shows up.

As a reference for all this in music if my math is correct a 16th note at 160bpm = (60/160)/4 = 9 milliseconds.

In jazz music you live and die by your ability to play in time.

That’s why you see so many jazz musos with red keyboards in front of them.

I want something portable that isnt a computer with all the cables and crap to take on the road.

I think the default is -R for jack anyway and I agree with Baggypants that the way I started the jack service probably didnt do much.

aah look I havent correctly hacked the start of the jackd service

root@zynthian:/zynthian/zynthian-sys/etc# ps ax | grep jackd
  479 ?        SLsl   2:14 /usr/local/bin/jackd -P 70 -t 2000 -s -d alsa -d hw:sndrpihifiberry -S -r 44100 -p 256 -n 2 -X raw
 1888 pts/1    S+     0:00 grep jackd

its looking a lot better !!
I used this http://zynthian.local/hw-audio
used these jackd options

-P 70 -t 2000 -s -d alsa -d hw:sndrpihifiberry -S  -r 96000 -p 128 -n 2 -X raw

Zynthian now in line with Nord Stage its the new bottom image !


this it the output of linux “top” command while playing
CPU doesnt seem to mind those buffers and samplerate

root@zynthian:~# ps -aux | grep jackd
root      2794 10.8  2.3 108096 92644 ?        SLsl 11:46   1:21 /usr/local/bin/jackd -P 70 -t 2000 -s -d alsa -d hw:sndrpihifiberry -S -r 96000 -p 128 -n 2 -X raw
root      3487  0.0  0.0   7364   492 pts/1    S+   11:58   0:00 grep jackd
root@zynthian:~# 

Hi @seanwayland !

Your math is not correct, my friend. At 160bpm, the quarter note is 60/160=0.375 seconds, so the 16th note is 0.375/4=0.09375 second = 93.75ms (roughly 10 notes per second, what is super fast playing!!).
A latency of 10ms is not a problem for playing this and most musicians can’t feel the difference . Of course, some musicians can perceive it, but still can play with it.
Anyway, please, keep us informed about your experience with this low-latency settings and if it’s positive, we would consider to change the defaults.

Cheers

2 Likes

yes you are correct my math almost as bad as my soldering skills and ability to assemble something like zynthian !
We will see if the mda piano plus waylosynth plus the waylomod UD overwhelms the CPU . I dont think it will !
Onwards ! what a great little box !!!

2 Likes

Don’t get obsessed by latency maths. Feeling is the really important thing.

Enjoy playing and send some recording of your favorite standards you like to play. Or better, from some session with your band. Or both! :grin:

Regards

2 Likes

MDA epiano is super light. From my POV, it’s a master piece with a really warm and organic sound, good dynamics, that works with almost no CPU usage. Simply amazing!

You must adjust the gain quite low to avoid clipping when playing many notes at once or playing hard. I don’t like compressors for playing. But if you don’t mind some noise in the speaker, it’s a killer.

I love to use it in rehearsal, more than Pianoteq, because when you connect the zynthian to a good standalone amplifier with good analog distortion and fat bass, ohhhh yessss!! It’s a real trip. It can sound soooo dirty, like a true Rhodes :nerd_face:

Regards

1 Like

I agree that piano is amazing and all the samples in one simple file. Beautifully implemented plugin one of the very best .

Be aware that CPU load is not the only factor to consider. Audio must be transferred between nodes (input, processors, output, etc.) and to reduce the onset of over/under-runs (xruns), buffers are used. These buffers must be filled, emptied, processed, etc. within each processing cycle. Any process could be a limiting factor in this. JACK provides a tool for monitoring (some of) this: jack_cpu_load. This prints out jacks calculated load each second. At idle Zynthian consumes about 4%. If this gets about 60% then things can start to go awry. Some synths / processors ramp up their cpu consumption when being played (higher with more polyphony / complex sound) whilst other use a constant amount. This still doesn’t indicate whether there will be data transfer issues everywhere, e.g. soundcards do their own thing. (I have some very bad USB soundcards that are very slow.)

Also watch out for flags appearing in the top right of the Zynthian display which can indicate xruns, temperature throttling, etc. If an xrun occurs there will be disruption to the audio that may be an audible click. This is due to too much or too little data being provided at some node in the processing graph within the processing cycle which will result in a discontinuity in the audio stream. xruns are our mortal enemy that should be eradicated, sometimes at the expense of higher latency.

As described earlier, most players can cope with significant latency when playing. Experiments show that approximately 30ms of latency is the point at which playing becomes substantially challengine. 12ms can be noticable but most types of playing / musicians are unaffected. Virtuoso musicians can be challenged above 6ms, as can the feel or groove be affected but this very much depends on the insturment, player, listening environment, etc. Many of us tend to be approximately 1.5m (5ms) away from our sound, e.g. amplifier when playing. If you listen on headphones then it is more natrual to have a little latency. Of course when feeding that distant amplifier, the latency is cascaded.

As @jofemodo says, listen and feel your way. We will do the maths and reduce default latency as far as we feel we can. If you feel its wrong then you now know how to adjust it. You are right, default Zynthian latency is approximately 11ms.

3 Likes

I have very high regard for Riban, I have to apologize… I feel my latency (quite annoying) ONLY if my Zynthian is controlled via midi from the PC… If I connect the keyboard directly to the Zynthian, I have no latency, or at least not audible. The latency is audible if the Zynthian is connected via Midi to the sound card (Focusrite) and is managed by a keyboard connected to the PC through the DAW. This is only as information and certainly not as criticism. Thank you

1 Like

You need to give more detail.

Keyboard->MIDI-5->Zynthian good/bad?
Keyboard->USB->Zynthian good/bad?
Keyboard->MIDI-5->PC->USB->Zynthian good/bad?
Keyboard->USB->PC->USB->Zynthian good/bad?
Keyboard->MIDI-5->PC->MIDI-5->Zynthian good/bad?
Keyboard->USB->PC->MIDI-5->Zynthian good/bad?

As you can see - there are many permutations of what you describe and this has not even detailed the hardware, e.g. what keyboard, what soundcards, etc.