Beispiel #1
0
void SineFB::oscillateShapeAR(float* outputBuffer, const float* phaseBuffer, const float* shapeBuffer, int bufferSize) noexcept
{
    
    for (int n = 0; n < bufferSize; ++n){

        //fb filtering
        float vn = (fb_path - z1) * alpha;
        fb_path = vn + z1;
        z1 = vn + fb_path;

        //phase offset and rebound
        float phaseOffset = shapeBuffer[n] * fb_path;
        float phase = phaseBuffer[n] +  phaseOffset;

        float floor = floorf(phase);
        phase = phase - floor;

        //linear interpolation and table lookup
        float index_f = phase * tableFakeSize;
        int index_i = static_cast<int>(index_f);
        float fract = index_f - index_i;
        outputBuffer[n] = interpolate_linear(sineTable[index_i], sineTable[index_i + 1], fract);
        fb_path = outputBuffer[n];
    }

}
Beispiel #2
0
void Lattice::interpolate(double* pos, double* value) {
    if (this->interpolation_type == INTERPOLATION_LINEAR) {
        interpolate_linear(pos, value);
    } else {
        runtimeErrorMsg() <<"Unknown interpolation type";
    }
}
Beispiel #3
0
void Lattice::interpolate(double* pos, double* value) {
    if (this->interpolation_type == INTERPOLATION_LINEAR) {
        interpolate_linear(pos, value);
    } else {
        char* c = runtime_error(128);
        ERROR_SPRINTF(c, "Unknown interpolation type");
    }
}
Beispiel #4
0
void SineFB::oscillateShapeCR(float* outputBuffer, const float* phaseBuffer, const float shape, int bufferSize) noexcept
{    
       
    if( shape == 0.0f ){ //we don't need self FM so we don't process the filter
        
        for (int n = 0; n < bufferSize; ++n){
            //linear interpolation and table lookup
            float index_f = phaseBuffer[n] * tableFakeSize;
            int index_i = static_cast<int>(index_f);
            float fract = index_f - index_i;
            outputBuffer[n] = interpolate_linear(sineTable[index_i], sineTable[index_i + 1], fract);
            fb_path = outputBuffer[n];
        }
        
    }else{ //processing also the filter in the fm path
        
        for (int n = 0; n < bufferSize; ++n){

            //fb filtering
            float vn = (fb_path - z1) * alpha;
            fb_path = vn + z1;
            z1 = vn + fb_path;

            //phase offset and rebound
            float phaseOffset = shape * fb_path;
            float phase = phaseBuffer[n] +  phaseOffset;

            float floor = floorf(phase);
            phase = phase - floor;

            //linear interpolation and table lookup
            float index_f = phase * tableFakeSize;
            int index_i = static_cast<int>(index_f);
            float fract = index_f - index_i;
            outputBuffer[n] = interpolate_linear(sineTable[index_i], sineTable[index_i + 1], fract);
            fb_path = outputBuffer[n];
        }                       
            
    }
        
}
float pdsp::LinearInterpolator::interpolate(const float* table, const float &index, const int &tableLen) noexcept {
    
    
     int index_int = static_cast<int> (index);
     float mu = index - index_int;
     float x1 = table[index_int];
     float x2 = table[index_int+1];
     
    return interpolate_linear(x1, x2, mu);
     
    
}
Beispiel #6
0
void pdsp::GrainWindow::process_audio( const float* inputBuffer,  const float* triggerBuffer, int bufferSize) noexcept{
    
    float* outputBuffer = getOutputBufferToFill(output);

    for(int n=0; n<bufferSize; ++n){
        
        
        if(run){
            
            float index = phase*grainShape->length_f;
            int index_int = static_cast<int> (index);
            float mu = index - index_int;
            float x1 = grainShape->buffer[index_int];
            float x2 = grainShape->buffer[index_int+1];
            float winAmp = interpolate_linear(x1, x2, mu);
           
            //float winAmp = interpolatorShell.interpolate(grainShape->buffer, phase*grainShape->length_f, grainShape->length);
            windowMeter.store(winAmp);
           
            if(signalAR){
                outputBuffer[n] = inputBuffer[n] * winAmp;
            }else{
                outputBuffer[n] = inputBuffer[0] * winAmp;                
            }
            
        }else{
            outputBuffer[n] = 0.0f;
        }
        
        phase+=baseInc;
        if(phase>=1.0f){ run = false; }

        if(triggerAR){
            if(checkTrigger(triggerBuffer[n])){
                run = true;
                phase = 0.0f;
            }
        }
        
    }  

}
static void process_file(FILE *fin, FILE *fout, char *infile, char *outfile) {
  int r;
  greymap_t *gm;
  potrace_bitmap_t *bm;
  void *sm;
  int x, y;
  int count;

  for (count=0; ; count++) {
    r = gm_read(fin, &gm);
    switch (r) {
    case -1:  /* system error */
      fprintf(stderr, "mkbitmap: %s: %s\n", infile, strerror(errno));
      exit(2);
    case -2:  /* corrupt file format */
      fprintf(stderr, "mkbitmap: %s: file format error: %s\n", infile, gm_read_error);
      exit(2);
    case -3:  /* empty file */
      if (count>0) {  /* end of file */
	return;
      }
      fprintf(stderr, "mkbitmap: %s: empty file\n", infile);
      exit(2);
    case -4:  /* wrong magic */
      if (count>0) {
	fprintf(stderr, "mkbitmap: %s: warning: junk at end of file\n", infile);
	return;
      }
      fprintf(stderr, "mkbitmap: %s: file format not recognized\n", infile);
      fprintf(stderr, "Possible input file formats are: pnm (pbm, pgm, ppm), bmp.\n");
      exit(2);
    case 1:  /* unexpected end of file */
      fprintf(stderr, "mkbitmap: %s: warning: premature end of file\n", infile);
      break;
    }
    
    if (info.invert) {
      for (y=0; y<gm->h; y++) {
	for (x=0; x<gm->w; x++) {
	  GM_UPUT(gm, x, y, 255-GM_UGET(gm, x, y));
	}
      }
    }
    
    if (info.highpass) {
      r = highpass(gm, info.lambda);
      if (r) {
	fprintf(stderr, "mkbitmap: %s: %s\n", infile, strerror(errno));
	exit(2);
      }
    }

    if (info.lowpass) {
      lowpass(gm, info.lambda1);
    }
    
    if (info.scale == 1 && info.bilevel) {  /* no interpolation necessary */
      sm = threshold(gm, info.level);
      gm_free(gm);
    } else if (info.scale == 1) {
      sm = gm;
    } else if (info.linear) {  /* linear interpolation */
      sm = interpolate_linear(gm, info.scale, info.bilevel, info.level);
      gm_free(gm);
    } else {  /* cubic interpolation */
      sm = interpolate_cubic(gm, info.scale, info.bilevel, info.level);
      gm_free(gm);
    }
    if (!sm) {
      fprintf(stderr, "mkbitmap: %s: %s\n", infile, strerror(errno));
      exit(2);
    }
    
    if (info.bilevel) {
      bm = (potrace_bitmap_t *)sm;
      bm_writepbm(fout, bm);
      bm_free(bm);
    } else {
      gm = (greymap_t *)sm;
      gm_writepgm(fout, gm, NULL, 1, GM_MODE_POSITIVE, 1.0);
      gm_free(gm);
    }
  }
}
Beispiel #8
0
static inline
auto lerp(const T& a, const T& b, C coef) {
	return interpolate_linear(a, b, coef);
}
Beispiel #9
0
int main() {

	double xx[100],yy[100];
	float ff[100];
	double x,y,z;
	float f;
	long index;
	long i,j;
	Vector v, normal, position, angle;

	printf("\n");
	printf("-------------------------------------\n");
	printf("    PhoSim Unit Testing Framework\n");
	printf("-------------------------------------\n\n");
	for (i=0;i<100;i++) xx[i]=((double)i)/100.0;
	for (i=0;i<100;i++) yy[i]=((double)i)/100.0;
	for (i=0;i<100;i++) ff[i]=((double)i)/100.0;


	find(xx,100,0.601,&index);
	unitTestOutput(index,60,"find","Index finding","none");

	index=find_linear(xx,100,0.601,&x);
	unitTestOutput(index,60,"findLinear","Index finding","none");

	find_linear_wrap(1.0,0.1,100,&i,&j,&x);
	unitTestOutput(j,60,"findLinearWrap","Index finding","none");

	x=1.0; y=1.0; z=0.0;
	normalize(&x,&y,&z);
	unitTestOutput(x,1.0/sqrt(2.0),"normalize","Normalize vector","none");

	x=interpolate(yy,xx,0.605,60);
	unitTestOutput(x,0.605,"interpolate","Interpolate array","none");

	x=interpolate_linear(yy,60,60.5);
	unitTestOutput(x,0.605,"interpolateLinear","Interpolate array","none");

	x=interpolate_bilinear(yy,0,0,0.0,60,60.5);
	unitTestOutput(x,0.605,"interpolateBilinear","Interpolate 2-D array","none");

	f=interpolate_bilinear_float_wrap(ff,0,0,1,0.0,60,61,0.5);
	unitTestOutput((double)f,0.605,"interpolateBilinearFloatWrap","Interpolate 2-D array","none");

	v.x=0.0; v.y=1.0/sqrt(2.0); v.z=-1.0/sqrt(2.0);
	normal.x=0.0; normal.y=0.0; normal.z=1.0;
	reflect(&v,normal);
	unitTestOutput(v.z,1/sqrt(2.0),"reflect","Ray component after reflection","none");

	v.x=0.0; v.y=1.0/sqrt(2.0); v.z=-1.0/sqrt(2.0);
	normal.x=0.0; normal.y=0.0; normal.z=1.0;
	refract(&v,normal,1.0,2.0);
	unitTestOutput(v.y,1/sqrt(2.0)/2.0,"refract","Ray component after snell's law","none");

	position.x=0.; position.y=0.; position.z=0.;
	angle.x=0; angle.y=1/sqrt(2.0); angle.z=1/sqrt(2.0);
	propagate(&position,angle,sqrt(2.0));
	unitTestOutput(position.y,1.0,"propagate","Ray position after propagation","none");

	return(0);
}