Zynthian`s sample rate

Hello :slight_smile:

I am trying to find out at what sample rate the Zynthian is working. The HiFiBerry DAC+ supports up to 192000Hz, which is nice.

I found the
/zynthian/zynthian-sys/etc/zynaddsubfxXML.cfg

The sample rate was set to 48.000 and I was able to increase to 192000 - and it still works - but I am not sure that this is all. Maybe the sound card itself must be set up to use the higher sample rate. What software/driver architecture is working inside the zythian? Can someone point me in the right direction?

Hi @lod!

Zynthian uses jack audio driver, that it’s configured to 44100. You can configure a higher freq, but it will eat more CPU. Up to you :wink:

If you want to change this, you should take a look to:

/etc/systemd/system/jack2.service

Kind Regards!

Hello @jofemodo,

I will try to benchmark it and report back :grinning:

The reason for this test: A friend told me that a higher sample rate affects (besides the sound quallity) the latency of a sound card in a positve way. So I will try to do a latancy test as well (not sure if this will work out as planned :grin: ).

Greetings,
Martin

OK I did the benchmark :slight_smile:

Setup
Device: Zynthian with RPi 3 / Hifiberry
Software: Mod-Ui + ZynAddSubFX (Preset Hyper Organ 1)
Input Chain: PC with Ableton -USB> Sound Card (Steinberg UR22) -MIDI> Zynthian
Output Chain: Zynthian -Jack> Sound Card (UR22) -USB> PC with Ableton

Thats quite a long input chain but I wanted to use Ableton for MIDI input in order to make sure that the input does not depend on Human timing. On the other Hand we have now to keep in mind, that the latency shown in the data below is the result of the whole input and output chain.

First run: Zynthians default settings (44100Hz)

23.9% CPU load. Thats why I have chosen this patch: It has a good punch on the CPU without being a problem at 44100Hz)

Thats a 40ms latency of my input/output chain - for my personal taste this is a bit to much.

Second run: Now with 48000Hz


CPU load 26.4. Of cause CPU load is not perfectly steady but it does not vary that much and I tried to take the screenshots at an average level.

Latency is similar to 44100Hz.

Third run: Lets take it to 96000Hz


50.3% and going into red alert mode. I have tried other patches and reached higher CPU load values but reached only in rare cases the red alert.

Uh whats that! ~33ms - lets try again -> OK its repeatable. Too bad that it is too hard for the Pi`s CPU.

For now I will stick to the 48000Hz. There seems to be no advantage for the latency but it is just increasing a little bit the CPU-load and according to Wikipedia:
48000Hz: The standard audio sampling rate used by professional digital video equipment ...

:sunglasses:

3 Likes

@lod

Thanks for testing and reporting! Hm… what you also can try is the following:

Buffer size, sometimes called frames/period

In a nutshell - Smaller buffer sizes produce less monitoring latency.

More in-depth details - A lower setting will make the computer work faster, which will allow for lower latency, but at      
the expense of increased CPU usage. Higher (larger) settings are more stable but you won't get low monitoring 
latency with them. If you are looking to achieve low latency monitoring, a setting between 64 – 256 will give you  
usable results.
(from http://libremusicproduction.com/articles/demystifying-jack-%E2%80%93-beginners-guide-getting-started-jack)

For jack there are two parameters -p, --period int and -n, --nperiods int. The last is already set to 2 and cannot be lowered. But --period is currently set to 256. You can change this parameter to something with a power of 2… lower means more CPU usage and faster getting xruns. Try 128 or 64 in combination with a higher samplerate - perhaps this can minimize the latency a little bit - perhaps with xruns.

You can set these values in /etc/systemd/system/jack2.service. Don’t forget the following after changing:

systemctl daemon-reload
systemctl restart jack2
systemctl restart mod-ttymidi
systemctl restart mod-ui

I don’t think that this will help very much… the CPU power is limited and minimizing the latency means raising the posibility of xruns - this depends hardly on your setup (number of plugins, complexity of plugins).

Regards/mit vogonischen Gruessen, Holger

1 Like

@C0d3man

Thank you for your suggestion!

In order to have the full data here available below the test results:

For the setup and the reference run please look at the data posed above.

Fourth run: Sample rate 48000Hz / Buffer size 128


31.6% as an average but the CPU load is not as steady any more - now there are spikes up to 60%. But no read alert so it works pretty good.

That is an improvement. i would say latency is now about 35ms.

Fifth run: Sample rate 48000Hz / Buffer size 64

Its saying CPU-load 28.7 but Red alert is on.

Latency improved a bit to ~32ms.

I will try out the buffer size 128 - lets see how this will work out.

1 Like

Hi @lod!

Good work!

I understand you are using an instrument from Ableton as reference, is it correct?

In theory, the latency difference when using 96000 and 44100, maintaining the other parameters (periods=256, nperiods=2) should be easy to calculate:

jack latency=(nperiodsperiod)/(nchansfreq)
freq=44100 =>(2256)/(244100)=5.8ms
freq=96200 =>(2256)/(296000)=2.9ms

So, the difference should be 2.9 ms. Your measure is slighty more, about twice. Probably it’s a preccission matter. Your “external” latency it too high and it’s difficult to appreciate the difference. What do you think?

Regarding the sampling frecuency (48000 vs 44100):

  • 44100 (and 88200) is the standard for audio
  • 48000 (and 96000) is used for video.

As Zynthian is an audio machine, it uses 44100 by default :wink:

Kind Regards!

1 Like

Hi @jofemodo !

I have measured how long it takes until a Midi-Note send by Ableton comes back into Ableton as an audio signal from the Zynthian. But I am using an external USB sound card (Steinberg UR22) for sending the MIDI and recording the audio.

Yes I guess that is the thing I learned doing the test - most of the lantency comes from the USB sound card. (output latency + input latency = too much latency). My buffer settings for the USB soundcard are already low. If they where set to even lower values clips and pops are staring to emerge. So I tryed to minimize the Zynthians latency:

Original: freq=44100 =>(2256)/(244100)=5.8ms
New: freq=48000 =>(2128)/(248000)=2.6ms

But it is just a try - I think the original parameters are better in most cases because they are less CPU intensive and it is very likely that I will revert back to them.

Jeje! More frecuency is better, the problem is always CPU, of course. Is finite :sob:
:yum:

1 Like

Is this still valid? I saw that several standard interface configurations come with a samplerate of 48000 by default in the jackd options (example of the UCA222). I’m trying to find the best configuration for my focusrite solo… that’s why the question…

We now use a default samplerate of 48000 frames per second.

1 Like

it is ok in Rp4 ?

Yes, the default is 48000 for both RPi4 and 5. And i would guess earlier as well.

More and more DACs are defaulting to 48000 so setting that value means less latency due to resampling.