Mat ColorMap::linear_colormap(InputArray X, InputArray r, InputArray g, InputArray b, InputArray xi) { Mat lut, lut8; Mat planes[] = { interp1(X, b, xi), interp1(X, g, xi), interp1(X, r, xi)}; merge(planes, 3, lut); lut.convertTo(lut8, CV_8U, 255.); return lut8; }
Solution VDSpiral (SpiralParams& sp) { GradientParams gp; Matrix<double>& fov = sp.fov; Matrix<double>& rad = sp.rad; double k_max, fov_max, dr; Matrix<double> r, theta; long n = 0; assert (numel(rad) >= 2); assert (isvec(rad) == isvec(fov)); assert (numel(rad) == numel(fov)); k_max = 5.0 / sp.res; fov_max = m_max(fov); dr = sp.shots / (fov_max); n = size(fov,1)*100; r = linspace<double> (0.0, k_max, n); Matrix<double> x = k_max*rad; fov = interp1 (x, fov, r, INTERP::LINEAR); dr = sp.shots / (1500.0 * fov_max); n = ceil (k_max/dr); x = r; r = linspace<double> (0.0, k_max, n); fov = interp1 (x, fov, r, INTERP::AKIMA); theta = cumsum ((2 * PI * dr / sp.shots) * fov); gp.k = Matrix<double> (numel(r), 3); for (size_t i = 0; i < numel(r); i++) { gp.k(i,0) = r[i] * cos (theta[i]); gp.k(i,1) = r[i] * sin (theta[i]); } gp.mgr = sp.mgr; gp.msr = sp.msr; gp.dt = sp.dt; gp.gunits = sp.gunits; gp.lunits = sp.lunits; Solution s = ComputeGradient (gp); return s; }
void main() { int m, n, i; float xp[50], yp[50]; float x[50], y[50]; system("cls"); //Accepting data printf("Enter the number of elements in x and y: "); scanf("%d", &n); printf("\n\nEnter the elements of x: "); for (i = 0; i < n; i++) scanf("%f", &x[i]); printf("\nEnter the elements of y: "); for (i = 0; i < n; i++) scanf("%f", &y[i]); printf("\nEnter the number of elements in xp: "); scanf("%d", &m); printf("\nEnter the value of xp: "); for (i = 0; i < m; i++) scanf("%f", &xp); //All the necessary values may be passed on to another function 'interp1', where all the necessary calculations may be done. if (m == 1) { yp[0] = interp1(x[0], x[n-1], xp[0], y[0], y[n-1]); //Display the result printf("\n\nResult"); printf("\nyp = \n %f", yp[0]); } else { for (i = 0; i < m-1; i++) { yp[i] = interp1(x[i], x[i+1], xp[i], y[i], y[i+1]); } yp[m-1] = interp1(x[n-1], x[n], xp[m-1], y[n-1], y[n]); //Display the result printf("\n\nResult\nyp = \n"); for (i = 0; i < m; i++) printf("\t%f", yp[i]); } }
template <class T> bool karbtest (Connector<T>* rc) { GradientParams gp; std::string in_file;// = std::string (base + "/" + std::string(rc->GetElement("/config/data-in")->Attribute("fname"))); std::string out_file;// = std::string (base + "/" + rc->GetElement("/config/data-out")->Attribute("fname")); bool simann = false; size_t hpoints = 1; rc->Attribute ("simann", &simann); rc->Attribute ("hpoints", &hpoints); if (simann) { double coolrate, startt, finalt; size_t coolit; bool verbose, exchange; rc->Attribute ("coolrate", &coolrate); rc->Attribute ("startt", &startt); rc->Attribute ("finalt", &finalt); rc->Attribute ("coolit", &coolit); rc->Attribute ("verbose", &verbose); rc->Attribute ("exchange", &exchange); SimulatedAnnealing sa (gp.k, coolit, startt, finalt, coolrate, verbose, exchange); sa.Cool(); gp.k = sa.GetSolution(); } rc->Attribute ("maxgrad", &(gp.mgr)); rc->Attribute ("maxslew", &(gp.msr)); rc->Attribute ("dt", &(gp.dt)); rc->Attribute ("gunits", &(gp.gunits)); rc->Attribute ("lunits", &(gp.lunits)); Matrix<double> x = linspace<double> (0.0,1.0,size(gp.k,0)); Matrix<double> xi = linspace<double> (0.0,1.0,size(gp.k,0)*hpoints); gp.k = interp1 (x, gp.k, xi, INTERP::AKIMA); printf ("\nComputing trajectory for ... \n"); printf (" [maxgrad: %.2f, maxslew: %.2f, dt: %.2e]\n\n", gp.mgr, gp.msr, gp.dt); SimpleTimer st ("VD spiral design"); Solution s = ComputeGradient (gp); st.Stop(); IOContext f = fopen (out_file.c_str(), WRITE); s.dump (f); fclose (f); return true; }
void D4C(const double *x, int x_length, int fs, const double *time_axis, const double *f0, int f0_length, int fft_size, const D4COption *option, double **aperiodicity) { int fft_size_d4c = static_cast<int>(pow(2.0, 1.0 + static_cast<int>(log(4.0 * fs / world::kFloorF0 + 1) / world::kLog2))); ForwardRealFFT forward_real_fft = {0}; InitializeForwardRealFFT(fft_size_d4c, &forward_real_fft); int number_of_aperiodicities = static_cast<int>(MyMinDouble(world::kUpperLimit, fs / 2.0 - world::kFrequencyInterval) / world::kFrequencyInterval); // Since the window function is common in D4CGeneralBody(), // it is designed here to speed up. int window_length = static_cast<int>(world::kFrequencyInterval * fft_size_d4c / fs) * 2 + 1; double *window = new double[window_length]; NuttallWindow(window_length, window); double *coarse_aperiodicity = new double[number_of_aperiodicities + 2]; coarse_aperiodicity[0] = -60.0; coarse_aperiodicity[number_of_aperiodicities + 1] = 0.0; double *coarse_frequency_axis = new double[number_of_aperiodicities + 2]; for (int i = 0; i <= number_of_aperiodicities; ++i) coarse_frequency_axis[i] = static_cast<double>(i) * world::kFrequencyInterval; coarse_frequency_axis[number_of_aperiodicities + 1] = fs / 2.0; double *frequency_axis = new double[fft_size / 2 + 1]; for (int i = 0; i <= fft_size / 2; ++i) frequency_axis[i] = static_cast<double>(i) * fs / fft_size; for (int i = 0; i < f0_length; ++i) { if (f0[i] == 0) { for (int j = 0; j <= fft_size / 2; ++j) aperiodicity[i][j] = 0.0; continue; } D4CGeneralBody(x, x_length, fs, MyMaxDouble(f0[i], world::kFloorF0), fft_size_d4c, time_axis[i], number_of_aperiodicities, window, window_length, &forward_real_fft, &coarse_aperiodicity[1]); // Linear interpolation to convert the coarse aperiodicity into its // spectral representation. interp1(coarse_frequency_axis, coarse_aperiodicity, number_of_aperiodicities + 2, frequency_axis, fft_size / 2 + 1, aperiodicity[i]); for (int j = 0; j <= fft_size / 2; ++j) aperiodicity[i][j] = pow(10.0, aperiodicity[i][j] / 20.0); } DestroyForwardRealFFT(&forward_real_fft); delete[] coarse_frequency_axis; delete[] coarse_aperiodicity; delete[] window; delete[] frequency_axis; }
static void ParameterModification(int argc, char *argv[], int fs, int f0_length, int fft_size, double *f0, double **spectrogram) { // F0 scaling if (argc >= 4) { double shift = atof(argv[3]); for (int i = 0; i < f0_length; ++i) f0[i] *= shift; } if (argc < 5) return; // Spectral stretching double ratio = atof(argv[4]); double *freq_axis1 = (double*) malloc(sizeof(double) * (fft_size)); double *freq_axis2 = (double*) malloc(sizeof(double) * (fft_size)); double *spectrum1 = (double*) malloc(sizeof(double) * (fft_size)); double *spectrum2 = (double*) malloc(sizeof(double) * (fft_size)); for (int i = 0; i <= fft_size / 2; ++i) { freq_axis1[i] = ratio * i / fft_size * fs; freq_axis2[i] = (double)(i) / fft_size * fs; } for (int i = 0; i < f0_length; ++i) { for (int j = 0; j <= fft_size / 2; ++j) spectrum1[j] = log(spectrogram[i][j]); interp1(freq_axis1, spectrum1, fft_size / 2 + 1, freq_axis2, fft_size / 2 + 1, spectrum2); for (int j = 0; j <= fft_size / 2; ++j) spectrogram[i][j] = exp(spectrum2[j]); if (ratio >= 1.0) continue; for (int j = (int)(fft_size / 2.0 * ratio); j <= fft_size / 2; ++j) spectrogram[i][j] = spectrogram[i][(int)(fft_size / 2.0 * ratio) - 1]; } if(spectrum1 != NULL) { free(spectrum1); spectrum1 = NULL; } if(spectrum2 != NULL) { free(spectrum2); spectrum2 = NULL; } if(freq_axis1 != NULL) { free(freq_axis1); freq_axis1 = NULL; } if(freq_axis2 != NULL) { free(freq_axis2); freq_axis2 = NULL; } }
float DLPF::update(float val) { float delta; switch (type) { case DLPF_ANGRATE: delta = fmodf_mpi_pi(val - oldVal); vel = interp1(delta * freq, vel, smooth); oldVal = val; return vel; case DLPF_RATE: delta = val - oldVal; vel = interp1(delta * freq, vel, smooth); oldVal = val; return vel; case DLPF_INTEGRATE: val = smooth * oldVal + val / freq; return val; case DLPF_SMOOTH: default: oldVal = interp1(val, oldVal, smooth); return oldVal; } }
/* * Test 2 * Esta dando diferente el valor yN[0] = 0.012, cuando en matlab da yN[0] = 0.01 .0 * */ void interpVectorTest(){ vector xO = zerov(2); xO.v[0] = 50; xO.v[1] = 200; vector yO = zerov(2); yO.v[0] = 0; yO.v[1] = 0.0018; vector xN = zerov(2); xN.v[0] = 150; xN.v[1] = 600; vector yN = zerov(2); interp1(xO, yO, xN, yN.v); printf("yN:\n"); printv(yN); double yNcurr = interp(xO.v, yO.v, 150, 0); printf("Numero interpolado yNCurr: %f", yNcurr); }
}END_TEST START_TEST(test_correct_code_interp1) { fl64 Yval = 0; fl64 Xmat[9] = { 0, 0.785398163397448, 1.5707963267949, 2.35619449019234, 3.14159265358979, 3.92699081698724, 4.71238898038469, 5.49778714378214, 6.28318530717959 }; fl64 Ymat[9] = { 0, 0.707106781186547, 1, 0.707106781186548, 1.22464679914735e-16, -0.707106781186547, -1, -0.707106781186548, -2.44929359829471e-16 }; fl64 trueVal = 0.973598; //0.9736 si32 sizeXmat = 9; fl64 Xval = 1.5; interp1(&Yval, Xmat, Ymat, sizeXmat, Xval); ck_assert((trueVal-Yval)<DBL_EPSILON); }END_TEST
static void subtract_minimum_envelope(FP_TYPE* x, int nx, FP_TYPE* f0, int nhop, int nfrm, int fs) { int ninstant = 0; int* env_instants = gen_ps_instants(f0, nhop, nfrm, nx, fs, & ninstant); FP_TYPE* fenv_instants = calloc(ninstant, sizeof(FP_TYPE)); int* env_winlen = calloc(ninstant, sizeof(int)); for(int i = 0; i < ninstant; i ++) env_winlen[i] = fs / f0[i]; FP_TYPE* env_samples = llsm_nonuniform_envelope(x, nx, env_instants, env_winlen, ninstant, 0); FP_TYPE* iota = calloc(nx, sizeof(FP_TYPE)); for(int i = 0; i < nx; i ++) iota[i] = i; for(int i = 0; i < ninstant; i ++) fenv_instants[i] = env_instants[i]; FP_TYPE* env = interp1(fenv_instants, env_samples, ninstant, iota, nx); for(int i = 0; i < nx; i ++) x[i] -= env[i]; free(env_instants); free(fenv_instants); free(env_winlen); free(env_samples); free(iota); free(env); }
void QtfeCanal::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); // background painter.drawImage(0,0,*background); // all points QPen pen(Qt::black, pointSizePixel, Qt::SolidLine); painter.setPen(pen); for(int i=0 ; i<list.size() ; ++i) { painter.drawPoint(listPos2WidgetPos(*list[i])); } // points interpolation line pen.setWidth(lineWidth); painter.setPen(pen); qreal x0 = 0.0; qreal y0 = evalf(x0); for(int p=1 ; p < list.size() ; ++p) for(int i=1 ; i <= 10 ; ++i) { qreal x1 = interp1(list[p-1]->x(), list[p]->x(), i/10.0); qreal y1 = evalf(x1); painter.drawLine(listPos2WidgetPos(QPointF(x0, y0)), listPos2WidgetPos(QPointF(x1, y1))); x0 = x1; y0 = y1; } // selected point pen.setColor(Qt::red); painter.setPen(pen); if(selected) { painter.drawEllipse(listPos2WidgetPos(*selected),circleSizePixel,circleSizePixel); } QWidget::paintEvent(event); }
// use armadillos interp1(X, Y, XI, YI) void MRG_interp1(const MRG_MATRIX_REAL & x, const MRG_MATRIX_REAL & y, const MRG_MATRIX_REAL & xi, MRG_MATRIX_REAL & yi) { interp1(x, y, xi, yi); }
//residualSpecgram 波形のコピーが入る。メモリを確保せずに渡す。この関数により必要なメモリが確保される。 //residualSpecgramLength 波形の長さが入る。メモリを確保せずに渡す。この関数により必要なメモリが確保される。 //residualSpecgramIndex 各フレームの波形を指定するインデックスが入る。 //戻り値波形の数(pCount) int pt101(double *x, int xLen, int fs, double *timeAxis, double *f0, double ***residualSpecgram, int **residualSpecgramLength, int *residualSpecgramIndex) { int i, index; double framePeriod = (timeAxis[1]-timeAxis[0])*1000.0; int fftl = (int)pow(2.0, 1.0+(int)(log(3.0*fs/FLOOR_F0+1) / log(2.0))); int tLen = getSamplesForDIO(fs, xLen, framePeriod); int vuvNum; // vuvNum = 0; vuvNum = 1; //tn_fuds for(i = 1;i < tLen;i++) { if(f0[i]!=0.0 && f0[i-1]==0.0) vuvNum++; //無声→有声 if(f0[i]==0.0 && f0[i-1]!=0.0) vuvNum++; //有声→無声 tn_fnds } // vuvNum+=vuvNum-1; // 島数の調整 (有声島と無声島) tn_fnds コメントアウト // if(f0[0] == 0) vuvNum++; tn_fnds コメントアウト // if(f0[tLen-1] == 0) vuvNum++; tn_fnds コメントアウト int stCount, edCount; int *stList, *edList; stList = (int *)malloc(sizeof(int) * vuvNum); edList = (int *)malloc(sizeof(int) * vuvNum); edCount = 0; stList[0] = 0; stCount = 1; index = 1; if(f0[0] != 0) //有声から始まる場合 { for(i = 1;i < tLen;i++) { if(f0[i]==0 && f0[i-1]!=0) //有声→無声 { edList[0] = i-1; edCount++; stList[1] = i; stCount++; index = i; break; //tn_fnds } } } edList[vuvNum-1] = tLen-1; for(i = index;i < tLen;i++) { if(f0[i]!=0.0 && f0[i-1]==0.0) //無声→有声 { edList[edCount++] = i-1; stList[stCount++] = i; } if(f0[i]==0.0 && f0[i-1]!=0.0) //有声→無声 { edList[edCount++] = i-1; stList[stCount++] = i; } } int *wedgeList; wedgeList = (int *)malloc(sizeof(int) * vuvNum); getWedgeList(x, xLen, vuvNum, stList, edList, fs, framePeriod, f0, wedgeList);//島中央のピーク位置を取得 double *signalTime, *f0interpolatedRaw, *totalPhase; double *fixedF0; fixedF0 = (double *)malloc(sizeof(double) * tLen); signalTime = (double *)malloc(sizeof(double) * xLen); f0interpolatedRaw = (double *)malloc(sizeof(double) * xLen); totalPhase = (double *)malloc(sizeof(double) * xLen); for(i = 0;i < tLen;i++) fixedF0[i] = f0[i] == 0 ? DEFAULT_F0 : f0[i]; //F0が0ならデフォルトに補正 for(i = 0;i < xLen;i++) signalTime[i] = (double)i / (double)fs; //サンプル位置の時刻 interp1(timeAxis, fixedF0, tLen, signalTime, xLen, f0interpolatedRaw);//各サンプルのF0 totalPhase[0] = f0interpolatedRaw[0]*2*PI/(double)fs; //各サンプルの位相 for(i = 1;i < xLen;i++) totalPhase[i] = totalPhase[i-1] + f0interpolatedRaw[i]*2*PI/(double)fs; double *pulseLocations; pulseLocations = (double *)malloc(sizeof(double) * xLen); int pCount; pCount = getPulseLocations(x, xLen, totalPhase, vuvNum, stList, edList, fs, framePeriod, wedgeList, pulseLocations);//位相が大きく動くサンプル位置の時刻 //tn_fndsデバッグ //zeroXToFile(x, xLen, f0interpolatedRaw, totalPhase, pCount, pulseLocations, fs, vuvNum, wedgeList); pCount++;//長さ0のダミーパルスを追加 *residualSpecgram = (double **)malloc(sizeof(double *) * pCount); for(i = 0;i < pCount;i++) (*residualSpecgram)[i] = (double *)malloc(sizeof(double) * fftl); *residualSpecgramLength = (int *)malloc(sizeof(int) * pCount); getOnePulseResidualSignal(x, xLen, fs, framePeriod/1000.0, f0, fftl, pulseLocations, pCount, *residualSpecgram, *residualSpecgramLength); getFrameResidualIndex(tLen, pCount, framePeriod/1000, pulseLocations, residualSpecgramIndex); // pulseToFile(pCount, pulseLocations, *residualSpecgramLength); free(fixedF0); free(pulseLocations); free(totalPhase); free(f0interpolatedRaw); free(signalTime); free(wedgeList); free(edList); free(stList); return pCount; }
void pt100(double *x, int xLen, int fs, double *timeAxis, double *f0, double **residualSpecgram) { int i, j, index; double framePeriod = (timeAxis[1]-timeAxis[0])*1000.0; int fftl = (int)pow(2.0, 1.0+(int)(log(3.0*fs/FLOOR_F0+1) / log(2.0))); int tLen = getSamplesForDIO(fs, xLen, framePeriod); int vuvNum; vuvNum = 0; for(i = 1;i < tLen;i++) { if(f0[i]!=0.0 && f0[i-1]==0.0) vuvNum++; } vuvNum+=vuvNum-1; // 島数の調整 (有声島と無声島) if(f0[0] == 0) vuvNum++; if(f0[tLen-1] == 0) vuvNum++; int stCount, edCount; int *stList, *edList; stList = (int *)malloc(sizeof(int) * vuvNum); edList = (int *)malloc(sizeof(int) * vuvNum); edCount = 0; stList[0] = 0; stCount = 1; index = 1; if(f0[0] != 0) { for(i = 1;i < tLen;i++) { if(f0[i]==0 && f0[i-1]!=0) { edList[0] = i-1; edCount++; stList[1] = i; stCount++; index = i; } } } edList[vuvNum-1] = tLen-1; for(i = index;i < tLen;i++) { if(f0[i]!=0.0 && f0[i-1]==0.0) { edList[edCount++] = i-1; stList[stCount++] = i; } if(f0[i]==0.0 && f0[i-1]!=0.0) { edList[edCount++] = i-1; stList[stCount++] = i; } } int *wedgeList; wedgeList = (int *)malloc(sizeof(int) * vuvNum); getWedgeList(x, xLen, vuvNum, stList, edList, fs, framePeriod, f0, wedgeList);//島中央のピーク位置を取得 double *signalTime, *f0interpolatedRaw, *totalPhase; double *fixedF0; fixedF0 = (double *)malloc(sizeof(double) * tLen); signalTime = (double *)malloc(sizeof(double) * xLen); f0interpolatedRaw = (double *)malloc(sizeof(double) * xLen); totalPhase = (double *)malloc(sizeof(double) * xLen); for(i = 0;i < tLen;i++) fixedF0[i] = f0[i] == 0 ? DEFAULT_F0 : f0[i]; //F0が0ならデフォルトに補正 for(i = 0;i < xLen;i++) signalTime[i] = (double)i / (double)fs; //サンプル位置の時刻 interp1(timeAxis, fixedF0, tLen, signalTime, xLen, f0interpolatedRaw);//各サンプルのF0 totalPhase[0] = f0interpolatedRaw[0]*2*PI/(double)fs; //各サンプルの位相 for(i = 1;i < xLen;i++) totalPhase[i] = totalPhase[i-1] + f0interpolatedRaw[i]*2*PI/(double)fs; double *pulseLocations; pulseLocations = (double *)malloc(sizeof(double) * xLen); int pCount; pCount = getPulseLocations(x, xLen, totalPhase, vuvNum, stList, edList, fs, framePeriod, wedgeList, pulseLocations);//位相が大きく動くサンプル位置の時刻 double *tmpResidualSpec; tmpResidualSpec = (double *)malloc(sizeof(double) * fftl); double currentF0; for(j = 0;j < fftl/2;j++) residualSpecgram[0][j] = 0.0; for(i = 1;i < tLen;i++) { currentF0 = f0[i] <= FLOOR_F0 ? DEFAULT_F0 : f0[i]; //フレームのF0 下限ならデフォルトに補正 getOneFrameResidualSignal(x, xLen, fs, i, framePeriod/1000.0, currentF0, fftl, pulseLocations, pCount, //最も近いパルス?前後1周期分の波形に窓をかけたものを取得 tmpResidualSpec); for(j = 0;j < fftl/2;j++) residualSpecgram[i][j] = tmpResidualSpec[j]; } free(fixedF0); free(tmpResidualSpec); free(pulseLocations); free(totalPhase); free(f0interpolatedRaw); free(signalTime); free(wedgeList); free(edList); free(stList); return; }
extern void *syncthread(void * arg) #endif { int i,j,nsat,isat[MAXOBS],ind[MAXSAT]={0},refi; uint64_t sampref,sampbase,codei[MAXSAT],diffcnt,mincodei; double codeid[OBSINTERPN],remcode[MAXSAT],samprefd,reftow=0,oldreftow; sdrobs_t obs[MAXSAT]; sdrtrk_t trk[MAXSAT]={{0}}; /* start tcp server (rtcm) */ if (sdrini.rtcm) { sdrout.soc_rtcm.port=sdrini.rtcmport; tcpsvrstart(&sdrout.soc_rtcm); } /* start tcp server (sbas) */ if (sdrini.sbas) { sdrout.soc_sbas.port=sdrini.sbasport; tcpsvrstart(&sdrout.soc_sbas); } /* rinex output setting */ if (sdrini.rinex) { createrinexopt(&sdrout.opt); if ((createrinexobs(sdrout.rinexobs,&sdrout.opt)<0)|| (createrinexnav(sdrout.rinexnav,&sdrout.opt)<0)) { sdrstat.stopflag=ON; } } sdrout.obsd=(obsd_t *)calloc(MAXSAT,sizeof(obsd_t)); while (!sdrstat.stopflag) { mlock(hobsmtx); /* copy all tracking data */ for (i=nsat=0;i<sdrini.nch;i++) { if (sdrch[i].nav.flagdec&&sdrch[i].nav.sdreph.eph.week!=0) { memcpy(&trk[nsat],&sdrch[i].trk,sizeof(sdrch[i].trk)); isat[nsat]=i; nsat++; } } unmlock(hobsmtx); /* find minimum tow channel (most distant satellite) */ oldreftow=reftow; reftow=3600*24*7; for (i=0;i<nsat;i++) { if (trk[i].tow[0]<reftow) reftow=trk[i].tow[0]; } /* output timing check */ if (nsat==0||oldreftow==reftow||((int)(reftow*1000)%sdrini.outms)!=0) { continue; } /* select same timing index */ for (i=0;i<nsat;i++) { for (j=0;j<OBSINTERPN;j++) { if (fabs(trk[i].tow[j]-reftow)<1E-4) { ind[i]=j; break; } } if (j==OBSINTERPN&&ind[i]==0) SDRPRINTF("%s error tow\n",sdrch[isat[i]].satstr); } /* decide reference satellite (nearest satellite) */ mincodei=UINT64_MAX; refi=0; for (i=0;i<nsat;i++) { codei[i]=trk[i].codei[ind[i]]; remcode[i]=trk[i].remcout[ind[i]]; if (trk[i].codei[ind[i]]<mincodei) { refi=i; mincodei=trk[i].codei[ind[i]]; } } /* reference satellite */ diffcnt=trk[refi].cntout[ind[refi]]-sdrch[isat[refi]].nav.firstsfcnt; sampref=sdrch[isat[refi]].nav.firstsf+ (uint64_t)(sdrch[isat[refi]].nsamp* (-PTIMING/(1000*sdrch[isat[refi]].ctime)+diffcnt)); sampbase=trk[refi].codei[OBSINTERPN-1]-10*sdrch[isat[refi]].nsamp; samprefd=(double)(sampref-sampbase); /* computation observation data */ for (i=0;i<nsat;i++) { obs[i].sys=sdrch[isat[i]].sys; obs[i].prn=sdrch[isat[i]].prn; obs[i].week=sdrch[isat[i]].nav.sdreph.week_gpst; obs[i].tow=reftow+(double)(PTIMING)/1000; obs[i].P=CLIGHT*sdrch[isat[i]].ti* ((double)(codei[i]-sampref)-remcode[i]); /* pseudo range */ /* uint64 to double for interp1 */ uint64todouble(trk[i].codei,sampbase,OBSINTERPN,codeid); obs[i].L=interp1(codeid,trk[i].L,OBSINTERPN,samprefd); obs[i].D=interp1(codeid,trk[i].D,OBSINTERPN,samprefd); obs[i].S=trk[i].S[0]; } sdrout.nsat=nsat; sdrobs2obsd(obs,nsat,sdrout.obsd); /* rinex obs output */ if (sdrini.rinex) { if (writerinexobs(sdrout.rinexobs,&sdrout.opt,sdrout.obsd, sdrout.nsat)<0) { sdrstat.stopflag=ON; } } /* rtcm obs output */ if (sdrini.rtcm&&sdrout.soc_rtcm.flag) sendrtcmobs(sdrout.obsd,&sdrout.soc_rtcm,sdrout.nsat); /* navigation data output */ for (i=0;i<sdrini.nch;i++) { if ((sdrch[i].nav.sdreph.update)&& (sdrch[i].nav.sdreph.cnt==sdrch[i].nav.sdreph.cntth)) { sdrch[i].nav.sdreph.cnt=0; sdrch[i].nav.sdreph.update=OFF; /* rtcm nav output */ if (sdrini.rtcm&&sdrout.soc_rtcm.flag) sendrtcmnav(&sdrch[i].nav.sdreph,&sdrout.soc_rtcm); /* rinex nav output */ if (sdrini.rinex) { if (writerinexnav(sdrout.rinexnav, &sdrout.opt,&sdrch[i].nav.sdreph)<0) { sdrstat.stopflag=ON; } } } } } /* thread termination */ free(sdrout.obsd); tcpsvrclose(&sdrout.soc_rtcm); tcpsvrclose(&sdrout.soc_sbas); SDRPRINTF("SDR syncthread finished!\n"); return THRETVAL; }
//----------------------------------------------------------------------------- // Test program. // test.exe input.wav outout.wav f0 spec flag // input.wav : argv[1] Input file // output.wav : argv[2] Output file // f0 : argv[3] F0 scaling (a positive number) // spec : argv[4] Formant shift (a positive number) //----------------------------------------------------------------------------- int main(int argc, char *argv[]) { if (argc != 7) { printf("command: synth FFT_length sampling_rate F0_file spectrogram_file aperiodicity_file output_waveform\n"); return -2; } int fft_size = atoi(argv[1]); int fs = atoi(argv[2]); // compute n bands from fs as in d4c.cpp:325 int number_of_aperiodicities = static_cast<int>(MyMinDouble(world::kUpperLimit, fs / 2.0 - world::kFrequencyInterval) / world::kFrequencyInterval); WorldParameters world_parameters = { 0 }; // You must set fs and frame_period before analysis/synthesis. world_parameters.fs = fs; // 5.0 ms is the default value. // Generally, the inverse of the lowest F0 of speech is the best. // However, the more elapsed time is required. world_parameters.frame_period = 5.0; world_parameters.fft_size = fft_size; // find number of frames (doubles) in f0 file: struct stat st; if (stat(argv[3], &st) == -1) { printf("cannot read f0\n"); return -2; } int f0_length = (st.st_size / sizeof(double)); world_parameters.f0_length = f0_length; // printf("%d\n", f0_length); world_parameters.f0 = new double[f0_length]; FILE *fp; fp = fopen(argv[3], "rb"); for (int i = 0; i < f0_length; i++) { fread(&world_parameters.f0[i], sizeof(double), 1, fp); } fclose(fp); double **coarse_aperiodicities = new double *[world_parameters.f0_length]; world_parameters.aperiodicity = new double *[world_parameters.f0_length]; for (int i = 0; i < world_parameters.f0_length; ++i) { world_parameters.aperiodicity[i] = new double[fft_size / 2 + 1]; coarse_aperiodicities[i] = new double[number_of_aperiodicities]; } world_parameters.spectrogram = new double *[world_parameters.f0_length]; for (int i = 0; i < world_parameters.f0_length; ++i) { world_parameters.spectrogram[i] = new double[fft_size / 2 + 1]; } fp = fopen(argv[4], "rb"); for (int i = 0; i < f0_length; i++) { for (int j = 0; j < fft_size / 2 + 1; j++) { fread(&world_parameters.spectrogram[i][j], sizeof(double), 1, fp); } } fclose(fp); // aper fp = fopen(argv[5], "rb"); for (int i = 0; i < f0_length; i++) { for (int j = 0; j < number_of_aperiodicities; j++) { fread(&coarse_aperiodicities[i][j], sizeof(double), 1, fp); } } fclose(fp); // convert bandaps to full aperiodic spectrum by interpolation (originally in d4c extraction): // Linear interpolation to convert the coarse aperiodicity into its // spectral representation. // -- for interpolating -- double *coarse_aperiodicity = new double[number_of_aperiodicities + 2]; coarse_aperiodicity[0] = -60.0; coarse_aperiodicity[number_of_aperiodicities + 1] = 0.0; double *coarse_frequency_axis = new double[number_of_aperiodicities + 2]; for (int i = 0; i <= number_of_aperiodicities; ++i) coarse_frequency_axis[i] = static_cast<double>(i) * world::kFrequencyInterval; coarse_frequency_axis[number_of_aperiodicities + 1] = fs / 2.0; double *frequency_axis = new double[fft_size / 2 + 1]; for (int i = 0; i <= fft_size / 2; ++i) frequency_axis[i] = static_cast<double>(i) * fs / fft_size; // ---- for (int i = 0; i < f0_length; ++i) { // load band ap values for this frame into coarse_aperiodicity for (int k = 0; k < number_of_aperiodicities; ++k) { coarse_aperiodicity[k+1] = coarse_aperiodicities[i][k]; } interp1(coarse_frequency_axis, coarse_aperiodicity, number_of_aperiodicities + 2, frequency_axis, fft_size / 2 + 1, world_parameters.aperiodicity[i]); for (int j = 0; j <= fft_size / 2; ++j) world_parameters.aperiodicity[i][j] = pow(10.0, world_parameters.aperiodicity[i][j] / 20.0); } //printf("%d %d\n", world_parameters.f0_length, fs); //--------------------------------------------------------------------------- // Synthesis part //--------------------------------------------------------------------------- // The length of the output waveform int y_length = static_cast<int>((world_parameters.f0_length - 1) * FRAMEPERIOD / 1000.0 * fs) + 1; double *y = new double[y_length]; // Synthesis WaveformSynthesis(&world_parameters, fs, y_length, y); // Output wavwrite(y, y_length, fs, 16, argv[6]); delete[] y; DestroyMemory(&world_parameters); for (int i=0; i<f0_length; i++){ delete[] coarse_aperiodicities[i]; } delete[] coarse_aperiodicities; delete[] coarse_aperiodicity; delete[] frequency_axis; printf("complete %s.\n", argv[6]); return 0; }