Plugin with internal samplerate, is it a good solution?

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

In order to achieve an audio plugin with an internal samplerate, one must first upsample above the desired fixed samplerate, then downsample to the desired samplerate. For example, if the goal is 144000hz and the user is running at 44100hz, upsample * 4 = 176400hz, now we can downsample to 144000hz.

144000 / 176400 = 0.81632653061224489796

Since the ratio is very not nice, this will cause jitter.

Image
(i made this amazing graph by hand in ms paint)

The reason I want this is so that, let's say you do a digital feedback circuit, 1-sample delay, that circuit is very sensitive to the current samplerate, so I want to solve the problem by guaranteeing the plugin is running at one samplerate no matter what. Will this jitter cause issues at different sample rates, is there a solution? Is this a bad idea? etc.

Post

This is a well studied problem. Search old threads and google.

You only need to up-sample once. The method of up-sampling (or interpolation) determines the frequency response. Most common interpolation methods include flooring/rounding, linear interpolation, 4-point splines and n-point sinc interpolation. The responses should be easy enough to find.

If consistency across sample rates is important to your plugin, then yes it is a good idea.

Post

Your definition of jitter is not mine, or you have a totally different assumption of how sampling rate conversions actually behave.
We are the KVR collective. Resistance is futile. You will be assimilated. Image
My MusicCalc is served over https!!

Post

Architeuthis wrote: Tue Mar 09, 2021 12:32 am In order to achieve an audio plugin with an internal samplerate, one must first upsample above the desired fixed samplerate, then downsample to the desired samplerate
No, that's not necessary.

What you want to do is interpolate directly from the original rate to the target rate, ideally using sinc-interpolation. In other words, you figure out where you need the target rate samples, then evaluate the interpolation of the original signal at those points and there's your target rate audio.

Post

Architeuthis wrote: Tue Mar 09, 2021 12:32 am The reason I want this is so that, let's say you do a digital feedback circuit, 1-sample delay, that circuit is very sensitive to the current samplerate, so I want to solve the problem by guaranteeing the plugin is running at one samplerate no matter what. Will this jitter cause issues at different sample rates, is there a solution? Is this a bad idea? etc.
To answer the other question: running at a fixed samplerate is not necessarily a bad idea, but it's quite complicated to get right. In particular, the biggest challenge is keeping two rates in sync when they are not at integer ratio from each other. What you likely want to do is to compute the fractional sample positions with respect to the external rate just once and then use the same computed values for both upsampling and downsampling to make sure the two rates always stay in sync.

I also suggest gather-interpolation for upsampling and scatters for downsampling to simplify the implementation. This is a tiny bit less efficient than gathering both directions, but it simplifies things a lot in terms of keeping things in sync and in terms of not needing to adjust the sinc-kernel based on the ratio of the sampling rates.

Post

Read this: https://www.earlevel.com/main/2017/08/1 ... rd-part-1/

TLDR, don't assume anything about what may exist between sample points.

Post

camsr wrote: Wed Mar 10, 2021 9:18 amTLDR, don't assume anything about what may exist between sample points.
That series of articles is very explicit about what exists between the sample points.

Point 2 from the intro:
We know what lies between samples

Post

In a lot of cases, this depends on the specifics of the implementation, there will be a good enough sample rate. Good enough to keep aliasing inaudible, or good enough to maintain a correctly positioned resonant peak within the audible part of the spectrum, etc.

So rather going for a complicated fractional resampling scheme in those cases it might make sense to use integer rates that are close enough to the desired fixed rate. If 192khz is the target then maybe go with 220.5 khz if the base rate is 44.1, or exactly 192 if the base rate was 48, for example.

Post

matt42 wrote: Wed Mar 10, 2021 11:32 am
camsr wrote: Wed Mar 10, 2021 9:18 amTLDR, don't assume anything about what may exist between sample points.
That series of articles is very explicit about what exists between the sample points.

Point 2 from the intro:
We know what lies between samples
Exactly.

Mathematically there (always) exists exactly one unique band-limited signal that satisfies the Nyquist-condition and this signal can be exactly reconstructed at arbitrary points with sinc-interpolation (or in practice, approximated to arbitrary precision by approximate sinc-interpolation). It is this very property that allows us to represent band-limited signals with a series of samples in the first place.

Post

matt42 wrote: Wed Mar 10, 2021 11:47 am So rather going for a complicated fractional resampling scheme in those cases it might make sense to use integer rates that are close enough to the desired fixed rate. If 192khz is the target then maybe go with 220.5 khz if the base rate is 44.1, or exactly 192 if the base rate was 48, for example.
I disagree. While it might sometimes make sense to oversample to a higher-rate in order to use a cheaper method of interpolation, practically speaking you always need some sort of interpolation for any kind of decent quality (ie. "nearest neighbour" starts to become a reasonable scheme only with oversampling ratios in the thousands, which is not terribly practical), which amounts to fractional resampling.

Post

mystran wrote: Wed Mar 10, 2021 11:55 ampractically speaking you always need some sort of interpolation for any kind of decent quality (ie. "nearest neighbour" starts to become a reasonable scheme only with oversampling ratios in the thousands, which is not terribly practical), which amounts to fractional resampling.
I'm sorry. Maybe we have our wires crossed. To clarify my earlier point was to not use any kind of fractional interpolation in cases where it's not necessary. Perhaps you got that and I'm completely misunderstanding your point.

Post

matt42 wrote: Wed Mar 10, 2021 12:22 pm
mystran wrote: Wed Mar 10, 2021 11:55 ampractically speaking you always need some sort of interpolation for any kind of decent quality (ie. "nearest neighbour" starts to become a reasonable scheme only with oversampling ratios in the thousands, which is not terribly practical), which amounts to fractional resampling.
I'm sorry. Maybe we have our wires crossed. To clarify my earlier point was to not use any kind of fractional interpolation in cases where it's not necessary. Perhaps you got that and I'm completely misunderstanding your point.
I probably just misunderstood what you were trying to say. I highly doubt we disagree on anything too fundamental here. I don't think avoiding fractional interpolation "at all cost" is worth it (sometimes it's the right thing to do), but I agree it doesn't simplify things in general.

Post

Yeah, I guess I just mean I'd need to have a good reason to upsample 44.1 to 192 rather than 176.4 or 220.5, for example. But if it has to be done then so be it. I probably could have been clearer in my post

Post

My Kawai K1 emulation uses an internal sample rate of 50khz, just as the hardware. As it is very unlikely for any host to run at this sample rate, I resample to match the host sample rate. If it fits the needs, why not?

Special care needs to be taken on any any sample-based events though, such as Midi events in my case. Depending on the resampling library, you might have to buffer events that lie on processing block borders etc.
https://k1v.nilsschneider.de - Kawai K1 emulated as VSTi/AU
https://heatvst.com - Android Synthesizer with full VST integration
https://gpuimpulsereverb.de - Use your GPU as reverberation DSP

Post

In my case, going to the nearest multiple of the samplerate is not going to work because the timbre and oscillating frequency of the algorithm will change even in the case of 176 vs 192. By the way, the higher the sample rate the less difference there is between sample rates because of the increase in accuracy.

Post Reply

Return to “DSP and Plugin Development”