Exemplo n.º 1
0
PitchDetector::PitchDetector(unsigned int numberOfSamples, double sampleRate)
{
    assert(numberOfSamples > 0);
    assert(sampleRate > 0);
    this->numberOfSamples = numberOfSamples;
    this->sampleRate = sampleRate;
    this->queueSize = DEFAULT_QUEUE_SIZE;
//    this->FFTBuffer = new float(numberOfSamples);
    
    this->FFTBuffer = (float *)calloc(sizeof(float), numberOfSamples);
    
    // 1.窗函数
    this->windowFunc = (float *)calloc(sizeof(float), numberOfSamples);
    vDSP_hamm_window(windowFunc, numberOfSamples, 0);

    // 2.fft处理buffer
    this->A.realp = (float  * __nonnull)malloc(sizeof(float)*(numberOfSamples/2));
    this->A.imagp = (float  * __nonnull)malloc(sizeof(float)*(numberOfSamples/2));

    // 3.能量
    this->magnitudes = (float *)malloc(sizeof(float)*(numberOfSamples/2));
    
    // 4.fft变换的预设
    float originalRealInLog2 = log2f(numberOfSamples);
    this->setupReal = vDSP_create_fftsetup(originalRealInLog2, FFT_RADIX2);

}
Exemplo n.º 2
0
void FFT32_configureWindow(FFT32 *self, FFTWindowType windowType)
{
    Float32 one = 1;
    
    switch (windowType) {
            
        case kFFTWindowType_None:
            
            vDSP_vfill(&one, self->window, 1, self->FFTFrameSize);
            break;
            
        case kFFTWindowType_Hanning:
            
            vDSP_hann_window(self->window, self->FFTFrameSize, vDSP_HANN_DENORM);
            break;
            
        case kFFTWindowType_Hamming:
            
            vDSP_hamm_window(self->window, self->FFTFrameSize, 0);
            break;
            
        default:
            printf("Valid window not specified, default to none\n");
            vDSP_vfill(&one, self->window, 1, self->FFTFrameSize);
            break;
    }
}
Exemplo n.º 3
0
void generateWindow(ofxAudioUnitWindowType windowType, float * window, size_t size)
{
	switch (windowType) {
		case OFXAU_WINDOW_HAMMING:
			vDSP_hamm_window(window, size, 0);
			break;
		case OFXAU_WINDOW_HANNING:
			vDSP_hann_window(window, size, 0);
			break;
		case OFXAU_WINDOW_BLACKMAN:
			vDSP_blkman_window(window, size, 0);
			break;
	}
}
Exemplo n.º 4
0
void createWindow(FFT* fft, int windowType)
{
	// allocate memory for a window
	if (fft->window == NULL)
    	fft->window = (float *)malloc(fft->size * sizeof(float));

    switch (windowType)
    {
    	case HANN:
    		vDSP_hann_window(fft->window, fft->size, vDSP_HANN_NORM);
    		break;

    	case HAMM:
    		vDSP_hamm_window(fft->window, fft->size, 0);        // 0 is the full window
    		break;

    	default:
    		break;
    }
}