Ideally, for optimal concert-like quality and keyboard feel, you should run Pianoteq 9 at 96’000 fps (I know @riban will love this ) with an audio data buffer of 64 samples. That should give you a theoretical latency of 6.6 milliseconds, which is very close to the actual mechanical response of an acoustic piano.
This said, such settings would exert a considerable pressure on the Pi5 CPU at maximum polyphony, even with just the PT engine loaded in the system, and do not expect anyway real timing figures to be so tight, because real round-trip latency also depends massively on DACs and audio drivers quality of the chosen audio board.
My suggestion is either go for the best available Hifiberry audio hat, or provide yourself with a high-res portable external DAC of a reputable brand. The latter wouldn’t be cheap, but would probably give you what you’re after.
I had shouted my opinion before even getting to this sentence!!!
@Aethermind’s calculations are a bit out. 96000 frames per second with two 64 frame buffers will give a theoretical latency of 1.3ms but this is likely to be unachievable. You would need to run jackd (not Pianoteq) at 96000 to get this latency and zynthian is optimised for 48000 frames per second. Going higher is untested and likely to cause other issues. Indeed, increasing Pianoteq internal samplerate will burn through CPU which is why we have only recently enabled full-rate (48000) on it.
Some soundcards do not support such low latency, for example my Tascam US-1608 will not support a reduction of buffer size and increase in samplerate beyond a limit (5.3ms). I would suggest that this is a reasonable target for zynthian. It may be possible to reduce this with some soundcards and with limits on what engines are run simultaneously but 5.3ms seems like a sweet point.
Is there a reason to use the “Raspberry Pi DAC Pro (formerly IQaudio DAC Pro)”? We have seem many issues with IQaudio in the past and I don’t trust them to provide reliable operation. If you already have one then simply build the zynthian and see. You can inform us! You can put it together really quickly on the bench to see how it behaves.
[Edit] I tested with the official zynthian V5 soundcard and saw similar results, i.e. I cannot reduce theoretical latency below 5.2ms. Anything else leads to xruns and/or gross distortion. Remember that in practice, 5.2ms isn’t bad. It is similar to sitting/standing about 1.5m from the sound source. If this was fed to headphones then you are probably getting a similar experience to a real grand piano player. Other’s in the forum may be able to provide some magical combination of hardware and configuration to obtain lower latency but my tests suggest 5.2ms to be the lowest achievable with the hardware I have available.
[Edit] I was able to eek out 4ms by using 3 buffers of 128 bytes at 48000 fps but the processor was really urnning hard, pushing the health indication into the amber and red whilst playing. This test was performed on a RPi4 so a RPi5 might fare better. So you could get down to 4ms but you may struggle to beat that.
Furthermore, even a professionally trained pianist would struggle to tell a perceptible difference between 5 and 3 msecs of audio latency in a blind test.
5-6 milliseconds is considered the threshold of perceived real-time in psychoacoustics, and anything equalling or under 10 msecs is considered acceptable and subjectively close to real-time. So, if you don’t plan to play demisemiquavers of chords at 160 bpm with both hands - supernatural powers apart -, I don’t think that you would even notice the difference.
Running PT at 96’000 might be more useful instead, since it would give you some added edge, regarding clarity of the cross resonances in the upper part of the spectrum, but you would have to stick to a buffer of 128 or 256 samples, and to check anyway how sustainably the system performs in a real-time Zynthian performance scenario with those settings.
Thanks very much for your detailed replies — I really appreciate both the technical explanations and the real-world latency figures. That was very helpful.
I have one follow-up question:
If your only goal was the lowest possible latency and the best keyboard playing experience with Pianoteq on a Raspberry Pi 5 today, which audio interface or HAT would you personally choose?
Assume:
Raspberry Pi 5 (4 GB)
Official 7" touchscreen
USB MIDI keyboard
No audio inputs required (no guitar or microphone)
Only MIDI in and audio out
Would you still choose the Raspberry Pi DAC Pro, or would you recommend something else (e.g. HiFiBerry, the official Zynthian soundcard, Pisound, or another solution)?
I’m not looking for the cheapest option—I’m looking for the solution that gives the best playing feel and the lowest stable latency.
Off the topic of best audio card for your requirements, I wanted to mention that there are two different ‘generations’ of “Official 7” touchscreen", I think known as Touch Display and Touch Display 2, and they are quite different. The original TD will generally work with Zynthian, TD2 will come up in portrait mode, and to the best of my knowledge, although the display can be right rotated to landscape, the touch screen cannot. I submmited a 3 file set of pull requests to add the support for TD2 in landscape about 10 days ago. It has not been accepted (hopefully), yet.
For reduced latency, I would recommend a I2S interface, i.e. a soundcard directly connected to the RPi header (like a hat) rather than USB. USB has fantastic behaviour now (since many years ago when substantial improvements to the audio stack were made) but it will always need some extra buffering which is within the USB driver, not jack. So there will be more latency.
Quality can be measured if you define your parameters but is mostly objective. (See the works of Robert M. Pirsig for a philosophical investigation into quality.) If I play in a rock band, almost any I2S interface (and most USB interfaces) would provide sufficient quality. If I were making a high definition recording, I would be looking for large dynamic range, low noise floor and low level of distortion in which case I would be looking at the DAC, analogue circuitry and probably most importantly the power supply circuitry. So the range of I2S soundcards would range from:
to a Hifiberry card which is regarded at the higher end of the “quality” range. If zynthian’s official soundcard fits your build then I would recommend this because we love zynthian.
It may be evident from my investment in zynthian, how much I love it - but if you only want Pianoteq then zynthian is actually not the best platform. You can run Pianoteq at full rate with full polyphony on a Debian (or other OS) RPi4 without issue. Zynthian adds some overhead which means we have to throttle the internal samplerate to half on the RPi4 but can run it at full rate on a RPi5. (It is in the back of our minds to improve the behaviour of zynthian’s core software to reduce this overhead.) So, if you want a single instrument, just put something like DietPi on the RPi5, install Pianoteq, run it with ALSA (not JACK) and get it to auto-start on boot. Extend its UI if required, e.g. over remote desktop. This would give the most performance and may allow use of higher samplerates and lower buffer settings. If you want more functionality, e.g. more instruments, effects, samplers, looper, sequencer, mixer, etc. then zynthian is fantastic.
[Edit] If you are going down the zynthian route, I would recommend adding audio inputs. My first DIY zynthian used one of the cheap I2S that I described above with output only which was fine for a long while but I did come to regret not having inputs. (I now have 16 inputs and 8 outputs!!!)
Apart from sound quality, have you measured or observed any practical latency differences between the various I²S audio HATs (e.g. Raspberry Pi DAC Pro, HiFiBerry DAC2 Pro, cheap PCM5122 boards, etc.)?
Or is the latency essentially identical between I²S HATs, with the main differences being analogue sound quality, noise floor and output stage?
That is seldom true… we continue to be curious and that is a wonderful thing!
Latency is cumulative. There is the internal workings of ALSA & JACK which we can control with buffer sizes, samplerate, etc. There is the hardware DAC which has its own buffers and conversion time. There is also some delay in tha analogue circuitry but this is generally insignificant. So yes, in theory there could be differences in the latency introduced by each soundcard. Most of them are likely to be broadly similar and their software drivers are likely to also be similar (as they use the same I2S interface). So, only going on my general experience (which is fairly extensive) and without any actual metrics (or other soundcards with which to test) I would say that you will have broadly the same latency with most (probably all) I2S soundcards.