处理线性上采样音频阵列

Handling linear upsampling audio array

本文关键字:音频 阵列 采样 线性 处理      更新时间:2023-10-16

我有一个实时信号,一个样本接一个样本,我需要对它进行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;

    }
    }

第页。S.我很清楚线性插值是不好的,但它是我见过的最简单的。我对编码还很陌生,所以在这个阶段,"实现的容易性"胜过性能。

问候Andrew

您需要为process4提供一个缓冲区,该缓冲区可以容纳4个浮点值。其次,您需要实例化interpoler_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);
    ...
}