Explanation of Interpolate Hermite method

前提是你 提交于 2019-12-10 10:35:42

问题


I've currently got this bounty running on how to resample audio data with the intention of increasing the pitch.

Many solutions have been made and I have to admit I'm feeling a bit overwhelmed by the choices and information.

I was directed to this solution and found this chunk of code:

public static float InterpolateCubic(float x0, float x1, float x2, float x3, float t)
{
    float a0, a1, a2, a3;
    a0 = x3 - x2 - x0 + x1;
    a1 = x0 - x1 - a0;
    a2 = x2 - x0;
    a3 = x1;
    return (a0 * (t * t * t)) + (a1 * (t * t)) + (a2 * t) + (a3);
}

public static float InterpolateHermite4pt3oX(float x0, float x1, float x2, float x3, float t)
{
    float c0 = x1;
    float c1 = .5F * (x2 - x0);
    float c2 = x0 - (2.5F * x1) + (2 * x2) - (.5F * x3);
    float c3 = (.5F * (x3 - x0)) + (1.5F * (x1 - x2));
    return (((((c3 * t) + c2) * t) + c1) * t) + c0;
}

This seems like something simple enough that I can wrap my head around, but I'm wondering how I input the amount I would want to increase my pitch by. Which leads me to the following questions:

  1. The t argument of the first method takes a number between 0 and 1. Is this the factor by which I increase the pitch? Would that make 1 an increase of pitch of %100 (essentially double the speed)?.

  2. If the above theory is correct am I able to input a factor of more then 1? If not, how would I be able to do this?

  3. If by stating the above I've clearly shown that I'm totally off track would someone please help clairfy how I control the amount of increase in pitch using this method?

Thank you so much.


回答1:


These are functions that do the following: Given a discrete sequence of samples, interpolate smoothly between them. That is: suppose your original data is x(0), x(1), x(2), etc. You want (let's say) to make it 1.234 times faster. Then you want samples x(0), x(1/1.234), x(2/1.234), x(3/1.234), etc. And you want these to look like samples from a nice smooth signal that goes through the sample points you have.

Both of these functions should be used as follows. You want to interpolate between x(n) and x(n+1). To get a value you can call x(n+t), call them with arguments x(n-1), x(n), x(n+1), x(n+2) and t. When t=0 you'll get x(n); when t=1 you'll get x(n+1); you shouldn't (except maybe at the ends of your data) use arguments that aren't between 0 and 1.

So, to speed up or slow down your signal, sample at times [integer]/[speed factor]; for each time t, take n-1,n,n+1,n+2 such that n <= t <= n+1, and call the interpolator with values x(n-1),x(n),x(n+1),x(n+2) and t-n. And see how it sounds :-).




回答2:


Interpolation is a way to find new data points between discrete values.

The diagram above shows five values. X0, X1, X2, X3, X4. The values are for these five points are known. The in-between values aren't known and can only be approximated by interpolating from the known data points. Different interpolation algorithms will give different results.

For example, to find the value of the red dot (shown between the X1 and X2 values) we can use interpolation. The t specifies the point you wish to find. t will always be a value between 0 and 1. In this case t will be approximately 0.25.

The simplest interpolation method is linear interpolation. It is essentially the same as drawing a straight line between two points.

Linear Interpolation
y = x1 + (x2 - x1) * t

Cubic interpolation and hermite interpolation both function similary to linear interpolation except they use more data points to calculate curves instead of straight lines.

To understand what these functions are doing, it could be helpful to plot the functions in a graphing application.

To answer your questions:

  1. t has no relationship to pitch. It specifies the location of the in-between point the interpolation algorithm will calculate the value for.

  2. NA.

  3. These functions calculate values between discreet points. By themselves they do not pitch shift audio but they could be used in the algorithm that does.



来源:https://stackoverflow.com/questions/5390957/explanation-of-interpolate-hermite-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!