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

Resampling block #59

Closed
sdatkinson opened this issue Jun 23, 2023 · 8 comments
Closed

Resampling block #59

sdatkinson opened this issue Jun 23, 2023 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@sdatkinson
Copy link
Owner

Implement Resample, which subclasses DSP. It encapsulates another DSP object, and takes care of the incoming and outgoing resampling required to expose a buffer to the encapsulated object at the sample rate that it expects.

The use case for this is sdatkinson/NeuralAmpModelerPlugin#59. For example, a NAM model that expects a sample rate of 48k may be encapsulated, and the DAW may be running the plugin with a buffer provided at a sample rate of 44.1kHz. Resample will:

  • Resample the incoming buffer to 48k
  • Provide the resampled buffer to the encapsulated NAM model
  • Resample the NAM model's output back to 44.1k.

This will incur a delay due to the bounding samples that are required to interpolate a given sample as well as the integer sample numbers, meaning that a varying number of samples will be outputted by both of the resampling functions.

If the inner and outer sampling rates are equal, then it would be great to bypass any interpolation math and do a straight pass-through.

The purpose of the resampling block is to expose a clean interface around the encapsulated DSP object, and should be orthogonal from the resampling algorithm itself that's used. I'll provide a simple cubic interpolation algorithm, and other developers may swap in more accurate or better-optimized routines as they'd like.

@sdatkinson sdatkinson added the enhancement New feature or request label Jun 23, 2023
@sdatkinson sdatkinson self-assigned this Jun 23, 2023
@daleonov
Copy link
Contributor

Yes! You can look at the resampler from JUCE for inspiration. I've been using it with NAM since last summer and it works perfectly for this exact purpose. So might as well port it to NAM. I use a LagrangeInterpolator from here -> https://docs.juce.com/master/classGenericInterpolator.html

@daleonov
Copy link
Contributor

Oh, by the way, two more requests for that:

  1. getLatency() method that tells us how many frames is the resampler's latency, so we can report it to the DAW to adjust PDC.
  2. prepare() method to call outside audio thread that resizes those internal buffers every time sample rate or block size changes.

(obviously method names are arbitrary)

@David-Else
Copy link

A few years ago this was considered the highest quality open source resampling library from the master behind Voxengo plugins: https://github.com/avaneev/r8brain-free-src. I assume it still is, check it out!

@olilarkin
Copy link
Contributor

I am not sure that the cubic resampler WIP in the NeuralAmpModelerCore repo will be of high enough quality. Cubic resampling will introduce a lot of aliasing. But r8brain-free-src is not designed for real time usage afaik, and will be too heavy. I propose to use either WDL_Resampler or perhaps this which @baconpaul kindly MIT'd for me.

@olilarkin
Copy link
Contributor

Implementing WDL_Resampler in the plug-in code would be simple

@olilarkin
Copy link
Contributor

I've got some really good results with the Lancsoz resampler, which has much less aliasing that the interpolation modes and is fast and only adds a tiny bit of latency: sdatkinson/NeuralAmpModelerPlugin#341

@baconpaul
Copy link

Once I fixed that bug. Lol. Glad to see it helps!

@sdatkinson
Copy link
Owner Author

Coming back to this, I don't think it makes sense to implement the resampler here: same as AudioDSPTools, it's not "NAM-specific" and others may have their own favorites already.

Still, I definitely appreciate the input on this Issue and will be referencing it as I work on getting resampling in my plugin; thanks!

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

No branches or pull requests

5 participants