Oversampling and latency

Thanks to Oli’s clear oversampling example I successfully implemented oversampling in one of my plugs :smiley: but I ran into a problem when I tried to mix both: processed (oversampled) signal and unprocessed one. Oversampling brings a couple of samples of additional latency (presented in this video: https://youtu.be/TDeJVkoPp-o ) what would not be a problem to compensate, if this latency would be rounded to exact sample. 2x oversampling is somewhere between 3 to 4 samples late and 4x, 8x and 16x algos are all around 5 samples late (but all are slightly different).
So how can one compensate latency with subsample accuracy? It seems the problem (and the solution: to make latency constant and/or rounded to exact sample) is in HIIR library, but hacking it is certainly above my competence. Does anybody have any ideas or workarounds?

My test files are here: https://github.com/JanezKrizaj/Oversampling_Test

Best to all!

The easiest thing to do would be to do your dry/wet mix at the upsampled rate, which may not be desirable.

Seems the filters in HIIR add a tiny amount of latency, various discussion on KvR about latency of polyphase IIR oversamplers, i’m afraid i don’t know the solution, but it might be possible to delay the input fractionally with an appropriate interpolated delay line

1 Like

Thanks Oli. I already searched KVR Forum, but I didn’t see the thread you linked :+1: As you suggested I updated my test project with interpolated delay line and here are my findings about oversampling vs. latency (in samples):
2x = 3.50
4x = 4.75
8x = 5.00
16x = 5.18
so the simplest solution would be to use 8x factor only, use 5 samples buffer for the “dry” signal and accordingly report latency in config.h

Caveat: there is also a phase shift (seems due to HIIR non phase linear filters) which can not be compensated with delay and is SR dependant:
44.1 kHz strongest phase shift at 16.5kHz (but back to normal at 20kHz)
48 kHz phase shift at 17.5kHz
88 & 96 kHz phase shift above hearing range :wink:

One more thing which bugs me (as I can not explain it to myself) is level inconsistency. If I feed oversampler with 20Hz to 20kHz sine sweep, the level stays firmly at 0db, but if i feed it with white noise, level meters jump to over + 8 db, but I can not audibly perceive such change. Hm, the world is beautiful with so many mysterious wonders :grinning: