0

我有一个实现可以以不同速度读取的音频流的类(包括反向和快速变化/“刮擦”)......我对读取部分使用线性插值,一切都很好......

但是现在我也想实现以不同的速度写入流,这需要我实现一种“反向插值”,即推导出输入样本向量 Z,用向量 Y 插值将产生输出 X(我'我试着写)..

我已经设法在恒定速度下做到这一点,但对不同速度(例如加速或减速)进行概括证明更复杂..

我想这个问题已经被反复解决了,但我似乎无法在网上找到很多线索,所以我的具体问题是是否有人听说过这个问题并可以为我指出正确的方向(或者,更好的是,给我看一个解决方案 :)

谢谢!

4

1 回答 1

0

I would not call it "reverse interpolation" as that does not exists (my first thought was you were talking about extrapolation!). What you are doing is still simply interpolation, just at an uneven rate.

Interpolation: finding a value between known values Extrapolation: finding a value beyond known values

Interpolating to/from constant rates is indeed much much simpler than the generic quest of "finding a value between known values". I propose 2 solutions.

1) Interpolate to a significantly higher rate, and then just sub-sample to the nearest one (try adding dithering)

2) Solve the generic problem: for each point you need to use the neighboring N points and fit a order N-1 polynomial to them.

  • N=2 would be linear and would add overtones (C0 continuity)
  • N=3 could leave you with step changes at the halfway point between your source samples (perhaps worse overtones than N=2!)
  • N=4 will get you C1 continuity (slope will match as you change to the next sample), surely enough for your application.

Let me explain that last one.

For each output sample use the 2 previous and 2 following input samples. Call them S0 to S3 on a unit time scale (multiply by your sample period later), and you are interpolating from time 0 to 1. Y is your output and Y' is the slope.

Y will be calculated from this polynomial and its differential (slope)

    Y(t) = At^3 + Bt^2 + Ct + D
    Y'(t) = 3At^2 + 2Bt + C

The constraints (the values and slope at the endpoints on either side)

    Y(0) = S1
    Y'(0) = (S2-S0)/2
    Y(1) = S2
    Y'(1) = (S3-S1)/2

Expanding the polynomial

    Y(0) = D
    Y'(0) = C
    Y(1) = A+B+C+D
    Y'(1) = 3A+2B+C

Plugging in the Samples

    D = S1
    C = (S2-S0)/2
    A + B = S2 - C - D
    3A+2B = (S3-S1)/2 - C

The last 2 are a system of equations that are easily solvable. Subtract 2x the first from the second.

    3A+2B - 2(A+B)= (S3-S1)/2 - C - 2(S2 - C - D)
    A             = (S3-S1)/2 + C - 2(S2 - D)

Then B is

    B = S2 - A - C - D

Once you have A, B, C and D you can put in an time 't' in the polynomial to find a sample value between your known samples.

Repeat for every output sample, reuse A,B,C&D if the next output sample is still between the same 2 input samples. Calculating t each time is similar to Bresenham's line algorithm, you're just advancing by a different amount each time.

于 2013-12-16T09:33:26.183 回答