Esempio n. 1
0
void scfft_global_init(){
	unsigned short wintype, i;
	for (wintype=0; wintype<2; ++wintype) {
		for (i=0; i< SC_FFT_LOG2_ABSOLUTE_MAXSIZE_PLUS1; ++i) {
			fftWindow[wintype][i] = 0;
		}
		for (i= SC_FFT_LOG2_MINSIZE; i < SC_FFT_LOG2_MAXSIZE+1; ++i) {
			fftWindow[wintype][i] = scfft_create_fftwindow(wintype, i);
		}
	}
	#if SC_FFT_VDSP
		// vDSP inits its twiddle factors
		for (i= SC_FFT_LOG2_MINSIZE; i < SC_FFT_LOG2_MAXSIZE+1; ++i) {
			fftSetup[i] = vDSP_create_fftsetup (i, FFT_RADIX2);
			if(fftSetup[i] == NULL){
				printf("FFT ERROR: Mac vDSP library could not allocate FFT setup for size %i\n", 1<<i);
			}
		}
		// vDSP prepares its memory-aligned buffer for rearranging input data.
		// Note max size here - meaning max input buffer size is these two sizes added together.
		// vec_malloc used in API docs, but apparently that's deprecated and malloc is sufficient for aligned memory on OSX.
		splitBuf.realp = (float*) malloc ( SC_FFT_MAXSIZE * sizeof(float) / 2);
		splitBuf.imagp = (float*) malloc ( SC_FFT_MAXSIZE * sizeof(float) / 2);
		//printf("SC FFT global init: vDSP initialised.\n");
	#elif SC_FFT_FFTW
		//printf("SC FFT global init: FFTW, no init needed.\n");
	#endif
}
Esempio n. 2
0
// check the global list of windows incs ours; create if not.
// Note that expanding the table, if triggered, will cause a CPU hit as things are malloc'ed, realloc'ed, etc.
void scfft_ensurewindow(unsigned short log2_fullsize, unsigned short log2_winsize, short wintype)
{
	// Ensure we have enough space to do our calcs
	if(log2_fullsize > largest_log2n){
		largest_log2n = log2_fullsize;
 		#if SC_FFT_VDSP
			size_t newsize = (1 << largest_log2n) * sizeof(float) / 2;
			splitBuf.realp = (float*) realloc (splitBuf.realp, newsize);
			splitBuf.imagp = (float*) realloc (splitBuf.imagp, newsize);
   		#endif
	}

	// Ensure our window has been created
	if((wintype != -1) && (fftWindow[wintype][log2_winsize] == 0)){
		fftWindow[wintype][log2_winsize] = scfft_create_fftwindow(wintype, log2_winsize);
	}

	// Ensure our FFT twiddle factors (or whatever) have been created
 	#if SC_FFT_VDSP
		if(fftSetup[log2_fullsize] == 0)
			fftSetup[log2_fullsize] = vDSP_create_fftsetup (log2_fullsize, FFT_RADIX2);
	#elif SC_FFT_GREEN
		if(cosTable[log2_fullsize] == 0)
			cosTable[log2_fullsize] = create_cosTable(log2_fullsize);
   	#endif
}