예제 #1
0
파일: fft.c 프로젝트: 87maxi/meters.lv2
static
int _fftx_run(struct FFTAnalysis *ft,
		const uint32_t n_samples, float const * const data)
{
	assert(n_samples <= ft->window_size);

	float * const f_buf = ft->fft_in;
	float * const r_buf = ft->ringbuf;

	const uint32_t n_off = ft->rboff;
	const uint32_t n_siz = ft->window_size;
	const uint32_t n_old = n_siz - n_samples;

	/* copy new data into ringbuffer and fft-buffer
	 * TODO: use memcpy
	 */
	for (uint32_t i = 0; i < n_samples; ++i) {
		r_buf[ (i + n_off) % n_siz ]  = data[i];
		f_buf[n_old + i] = data[i];
	}

	ft->rboff = (ft->rboff + n_samples) % n_siz;
#if 1
	ft->smps += n_samples;
	if (ft->smps < ft->sps) {
		return -1;
	}
	ft->step = ft->smps;
	ft->smps = 0;
#else
	ft->step = n_samples;
#endif

	/* copy samples from ringbuffer into fft-buffer */
	const uint32_t p0s = (n_off + n_samples) % n_siz;
	if (p0s + n_old >= n_siz) {
		const uint32_t n_p1 = n_siz - p0s;
		const uint32_t n_p2 = n_old - n_p1;
		memcpy(f_buf, &r_buf[p0s], sizeof(float) * n_p1);
		memcpy(&f_buf[n_p1], &r_buf[0], sizeof(float) * n_p2);
	} else {
		memcpy(&f_buf[0], &r_buf[p0s], sizeof(float) * n_old);
	}

	/* ..and analyze */
	ft_analyze(ft);
	ft->phasediff_bin = ft->phasediff_step * (double)ft->step;
	return 0;
}
예제 #2
0
파일: check1.c 프로젝트: Galathorn/Project
int			*ft_arraypiece(int npiece, char *strfile)
{
	int		*piecearray;
	int		i;
	int		elemtab;

	elemtab = 0;
	i = 0;
	if (!(piecearray = (int *)malloc(npiece * sizeof(int))))
		return (0);
	while (strfile[i])
	{
		if (strfile[i] == '\n' && strfile[i - 1] == '\n')
			g_boul = 0;
		if (strfile[i] == '#' && strfile[i - 1] != '#' && g_boul == 0)
		{
			piecearray[elemtab] = ft_analyze(piecearray[elemtab], &strfile[i]);
			elemtab++;
			g_boul++;
		}
		i++;
	}
	return (piecearray);
}