我有一个实时信号,一个样品一个样品,我需要对它进行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;
}
}我很清楚线性插值是不好的,但这是我见过的最简单的。我对编码还很陌生,所以在这个阶段,“易于实现”超过了性能。
问候安德鲁
发布于 2014-04-20 16:27:15
您需要向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);
...
}https://stackoverflow.com/questions/23181862
复制相似问题