Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to reduce latency? #77

Open
coolkids94 opened this issue May 25, 2024 · 21 comments
Open

how to reduce latency? #77

coolkids94 opened this issue May 25, 2024 · 21 comments

Comments

@coolkids94
Copy link

how do i reduce latency?
i see that there is launch switches for audio buffering and audio output but i dont know how to use them

@pachuco
Copy link
Contributor

pachuco commented May 26, 2024

I think it was -ab:BUFSIZE:NUMBUFS.
Default being -ab:512:32

@Karmeck
Copy link

Karmeck commented May 27, 2024

https://www.vogons.org/search.php?keywords=Buffer&t=99447

I think this link will work. It searches the vogons thread for the word buffer. How to use it and how it affects latency is mentions among the results

The thread in question :
https://www.vogons.org/viewtopic.php?f=24&t=99447&start=380

@AndyGraewe
Copy link

Currently the latency is to high to use it as an instrument (MIDI keyboard connected), even if I start it with -ab 1:1.
For games it might be ok. But the latency is higher then any vst/au plugin on my M1 Macbook (which I normaly run with something between 128 and 512 buffer size).
Even if I start with -ab 1:1 it feels more like a buffer size of 2048 or even higher compared to vst/au plugins in a DAW context.

@markanini
Copy link

markanini commented Jun 5, 2024

Perhaps you can reach out to

@giulioz

he demoed his work on an AU version a while back.

@giulioz
Copy link
Contributor

giulioz commented Jun 5, 2024

@AndyGraewe I think that at least on windows there is a minimum latency you can remove even by changing the buffer size, due to how windows audio driver work. The solution would be to use ASIO drivers instead, which could be easy enough to implement. I could try it if people are interested.

@markanini
Copy link

@AndyGraewe I think that at least on windows there is a minimum latency you can remove even by changing the buffer size, due to how windows audio driver work. The solution would be to use ASIO drivers instead, which could be easy enough to implement. I could try it if people are interested.

I would gladly help with testing, but my system is Windows if it helps with an Asio interface and a midi keyboard.

@giulioz
Copy link
Contributor

giulioz commented Jun 8, 2024

@markanini started working on it on this branch: https://github.com/giulioz/Nuked-SC55/tree/asio
Still WIP but going to continue soon

@juanpc2018
Copy link

juanpc2018 commented Sep 21, 2024

latency deepnds on several factors:
#1. AD-DA converter IC,
older generation "1st" 48Khz,
had too much latency,
96Khz, 192Khz "1st gen" also had,
192KHz "2nd Gen" had half,
for example:
some RME Fireface 800 interfaces
early serials 2004 had older 192KHz,
serials since March 2005 - 2014 had 2nd Gen 192KHz, IC.
AK4396 instead of AK4395
DA (43.5 x 1/fs) ms
0.99 = 44.1KHz
0.9 = 48KHz
0.49 = 88.2KHz
0.45 = 96Khz
0.25 = 176.4KHz
0.23 = 192Khz
DA (28 x 1/fs) ms *
0.63 = 44.1KHz
0.58 = 48KHz
0.32 = 88.2KHz
0.29 = 96Khz
0.16 = 176.4KHz
0.15 = 192Khz
manual page 92

Latest AKM has a bit less latency vs. Latest Cirrus Logic DA,
because Cirrus has a voltage Lag circuit to emulate a very fast analog voltage follower,
instead AKM is Stair step type.

latest DA with Digital filters "3rd Gen"
have half latency again, near 0, very low latency...

a 512 buffer = 256 buffer,
just replacing the AD-DA converters.
Apogee Rosetta 800 192 had 1st gen DA,

also some Pro interfaces, have 4-stage Analog amplifier,
increasing latency,
most modern interfaces only have 1-stage of amplification.

#2.
Sample Rate:
same DA converter used at 48Khz,
96Khz, or 192Khz has different latency...
faster = lower latency
but...
problem with 192KHz is that requires
ultra low jitter clock to avoid aperture errors.
jitter creates out of phase harmonic cancelations, depending on the amount.
from just blurr to swiss chese holes "very dark sound"

DDS clocks with 1ns "1000ps! of jitter cannot be used over 48Khz,
sounds blurry, Not detailed.

better a Real XO x512.

Some interfaces have JetPLL, that sounds better than most DDS.
some high end audio interfaces have 2x frequency JetPLL clock,

#3. USB is Not good for low latency audio,
PCI or PCIe have lower latency, same AD-DA converter by ADAT.

Basically:
PCI vs. USB2.0 interface like Focusrite Scarlett 18i20mk2
512 = 256
256=128
128=64
64=32

*same / similar latency in miliseconds AD-DA,
has different CPU load, different Buffer size.

#4. CPU
modern CPUs have latency because need millions of interrupts per second "buffer size"
requires a preemptive-RealTime kernel, to minimize interrupts.
Liquorix Kernel in Linux is nice for audio,
lowlatency kernel its ok, but Not as good.
generic kernel is useless for low latency in Linux

preemp-RT kernel was added to Linux Generic Kernel a few days ago.

asuming CPU has a proper Kernel,
requires a very fast CPU to have a lower buffer size.
High Single core score, in Cinebench R15, R20, R23, 2024

also code needs to run bare metal as possible,
like Ms-DOS, Not like Windows.
like Proxmox or ESXi, Not like VirtualMachine insde a OS.

other option is moving the software to other technology
like FPGA,
MISTer its based on Terasic De10-Nano developer board,
emulates up to 486 Dx 90 MHz.

FPGA can be designed to run more parallel,
CPUs are designed to run in serial, as fast as possible,
with some parallel features like AltiVec, MMX, and Pipelines.

for example:
Dhrystone its a classic CPU test,
older Amiga used Motorola CPUs,
PiStorm32 its a Motorola 68040 bare metal CPU emulation based on Pi4,
gives 1.6 Million Dhrystones in AmigaOS3.x Sysinfo,
4000x faster than 8086 XT at 8MHz.
test is Not 100% accurate between diferent architectures, and different compilers,
but gives a close enough basic idea.

Direct Pi4/Pi5 Unknown.

MacMini 2014 | 2.8GHz | i5 | 4th Gen intel mobile cpu 4308u
OSX Cata 10.15.7
gives 20 Million Dhrystones,
but requires more than 60 seconds, or several 60 seconds test, because power settings.

@giulioz
Copy link
Contributor

giulioz commented Sep 21, 2024

@juanpc2018 I think what the user is asking here is how to reduce the buffer size. The latency in the emulator is very high (almost half a second) because it uses a giant audio buffer size by default and it uses high-latency drivers (SDL) by default. The solution here is very simple, and it's 1) reducing the buffer size 2) make the code use a lower-level audio API like CoreAudio or ASIO. I've done a CoreAudio version on my own and I can reach latencies as low as 5ms, which is very good for live playing purposes. You also have to consider that the original hardware had a noticeable latency anyway due to the speed of cpu processing and the midi bus, which is actually accurately emulated here as well. So even with the most perfect audio processing you will still have that latency which is unavoidable.

I'm sorry to call you out on this and I really don't want to sound rude, but I feel like some stuff you stated in your previous comment could be a bit inaccurate and misleading. A good part of the current music industry makes music with plugins running on USB audio and high-level operating systems like Windows and MacOS, while still achieving state-of-the-art latency and sound quality. You stated several reasons in your comment that would actually not solve the core problem I stated previously.

@juanpc2018
Copy link

juanpc2018 commented Sep 21, 2024

Discussion Tab is Not active.

i have Protools HDX "Near 0-latency DSP"
ive done many tests... with real oscilloscope,
Nothing i say is misleading...

i also have a Real JV-880
has 2 stereo outs,
different DA converter.

same:
Focusrite Scarlet 18i20mk2
DA has:
Cirrus 1-2 + Relay
AKM 3-4-5-6-7-8-9-10 No Relay.

@AndyGraewe
Copy link

AndyGraewe commented Oct 14, 2024

I've done a CoreAudio version on my own and I can reach latencies as low as 5ms, which is very good for live playing purposes.

Is this version availible somewere? I would love to test it.

@juanpc2018
Copy link

juanpc2018 commented Oct 14, 2024

There was a popular Synth called AXS for DOS, then was released free for Windows, 1, 2, 3,4,5,6,7,8,9
only had MME and WDM, DirectX drivers, No ASIO.
minimum latency 40ms with PCI card RME hdsp9632 or Lynx AES16,
in Linux/Wine/Lowlatency Kernel
RME allows 10ms latency.
Lynx requires purchasing OSS 4front drivers, Not Open Source.

Windows MIDI is very unstable brand to brand,
required MIDITest 4 software...

want to try AXS for DOS version,
old boards with MPU-401 Joystick port had much better MIDI in XP/98se/95/DOS.
but in MISTer + optional MIDI expansion, and a 486sx 90MHz core.

@AndyGraewe
Copy link

Currently the latency is to high to use it as an instrument (MIDI keyboard connected), even if I start it with -ab 1:1. For games it might be ok. But the latency is higher then any vst/au plugin on my M1 Macbook (which I normaly run with something between 128 and 512 buffer size). Even if I start with -ab 1:1 it feels more like a buffer size of 2048 or even higher compared to vst/au plugins in a DAW context.

I found out that my latency issues with M1 Mac had to do with how I had built/compiled.

Yesterday I tried to re-build (like the way I did in May), but it was not possible due to some rtmidi issue.
I did not find out, what the issue was.

I was finally able to build the project using XCode this time and this fork:
https://github.com/jcmoyer/Nuked-SC55
This build runs way better with much less latency now.

I also welcome this forks possibility of sorting the roms into different folders for better organization.

@juanpc2018
Copy link

juanpc2018 commented Oct 21, 2024

rtMIDI reminds me of rtpMIDI
rtpMIDI reminds me of ipMIDI

@markanini
Copy link

markanini commented Oct 21, 2024

Just a +1. Playing SC55 as a live MIDI instrument with low latency on Windows would be something I'd enjoy trying.

@AndyGraewe
Copy link

AndyGraewe commented Oct 21, 2024

This fork https://github.com/jcmoyer/Nuked-SC55 with XCode build on Mac is now totaly MIDI playable.

It is not a vst, but I run it standalone and linked it as "external" instrument in Ableton Live.

@MusicallyInspired
Copy link

Now we just need ASIO for Windows.

@AndyGraewe
Copy link

Plugin version for Windows and Mac would be awesome.

@giulioz
Copy link
Contributor

giulioz commented Oct 21, 2024

I had been working on that for a while
https://github.com/giulioz/jv880_juce/tree/main
https://www.youtube.com/watch?v=IOflNNMC9Dc
https://www.youtube.com/watch?v=DxIF8f454ns

@AndyGraewe
Copy link

AndyGraewe commented Oct 21, 2024

I had been working on that for a while

I know that and I very much appreciate it.
Many thanks in advance.
Let me know if I can help with beta test plugin versions (win and mac).

I had nor discovered that there is alread a /tree/audiounit in your fork yet.
I will try to compile right now. :)

@AndyGraewe
Copy link

AndyGraewe commented Oct 21, 2024

No, I cannot build it.

I get file not found for this import:
#import <mcu.h>

in sc55AU2ExtensionDSPKernel.hpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants