2014-04-20 2 views
0

샘플로 샘플에 들어오는 실시간 신호가 있고, 4x 업 샘플링이 필요합니다. 나는이 수업을 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. 선형 보간법이 좋지 않다는 것을 잘 알고 있지만, 내가 본 것은 가장 간단합니다. 그리고 코딩의 새 기능이므로이 단계에서 '구현의 용이성'이 성능보다 우수합니다.

감사 앤드류

+0

"배열 요소를 개별적으로 반환"하는 것이 명확하지 않습니다. –

+0

나는 out [0], out [1], out [2], out [3]을 필요로합니다. 클래스는 단지 포인터라고 생각합니다. –

답변

1

당신은 4 개 부동 소수점 값을 보유 할 수있는 process4하는 버퍼를 제공해야합니다. 둘째, 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); 
    ... 
} 
+0

이제 새로운 오류가 발생합니다 : 객체가없는 멤버 함수 'void interpolator_linear :: process4x (float, float *) ...를 호출 할 수 없습니다. 나는 그것을 얻지 않는다, 그렇지 않다 -> 떠 다니고 [4]; 벌써? –

+0

@ ichad.c 편집 된 답변보기. – jaket

+0

돌 하나가 두 마리, 뛰어남. 고마워요! –

관련 문제