If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Ruby resampling help
14 posts
• Page 2 of 2 • 1, 2
Re: Ruby resampling help
The following might sound strange, but I just want to make sure, we're on the same path.
Interpolation is finding values between two given values, based on certain rules. Linear is simple: If we're given 5 and 10 and want to find the value that is exactly in the center between them (50%), we calculate 10 - 5 = 5 * 0.5 = 2.5 + 5 = 7.5
In other words, we need the first and last value (a, b) and a percentage that describes the "position" between them (t): lerp(a, b, t)
Cubic Interpolation works a bit different. It uses first and last value and a percentage (a, d, t), but additionally two control points (b, c).
As you can see, instead of magically calculating the curve, instead 6 calculations are done per t-value: linear interpolation between a and b (P01), b and c (P11), c and d (P21), then linear calculation of P01 and P11 (P02), P11 and P21 (P12), and finally linear interpolation between P02 and P12.
That means, you define two end points, two control points and a t-value to get the resulting value. a and d are easy: that's last sample and current sample (or current sample and next sample, depending on your approach). b, c and t however have to be defined in a way that suits your needs. Since I don't know which values are preferred for standard cubic interpolation of samples, you could go with another standard, called the one-third-rule. Make b 1/3 of the way from a to d, c 1/3 of the way from d to a. For t again you have to experiment, but I would think the one-third-rule would be quite nice as well.
If you copied the methods from the spline class, just call qubic(a, b, c, d, t) with qubic(lastsample, lastsample + (currentsample-lastsample) * 0.333, currentsample - (currentsample-lastsample) * 0.333, currentsample, 0.333)
Interpolation is finding values between two given values, based on certain rules. Linear is simple: If we're given 5 and 10 and want to find the value that is exactly in the center between them (50%), we calculate 10 - 5 = 5 * 0.5 = 2.5 + 5 = 7.5
In other words, we need the first and last value (a, b) and a percentage that describes the "position" between them (t): lerp(a, b, t)
Cubic Interpolation works a bit different. It uses first and last value and a percentage (a, d, t), but additionally two control points (b, c).
As you can see, instead of magically calculating the curve, instead 6 calculations are done per t-value: linear interpolation between a and b (P01), b and c (P11), c and d (P21), then linear calculation of P01 and P11 (P02), P11 and P21 (P12), and finally linear interpolation between P02 and P12.
That means, you define two end points, two control points and a t-value to get the resulting value. a and d are easy: that's last sample and current sample (or current sample and next sample, depending on your approach). b, c and t however have to be defined in a way that suits your needs. Since I don't know which values are preferred for standard cubic interpolation of samples, you could go with another standard, called the one-third-rule. Make b 1/3 of the way from a to d, c 1/3 of the way from d to a. For t again you have to experiment, but I would think the one-third-rule would be quite nice as well.
If you copied the methods from the spline class, just call qubic(a, b, c, d, t) with qubic(lastsample, lastsample + (currentsample-lastsample) * 0.333, currentsample - (currentsample-lastsample) * 0.333, currentsample, 0.333)
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Ruby resampling help
I hope my last post was not too long? Just in case, here's another example.
You do 4x upsampling (or whatever the correct term is). That means, for every sample you end up with 4 samples. To not confuse you with odd values, I will show the use over the whole range from last sample to current sample (while in reality you'd calculate last sample to current sample - 1).
For each sample you would call qubic with the t-values 0, 0.25, 0.5, 0.75 and 1
0 and 1 give you last and current sample, while the three others are the interpolated values between last and current sample.
And remember: by changing b and c you get different interpolation values for the same t-values (except 0 and 1), so experiment!
You do 4x upsampling (or whatever the correct term is). That means, for every sample you end up with 4 samples. To not confuse you with odd values, I will show the use over the whole range from last sample to current sample (while in reality you'd calculate last sample to current sample - 1).
For each sample you would call qubic with the t-values 0, 0.25, 0.5, 0.75 and 1
0 and 1 give you last and current sample, while the three others are the interpolated values between last and current sample.
And remember: by changing b and c you get different interpolation values for the same t-values (except 0 and 1), so experiment!
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: Ruby resampling help
This is nice posts, explaining some rules. But i don't think that this is useful for realtime resampling. because we need to make many calculations per one sample. this is nice for resizing images, creating curves like vst volume shaper. Can apply for resizing of wave tables, but we create this tables and can make immediately the right size.
- Logado
- Posts: 62
- Joined: Tue Jan 06, 2015 5:42 pm
Re: Ruby resampling help
Logado wrote:This is nice posts, explaining some rules. But i don't think that this is useful for realtime resampling. because we need to make many calculations per one sample. this is nice for resizing images, creating curves like vst volume shaper. Can apply for resizing of wave tables, but we create this tables and can make immediately the right size.
Did you notice that this thread is about working in green? It is not about realtime resampling.
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
14 posts
• Page 2 of 2 • 1, 2
Who is online
Users browsing this forum: Google [Bot] and 76 guests