コード例 #1
0
ファイル: coscalc.cpp プロジェクト: astrojhgu/coscalcpp
  double cosmic_calculator::calc_dm(double z)const
  {
    double Dh=cp.c/cp.H0;
    double Dc=calc_dc(z);
    if(cp.Omega_k>0)
      {
	return Dh/std::sqrt(cp.Omega_k)*std::sinh(std::sqrt(cp.Omega_k)*Dc/Dh);
      }
    else if(cp.Omega_k<0)
      {
	return Dh/std::sqrt(-cp.Omega_k)*std::sin(std::sqrt(-cp.Omega_k)*Dc/Dh);
      }
    else
      {
	return Dc;
      }
  }
コード例 #2
0
ファイル: ppsfns.c プロジェクト: Salimlou/AudioAnecdotes
int track_pps(WAVDATA *wvd, PPSDATA *pps, long seed, long period, long ss, long es)
{
	int vstat, navg, fpt;
	long j, ipt, ibeg, iend, nwin, minPP, maxPP, loc, lc2, npps=0, ns, nc, ic;
	float time, tlast, max, v, *kernel, *kernelX, tsc, vuv, pavg, pmin, pmax, sr;
	double rad, rx;
	short *data;

	ns = wvd->ns;
	nc = wvd->nc;
	ic = wvd->active;
	tsc = wvd->srms;
	sr = (float) (tsc * 1000.0);
	data = wvd->wavdata;
/*
 * get windowed kernel at seed location
 */
	DC = calc_dc(ic, nc, ns, data);
	seed = tweak(seed, nc, ic, data, ns);
	nwin = (int) (pitcmn.wlen * tsc + 0.5);
	nwin = 2 * (nwin/2) + 1;  /* nwin should be odd */

	if (seed < nwin/2 || seed > (ns - nwin/2)) {
		return -1;
	}
	
	if (!(kernel = (float *) malloc(nwin * sizeof(float))))
		return -1;

	if (!(kernelX = (float *) malloc(nwin * sizeof(float)))){
		free(kernel);
		return -1;
	}
		
	rx = 2.0 * M_PI/ (float) nwin;

	ibeg = (seed * nc + ic) - (nc * nwin/2);

	for (rad=rx/2.0, ipt=ibeg, j=0; j<nwin; j++, ipt+=nc, rad+=rx)
		kernel[j] = (float) (0.5 - 0.5 * cos(rad)) * (float) (data[ipt] - DC);

	for (rad=rx/2.0, j=0; j<nwin; j++, rad+=rx)
		kernelX[j] = (float) ((0.5 - 0.5 * cos(rad)) * -16384.0 * sin(rad));

	minPP = (int) (pitcmn.jitlo * (float)period + 0.5); /* allow for acceptable jitter */
	maxPP = (int) (pitcmn.jithi * (float)period + 0.5);
	tlast = (float) seed / tsc;
	if (seed >= ss && seed <= es) {
		ppadd(tlast, 1, pps); /* store location of seed as a PP */
		npps++;
	}
	ibeg = seed + minPP;
	iend = seed + maxPP;
	ipt = ibeg;

	if (pitcmn.vuv == 0.0)
    	vuv = (float) (0.1 * compare(seed*nc + ic, nc, data, nwin, kernelX) / (double) nwin);
    else
    	vuv = pitcmn.vuv * pitcmn.vuv;

	pavg = (float) period / tsc;
	navg = 1;
	pmin = pmax = pavg;
/* 
 * Search from seed location to end of the input waveform
 */
	while ((iend + nwin/2) <= es) {
		max = compare(ipt*nc + ic, nc, data, nwin, kernel);
		loc = ipt;
		for (ipt=ibeg+1; ipt < iend; ipt++)
			if ((v = compare(ipt*nc+ic, nc, data, nwin, kernel)) > max) {
				max = v;
				loc = ipt;
			}
		if (use_vData) {
			fpt = (int) ((((double)loc / tsc) - vData->StartTime) / vData->StepSize + 0.5);
			if (fpt < 0)
				fpt = 0;
			if (fpt >= vData->nfr)
				fpt = vData->nfr - 1;
		}
		max = compare(loc*nc+ic, nc, data, nwin, kernelX) / (float) nwin; /* for voicing decision */

		if (max > vuv) {
			lc2 = tweak(loc, nc, ic, data, ns);
			if (labs(lc2 - loc) < nwin/4)
				loc = lc2;
			time = (float) loc / tsc;
			if (vstat) {
				v = time - tlast;
				pavg += v;
				navg++;
				if (v < pmin) pmin = v;
				if (v > pmax) pmax = v;
				if (use_vData) {
					minPP = (long) ((pitcmn.jitlo * sr/vData->F0[fpt]) + 0.5);  /* allow -jitlo variation for next period */
					maxPP = (long) ((pitcmn.jithi * sr/vData->F0[fpt]) + 0.5); /* allow +jithi variation for next period */
				} else {
					minPP = (long) ((pitcmn.jitlo * v) * tsc + 0.5);  /* allow - 10% variation for next period */
					maxPP = (long) ((pitcmn.jithi * v) * tsc + 0.5); /* allow + 15% variation for next period */
				}
			} else {
				if (use_vData)
					v = (sr/vData->F0[fpt])/tsc;
				else	
					v = pavg / (float) navg;
				minPP = (long) ((pitcmn.jitlo * v) * tsc + 0.5);  /* allow - 25% variation for next period */
				maxPP = (long) ((pitcmn.jithi * v) * tsc + 0.5); /* allow + 50% variation for next period */
			}
			vstat = 1;
		} else {
			v = pavg / (float) navg;
			time = tlast + v;
			loc = (long) (tsc * time + 0.5f);
			if (loc > ns) {
				loc = ns;
				time = (float) loc / tsc;
				v = time - tlast;
			}
			vstat = 0;
			minPP = (long) ((pitcmn.jitlo * v) * tsc + 0.5);  /* allow - 25% variation for next period */
			maxPP = (long) ((pitcmn.jithi * v) * tsc + 0.5); /* allow + 50% variation for next period */
		}				
		if (loc >= ss) {
			ppadd(time, vstat, pps);
			npps++;
		}
		ibeg = (loc * nc + wvd->active) - (nc * nwin/2);
		if ((ibeg + nwin) < ns)
			if (vstat)
				for (rad=rx/2.0f, ipt=ibeg, j=0; j<nwin; j++, ipt+=nc, rad+=rx)
					kernel[j] = 0.5f * (kernel[j] + ((float) (0.5 - 0.5 * cos(rad)) * (float) (data[ipt] - DC)));
			else
				for (j=0; j<nwin; j++)
					kernel[j] = 0.5f * (kernel[j] + kernelX[j]);
				
		
		ibeg = loc + minPP;
		iend = loc + maxPP;
		ipt = ibeg;
		tlast = time;
	}

	tlast = (float) seed / tsc;
	ibeg = (seed * nc + ic) - (nc * nwin/2);
	for (rad=rx/2.0, ipt=ibeg, j=0; j<nwin; j++, ipt+=nc, rad+=rx)
		kernel[j] = (float) (0.5 - 0.5 * cos(rad)) * (float) (data[ipt] - DC);

	minPP = (int) (pitcmn.jitlo * (float)period + 0.5); /* reset for original period template */
	maxPP = (int) (pitcmn.jithi * (float)period + 0.5);
	ibeg = seed - maxPP;
	iend = seed - minPP;
	ipt = ibeg;
    
	while ((ibeg >= ss) && (ibeg > nwin/2)) {
		max = compare(ipt*nc + ic, nc, data, nwin, kernel);
		loc = ipt;
		for (ipt=ibeg+1; ipt < iend; ipt++)
			if ((v = compare(ipt*nc+ic, nc, data, nwin, kernel)) > max) {
				max = v;
				loc = ipt;
			}
		if (use_vData) {
			fpt = (int) ((((double)loc / tsc) - vData->StartTime) / vData->StepSize + 0.5);
			if (fpt < 0)
				fpt = 0;
			if (fpt >= vData->nfr)
				fpt = vData->nfr - 1;
		}
		max = compare(loc*nc+ic, nc, data, nwin, kernelX) / (float) nwin; /* for voicing decision */
		if (max > vuv) {
			lc2 = tweak(loc, nc, ic, data, ns);
			if (labs(lc2 - loc) < nwin/4)
				loc = lc2;
			time = (float) loc / tsc;
			if (vstat) {
				v = tlast - time;
				pavg += v;
				navg++;
				if (v < pmin) pmin = v;
				if (v > pmax) pmax = v;
				if (use_vData) {
					minPP = (long) ((pitcmn.jitlo * sr/vData->F0[fpt]) + 0.5);  /* allow -jitlo variation for next period */
					maxPP = (long) ((pitcmn.jithi * sr/vData->F0[fpt]) + 0.5); /* allow +jithi variation for next period */
				} else {
					minPP = (long) ((pitcmn.jitlo * v) * tsc + 0.5);  /* allow - 10% variation for next period */
					maxPP = (long) ((pitcmn.jithi * v) * tsc + 0.5); /* allow + 15% variation for next period */
				}
			} else {
				if (use_vData)
					v = (sr/vData->F0[fpt])/tsc;
				else	
					v = pavg / (float) navg;
				minPP = (long) ((pitcmn.jitlo * v) * tsc + 0.5);  /* allow - 25% variation for next period */
				maxPP = (long) ((pitcmn.jithi * v) * tsc + 0.5); /* allow + 50% variation for next period */
			}
			vstat = 1;
		} else {
			v = pavg / (float) navg;
			time = tlast - v;
			loc = (long) (tsc * time + 0.5);
			if (loc < 0) {
				loc = 0;
				time = (float) loc / tsc;
				v = tlast - time;
			}
			vstat = 0;
			minPP = (long) ((pitcmn.jitlo * v) * tsc + 0.5);  /* allow - 25% variation for next period */
			maxPP = (long) ((pitcmn.jithi * v) * tsc + 0.5); /* allow + 50% variation for next period */
		}				
		if (loc >= ss && loc <= es) {
			ppadd(time, vstat, pps);
			npps++;
		}
		ibeg = (loc * nc + ic) - (nc * nwin/2);
		if (ibeg >= 0)
			if (vstat)
				for (rad=rx/2.0f, ipt=ibeg, j=0; j<nwin; j++, ipt+=nc, rad+=rx)
					kernel[j] = (float) (0.5 * (kernel[j] + ((0.5 - 0.5 * cos(rad)) * (double) (data[ipt] - DC))));
			else
				for (j=0; j<nwin; j++)
					kernel[j] = (float) (0.5 * (kernelX[j] + kernel[j]));
		
		ibeg = loc - maxPP;
		iend = loc - minPP;
		ipt = ibeg;
		tlast = time;
	}

	ppsort(pps);
	free(kernel);
	free(kernelX);
	return (int) npps;
}