c++ - Handling linear upsampling audio array -


i have real-time signal coming in sample sample, need 4x upsampling on it. have class 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 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 

i assume above correct. question how return array elements individually?

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 call here?  interpolator_linear::process4(input, should here??);  ////i need seperate out arrays elements 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 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. aware linear interpolation bad, it's simplest i've seen. , i'm new coding 'ease of implementation' trumps performance @ stage.

regards andrew

you need provide buffer process4 can hold 4 floating point values. secondly, need instantiate interpolater_linear in order use it.

interpolator_linear interp; // you'll want make member of td_osclip.  float out[4]; for( int s = sampleframes; s > 0; --s ) {     float input = *in;      interp.process4(input, out);     ... } 

Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -