void AnimationPath::CubicInterpolatePath(float& increment, int& iter, DataPointListF& DPLF, DataPointList& NewDPL) { float mu = 0; for(; mu < 1; mu += increment) { float newValue; //repeat element 0 as element -1 for first element if(iter == 0) newValue = CubicInterpolate(mu, DPLF[iter].value, DPLF[iter].value, DPLF[iter+1].value, DPLF[iter+2].value); //repeat element n+1 as element n+2 for second to last element else if(iter == (int)(DPLF.size()- 2)) newValue = CubicInterpolate(mu, DPLF[iter-1].value, DPLF[iter].value, DPLF[iter+1].value, DPLF[iter+1].value); //standard interpolation else newValue = CubicInterpolate(mu, DPLF[iter-1].value, DPLF[iter].value, DPLF[iter+1].value, DPLF[iter+2].value); DataPoint dp; dp.value = Utils::ToString(newValue); dp.interpType = DPLF[iter].interpType; dp.time = DPLF[iter].time; NewDPL.push_back(dp); } }
kmVec3* kmVec3CatmullRom(kmVec3* pOut, const kmVec3* v1, const kmVec3* v2, const kmVec3* v3, const kmVec3* v4, const kmScalar t) { kmVec3Fill(pOut, CubicInterpolate(v1->x, v2->x, v3->x, v4->x, t), CubicInterpolate(v1->y, v2->y, v3->y, v4->y, t), CubicInterpolate(v1->z, v2->z, v3->z, v4->z, t)); return pOut; }
void drawBars(const intComplex *data, struct spectrum_object_t *sobj, SDL_Surface *screen){ int c = 0, vpos; unsigned char *cc = (unsigned char*)&c; SDL_LockSurface(screen); for(int px=0; px<sobj->pos.w; px++){ int vpos = sobj->vpos[px]; float t = sobj->ppos[px]; if (vpos>=sobj->samplelen) return; float f0 = data[vpos+0].re; //* scale; float f1 = data[vpos+1].re; //* scale; float f2 = data[vpos+2].re; //* scale; float f3 = data[vpos+3].re; //* scale; float h = fabs(CubicInterpolate(f0, f1, f2, f3, t) / 65536.)*(float)sobj->pos.h; for(int py=0; py<sobj->pos.h; py++){ if(py<h){ cc[2] = (py * 255) / sobj->pos.h; cc[1] = 255 - (py * 255) / sobj->pos.h; cc[0] = 0x00; cc[3] = 0xff; } else c = 0x0; putpixel(screen, sobj->pos.x+px, sobj->pos.y+(sobj->pos.h-py), c); } } SDL_UnlockSurface(screen); }
void InverseWarpLine(float src[], float dst[], float disp[], int w, int n_bands, int order, float *fwd_disp, float disp_gap) { // Inverse warp a single line for (int x = 0; x < w ; x++, dst += n_bands) { // Warped (source) location float d = disp[x]; float y = x - d; if (y < 0.0 || y > w-1) continue; // Check for occlusion/gap int xx = int(y); if (fwd_disp && disp_gap && fabs(d - fwd_disp[xx]) >= disp_gap) continue; // Resampling float *ps0 = &src[xx * n_bands]; if (order == 0 || xx == y) memcpy(dst, ps0, n_bands*sizeof(float)); else if (order == 1 || xx-1 < 0 || xx+2 > w-1) { // Linear interpolation float f = y - xx; float *ps1 = &ps0[n_bands]; for (int b = 0; b < n_bands; b++) { float v = ps0[b] + f * (ps1[b] - float(ps0[b])); dst[b] = v; } } else if (order == 3) { // Cubic interpolation float f = y - xx; float *psp = &ps0[-n_bands]; float *ps1 = &ps0[n_bands]; float *ps2 = &ps0[2*n_bands]; for (int b = 0; b < n_bands; b++) { float v = CubicInterpolate(f, (float) psp[b], (float) ps0[b], (float) ps1[b], (float) ps2[b]); dst[b] = v; } } else throw CError("InverseWarp: order = %d not implemented", order); } }
NOISE_DATATYPE cNoise::CubicNoise2D(NOISE_DATATYPE a_X, NOISE_DATATYPE a_Y) const { const int BaseX = FAST_FLOOR(a_X); const int BaseY = FAST_FLOOR(a_Y); const NOISE_DATATYPE points[4][4] = { { IntNoise2D(BaseX - 1, BaseY - 1), IntNoise2D(BaseX, BaseY - 1), IntNoise2D(BaseX + 1, BaseY - 1), IntNoise2D(BaseX + 2, BaseY - 1), }, { IntNoise2D(BaseX - 1, BaseY), IntNoise2D(BaseX, BaseY), IntNoise2D(BaseX + 1, BaseY), IntNoise2D(BaseX + 2, BaseY), }, { IntNoise2D(BaseX - 1, BaseY + 1), IntNoise2D(BaseX, BaseY + 1), IntNoise2D(BaseX + 1, BaseY + 1), IntNoise2D(BaseX + 2, BaseY + 1), }, { IntNoise2D(BaseX - 1, BaseY + 2), IntNoise2D(BaseX, BaseY + 2), IntNoise2D(BaseX + 1, BaseY + 2), IntNoise2D(BaseX + 2, BaseY + 2), }, }; const NOISE_DATATYPE FracX = a_X - BaseX; const NOISE_DATATYPE interp1 = CubicInterpolate(points[0][0], points[0][1], points[0][2], points[0][3], FracX); const NOISE_DATATYPE interp2 = CubicInterpolate(points[1][0], points[1][1], points[1][2], points[1][3], FracX); const NOISE_DATATYPE interp3 = CubicInterpolate(points[2][0], points[2][1], points[2][2], points[2][3], FracX); const NOISE_DATATYPE interp4 = CubicInterpolate(points[3][0], points[3][1], points[3][2], points[3][3], FracX); const NOISE_DATATYPE FracY = a_Y - BaseY; return CubicInterpolate(interp1, interp2, interp3, interp4, FracY); }
float SpectrumAnalyst::GetProcessedValue(float freq0, float freq1) const { float bin0, bin1, binwidth; if (mAlg == Spectrum) { bin0 = freq0 * mWindowSize / mRate; bin1 = freq1 * mWindowSize / mRate; } else { bin0 = freq0 * mRate; bin1 = freq1 * mRate; } binwidth = bin1 - bin0; float value = float(0.0); if (binwidth < 1.0) { float binmid = (bin0 + bin1) / 2.0; int ibin = (int)(binmid) - 1; if (ibin < 1) ibin = 1; if (ibin >= GetProcessedSize() - 3) ibin = std::max(0, GetProcessedSize() - 4); value = CubicInterpolate(mProcessed[ibin], mProcessed[ibin + 1], mProcessed[ibin + 2], mProcessed[ibin + 3], binmid - ibin); } else { if (bin0 < 0) bin0 = 0; if (bin1 >= GetProcessedSize()) bin1 = GetProcessedSize() - 1; if ((int)(bin1) > (int)(bin0)) value += mProcessed[(int)(bin0)] * ((int)(bin0) + 1 - bin0); bin0 = 1 + (int)(bin0); while (bin0 < (int)(bin1)) { value += mProcessed[(int)(bin0)]; bin0 += 1.0; } value += mProcessed[(int)(bin1)] * (bin1 - (int)(bin1)); value /= binwidth; } return value; }
// for Chugins extending UGen SAMPLE tick ( SAMPLE in ) { // default: this passes whatever input is patched into Chugin if (sync == 0) { if (in > 0) { freq = in; step = table_size * freq / srate; } table_pos += step; } else if (sync == 1) table_pos = table_size * in; while (table_pos > table_size) table_pos -= table_size; int y0, y1, y2, y3; y0 = (int) table_pos; y1 = (y0 + 1) % table_size; y2 = (y0 + 2) % table_size; y3 = (y0 + 3) % table_size; if (interpolate==1) { return LinearInterpolate(current_table[y0], current_table[y1], table_pos - y0); } else if (interpolate==2) { return LagrangeInterpolate(current_table[y0], current_table[y1], current_table[y2], current_table[y3], table_pos - y0); } if (interpolate==3) { return CubicInterpolate(current_table[y0], current_table[y1], current_table[y2], current_table[y3], table_pos - y0); } else if (interpolate==4) { return HermiteInterpolate(current_table[y0], current_table[y1], current_table[y2], current_table[y3], table_pos - y0); } return current_table[y0]; }
float FreqWindow::GetProcessedValue(float freq0, float freq1) { int alg = mAlgChoice->GetSelection(); float bin0, bin1, binwidth; if (alg == 0) { bin0 = freq0 * mWindowSize / mRate; bin1 = freq1 * mWindowSize / mRate; } else { bin0 = freq0 * mRate; bin1 = freq1 * mRate; } binwidth = bin1 - bin0; float value = float(0.0); if (binwidth < 1.0) { float binmid = (bin0 + bin1) / 2.0; int ibin = int (binmid) - 1; if (ibin < 1) ibin = 1; if (ibin >= mProcessedSize - 3) ibin = mProcessedSize - 4; value = CubicInterpolate(mProcessed[ibin], mProcessed[ibin + 1], mProcessed[ibin + 2], mProcessed[ibin + 3], binmid - ibin); } else { if (int (bin1) > int (bin0)) value += mProcessed[int (bin0)] * (int (bin0) + 1 - bin0); bin0 = 1 + int (bin0); while (bin0 < int (bin1)) { value += mProcessed[int (bin0)]; bin0 += 1.0; } value += mProcessed[int (bin1)] * (bin1 - int (bin1)); value /= binwidth; } return value; }
int drawSpectogram(const complex *data, struct spectogram_object_t *sobj, SDL_Surface *screen){ int c = 0, vpos; unsigned char *cc = &sobj->screenBuffer[sobj->pos.h*sobj->time]; float _samplerate = (float)sobj->samplerate; // todo ... float freq = 0.0, ppos = 0.0, t = 0.0; float fft_freqstep = 1./(float) sobj->samplerate; float freqstep = 3./(float)sobj->pos.h; // 10^4 nagysagrendig megyunk float scale = 15./((float)(sobj->samplelen)); for(int py=0; py<sobj->pos.h; py++){ freq = 20.*pow(10,(float)(py)*freqstep); ppos = (float)(sobj->samplelen-4) * freq * fft_freqstep; vpos = (int)floor(ppos); t = ppos - (float)vpos; if (vpos>=sobj->samplelen) return (sobj->time+1)%sobj->pos.w; float f0 = data[vpos+0].re * scale, f1 = data[vpos+1].re * scale, f2 = data[vpos+2].re * scale, f3 = data[vpos+3].re * scale; float f = fabs(CubicInterpolate(f0, f1, f2, f3, t)); f = (f>1.)?1.:f; f = (f<0.)?0.:f; cc[py] = (unsigned char)(f * 255); } SDL_LockSurface(screen); unsigned int color; cc = (unsigned char*)&color; int i; unsigned char k; for(int x = 0; x<sobj->pos.w; ++x) for(int y = 0; y<sobj->pos.h; ++y){ i = x*sobj->pos.h+y; k = sobj->screenBuffer[i]; cc[0] = k; cc[2] = k; cc[1] = k; cc[3] = 0xff; putpixel(screen, sobj->pos.x+x, sobj->pos.y+(sobj->pos.h-y), color); } SDL_UnlockSurface(screen); sobj->time = (sobj->time+1)%sobj->pos.w; return 1; }
double InterpolatorValue(interpolator_t *interpolator, int subchannel, char *valid) { // Check for invalid if (!interpolator->valid || interpolator->seg == NULL || subchannel < 0 || subchannel >= interpolator->seg->channels) { if (valid != NULL) { *valid = 0; } return 0.0; } //if (t >= interpolator->seg->startTime) double val; if (interpolator->mode == 1) { val = NearestInterpolate(interpolator->values[1][subchannel], interpolator->values[2][subchannel], interpolator->prop); } else if (interpolator->mode == 2) { val = LinearInterpolate(interpolator->values[1][subchannel], interpolator->values[2][subchannel], interpolator->prop); } else if (interpolator->mode == 3) { val = CubicInterpolate(interpolator->values[0][subchannel], interpolator->values[1][subchannel], interpolator->values[2][subchannel], interpolator->values[3][subchannel], interpolator->prop); } else { val = 0.0; } if (valid != NULL) { *valid = 1; } return val; }
NOISE_DATATYPE cNoise::CubicNoise3D(NOISE_DATATYPE a_X, NOISE_DATATYPE a_Y, NOISE_DATATYPE a_Z) const { const int BaseX = FAST_FLOOR(a_X); const int BaseY = FAST_FLOOR(a_Y); const int BaseZ = FAST_FLOOR(a_Z); const NOISE_DATATYPE points1[4][4] = { { IntNoise3D(BaseX - 1, BaseY - 1, BaseZ - 1), IntNoise3D(BaseX, BaseY - 1, BaseZ - 1), IntNoise3D(BaseX + 1, BaseY - 1, BaseZ - 1), IntNoise3D(BaseX + 2, BaseY - 1, BaseZ - 1), }, { IntNoise3D(BaseX - 1, BaseY, BaseZ - 1), IntNoise3D(BaseX, BaseY, BaseZ - 1), IntNoise3D(BaseX + 1, BaseY, BaseZ - 1), IntNoise3D(BaseX + 2, BaseY, BaseZ - 1), }, { IntNoise3D(BaseX - 1, BaseY + 1, BaseZ - 1), IntNoise3D(BaseX, BaseY + 1, BaseZ - 1), IntNoise3D(BaseX + 1, BaseY + 1, BaseZ - 1), IntNoise3D(BaseX + 2, BaseY + 1, BaseZ - 1), }, { IntNoise3D(BaseX - 1, BaseY + 2, BaseZ - 1), IntNoise3D(BaseX, BaseY + 2, BaseZ - 1), IntNoise3D(BaseX + 1, BaseY + 2, BaseZ - 1), IntNoise3D(BaseX + 2, BaseY + 2, BaseZ - 1), }, }; const NOISE_DATATYPE FracX = (a_X) - BaseX; const NOISE_DATATYPE x1interp1 = CubicInterpolate( points1[0][0], points1[0][1], points1[0][2], points1[0][3], FracX ); const NOISE_DATATYPE x1interp2 = CubicInterpolate( points1[1][0], points1[1][1], points1[1][2], points1[1][3], FracX ); const NOISE_DATATYPE x1interp3 = CubicInterpolate( points1[2][0], points1[2][1], points1[2][2], points1[2][3], FracX ); const NOISE_DATATYPE x1interp4 = CubicInterpolate( points1[3][0], points1[3][1], points1[3][2], points1[3][3], FracX ); const NOISE_DATATYPE points2[4][4] = { { IntNoise3D( BaseX-1, BaseY-1, BaseZ ), IntNoise3D( BaseX, BaseY-1, BaseZ ), IntNoise3D( BaseX+1, BaseY-1, BaseZ ), IntNoise3D( BaseX+2, BaseY-1, BaseZ ), }, { IntNoise3D( BaseX-1, BaseY, BaseZ ), IntNoise3D( BaseX, BaseY, BaseZ ), IntNoise3D( BaseX+1, BaseY, BaseZ ), IntNoise3D( BaseX+2, BaseY, BaseZ ), }, { IntNoise3D( BaseX-1, BaseY+1, BaseZ ), IntNoise3D( BaseX, BaseY+1, BaseZ ), IntNoise3D( BaseX+1, BaseY+1, BaseZ ), IntNoise3D( BaseX+2, BaseY+1, BaseZ ), }, { IntNoise3D( BaseX-1, BaseY+2, BaseZ ), IntNoise3D( BaseX, BaseY+2, BaseZ ), IntNoise3D( BaseX+1, BaseY+2, BaseZ ), IntNoise3D( BaseX+2, BaseY+2, BaseZ ), }, }; const NOISE_DATATYPE x2interp1 = CubicInterpolate( points2[0][0], points2[0][1], points2[0][2], points2[0][3], FracX ); const NOISE_DATATYPE x2interp2 = CubicInterpolate( points2[1][0], points2[1][1], points2[1][2], points2[1][3], FracX ); const NOISE_DATATYPE x2interp3 = CubicInterpolate( points2[2][0], points2[2][1], points2[2][2], points2[2][3], FracX ); const NOISE_DATATYPE x2interp4 = CubicInterpolate( points2[3][0], points2[3][1], points2[3][2], points2[3][3], FracX ); const NOISE_DATATYPE points3[4][4] = { { IntNoise3D( BaseX-1, BaseY-1, BaseZ+1 ), IntNoise3D( BaseX, BaseY-1, BaseZ+1 ), IntNoise3D( BaseX+1, BaseY-1, BaseZ+1 ), IntNoise3D( BaseX+2, BaseY-1, BaseZ + 1), }, { IntNoise3D( BaseX-1, BaseY, BaseZ+1 ), IntNoise3D( BaseX, BaseY, BaseZ+1 ), IntNoise3D( BaseX+1, BaseY, BaseZ+1 ), IntNoise3D( BaseX+2, BaseY, BaseZ + 1), }, { IntNoise3D( BaseX-1, BaseY+1, BaseZ+1 ), IntNoise3D( BaseX, BaseY+1, BaseZ+1 ), IntNoise3D( BaseX+1, BaseY+1, BaseZ+1 ), IntNoise3D( BaseX+2, BaseY+1, BaseZ + 1), }, { IntNoise3D( BaseX-1, BaseY+2, BaseZ+1 ), IntNoise3D( BaseX, BaseY+2, BaseZ+1 ), IntNoise3D( BaseX+1, BaseY+2, BaseZ+1 ), IntNoise3D( BaseX+2, BaseY+2, BaseZ + 1), }, }; const NOISE_DATATYPE x3interp1 = CubicInterpolate( points3[0][0], points3[0][1], points3[0][2], points3[0][3], FracX ); const NOISE_DATATYPE x3interp2 = CubicInterpolate( points3[1][0], points3[1][1], points3[1][2], points3[1][3], FracX ); const NOISE_DATATYPE x3interp3 = CubicInterpolate( points3[2][0], points3[2][1], points3[2][2], points3[2][3], FracX ); const NOISE_DATATYPE x3interp4 = CubicInterpolate( points3[3][0], points3[3][1], points3[3][2], points3[3][3], FracX ); const NOISE_DATATYPE points4[4][4] = { { IntNoise3D( BaseX-1, BaseY-1, BaseZ+2 ), IntNoise3D( BaseX, BaseY-1, BaseZ+2 ), IntNoise3D( BaseX+1, BaseY-1, BaseZ+2 ), IntNoise3D( BaseX+2, BaseY-1, BaseZ+2 ), }, { IntNoise3D( BaseX-1, BaseY, BaseZ+2 ), IntNoise3D( BaseX, BaseY, BaseZ+2 ), IntNoise3D( BaseX+1, BaseY, BaseZ+2 ), IntNoise3D( BaseX+2, BaseY, BaseZ+2 ), }, { IntNoise3D( BaseX-1, BaseY+1, BaseZ+2 ), IntNoise3D( BaseX, BaseY+1, BaseZ+2 ), IntNoise3D( BaseX+1, BaseY+1, BaseZ+2 ), IntNoise3D( BaseX+2, BaseY+1, BaseZ+2 ), }, { IntNoise3D( BaseX-1, BaseY+2, BaseZ+2 ), IntNoise3D( BaseX, BaseY+2, BaseZ+2 ), IntNoise3D( BaseX+1, BaseY+2, BaseZ+2 ), IntNoise3D( BaseX+2, BaseY+2, BaseZ+2 ), }, }; const NOISE_DATATYPE x4interp1 = CubicInterpolate( points4[0][0], points4[0][1], points4[0][2], points4[0][3], FracX ); const NOISE_DATATYPE x4interp2 = CubicInterpolate( points4[1][0], points4[1][1], points4[1][2], points4[1][3], FracX ); const NOISE_DATATYPE x4interp3 = CubicInterpolate( points4[2][0], points4[2][1], points4[2][2], points4[2][3], FracX ); const NOISE_DATATYPE x4interp4 = CubicInterpolate( points4[3][0], points4[3][1], points4[3][2], points4[3][3], FracX ); const NOISE_DATATYPE FracY = (a_Y) - BaseY; const NOISE_DATATYPE yinterp1 = CubicInterpolate( x1interp1, x1interp2, x1interp3, x1interp4, FracY ); const NOISE_DATATYPE yinterp2 = CubicInterpolate( x2interp1, x2interp2, x2interp3, x2interp4, FracY ); const NOISE_DATATYPE yinterp3 = CubicInterpolate( x3interp1, x3interp2, x3interp3, x3interp4, FracY ); const NOISE_DATATYPE yinterp4 = CubicInterpolate( x4interp1, x4interp2, x4interp3, x4interp4, FracY ); const NOISE_DATATYPE FracZ = (a_Z) - BaseZ; return CubicInterpolate( yinterp1, yinterp2, yinterp3, yinterp4, FracZ ); }
NOISE_DATATYPE cNoise::CubicNoise1D(NOISE_DATATYPE a_X) const { int BaseX = FAST_FLOOR(a_X); NOISE_DATATYPE FracX = a_X - BaseX; return CubicInterpolate(IntNoise1D(BaseX - 1), IntNoise1D(BaseX), IntNoise1D(BaseX + 1), IntNoise1D(BaseX + 2), FracX); }