我有样本的实时信号,我需要对其进行4倍上采样。我有来自musicdsp.org的这个课程:
#ifndef TD_INTERPOLATOR_H_INCLUDED
#define TD_INTERPOLATOR_H_INCLUDED
/************************************************************************
* Linear interpolator class *
************************************************************************/
class interpolator_linear
{
public:
interpolator_linear() {
reset_hist();
}
// reset history
void reset_hist() {
d1 = 0.f;
}
// 4x interpolator
// out: pointer to float[4]
inline void process4x(float const in, float *out) {
float y = in-d1;
out[0] = d1 + 0.25f*y; // interpolate
out[1] = d1 + 0.5f*y;
out[2] = d1 + 0.75f*y;
out[3] = in;
d1 = in; // store delay
}
}
private:
float d1; // previous input
};
#endif // TD_INTERPOLATOR_H_INCLUDED
我认为以上是正确的。现在的问题是如何单独返回数组元素?
void TD_OSclip::subProcessClip4( int bufferOffset, int sampleFrames )
{
float* in = bufferOffset + pinInput.getBuffer();
float* outputt = bufferOffset + pinOutput.getBuffer();
for( int s = sampleFrames; s > 0; --s )
{
float input = *in;
//upsample 4x Linear --How should I call it here?
interpolator_linear::process4(input, what should be here??);
////I need all the seperate out arrays elements for the next stage
//do process
float clip = 0.5f;
float neg_clip = -0.5f;
float out0 = std::max( neg_clip, std::min( clip, out[0] ) );
float out1 = std::max( neg_clip, std::min( clip, out[1] ) );
float out2 = std::max( neg_clip, std::min( clip, out[2] ) );
float out3 = std::max( neg_clip, std::min( clip, out[3] ) );
//lowpass filter ommitted for briefness
float out0f = out0;
float out1f = out0;
float out2f = out0;
float out3f = out0;
//downsample
float output1 = ( out0f + out1f + out2f + out3f ) / 4.f;
*outputt = output1;
++in;
++outputt;
}
}
P.S。我很清楚线性插值很糟糕,但它是我见过的最简单的插值。而且我对编码很陌生,所以“易于实施”在这个阶段胜过性能。
此致 安德鲁
答案 0 :(得分:1)
您需要为process4提供一个缓冲区,它可以容纳4个浮点值。 其次,您需要实例化interpolater_linear才能使用它。
interpolator_linear interp; // you'll want to make this a member of TD_OSclip.
float out[4];
for( int s = sampleFrames; s > 0; --s )
{
float input = *in;
interp.process4(input, out);
...
}