首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >处理线性上采样音频阵列

处理线性上采样音频阵列
EN

Stack Overflow用户
提问于 2014-04-20 12:15:45
回答 1查看 365关注 0票数 0

我有一个实时信号,一个样品一个样品,我需要对它进行4倍的重采样。我有musicdsp.org的这门课:

代码语言:javascript
复制
#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

我想上面的说法是正确的。现在的问题是如何单独返回数组元素?

代码语言:javascript
复制
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;


    }

    }

我很清楚线性插值是不好的,但这是我见过的最简单的。我对编码还很陌生,所以在这个阶段,“易于实现”超过了性能。

问候安德鲁

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-20 16:27:15

您需要向process4提供一个缓冲区,它可以容纳4个浮点值。其次,您需要实例化interpolater_linear才能使用它。

代码语言:javascript
复制
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);
    ...
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23181862

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档