1
votes

i am trying to build an iOS 7 application that detecting the sound/song pitch(or frequency), For example: 349.23Hz, 392.00Hz, 440.00Hz......

So, I download the "Auto Correllation" project (it's a Musician's ket http://musicianskit.com/developer.php), I run it on iOS 7 Simulator, it works fine, The "hanning fft window" have value (not NaN), and able get the frequency finally.

But, it doesn't work on iPhone device, it cannot has any value in "hanning fft window". Can anybody have a look into these classes by Kevin Murphy and tell me how I could modify them to work on iPhone device(not the iOS simulator)? Many many thanks~

I've pasted my code below:

// PitchDetector.m

    -(id) initWithSampleRate: (float) rate lowBoundFreq: (int) low hiBoundFreq: (int) hi andDelegate: (id<PitchDetectorDelegate>) initDelegate {
        self.lowBoundFrequency = low;
        self.hiBoundFrequency = hi;
        self.sampleRate = rate;
        self.delegate = initDelegate;

        bufferLength = self.sampleRate/self.lowBoundFrequency;    

        hann = (float*) malloc(sizeof(float)*bufferLength);

        // applied the Hanning windows, the 'hann' is the Hanning fft Window
        vDSP_hann_window(hann, bufferLength, vDSP_HANN_NORM);

        sampleBuffer = (SInt16*) malloc(512);
        samplesInSampleBuffer = 0;

        result = (float*) malloc(sizeof(float)*bufferLength);

        return self;
    }

    -(void) performWithNumFrames: (NSNumber*) numFrames;
    {
        int n = numFrames.intValue;
        float freq = 0;    
        SInt16 *samples = sampleBuffer;

        int returnIndex = 0;
        float sum;
        bool goingUp = false;
        float normalize = 0;    
        for(int i = 0; i<n; i++) {
            sum = 0;
            for(int j = 0; j<n; j++) {
                //here I found the hann[j] is NaN. seems doesn't have value in hann('hann' is the Hanning fft Window)
                //if hann[j] is Not a Number (NaN), the value of sum also to be NaN.
                sum += (samples[j]*samples[j+i])*hann[j];            
            }
            if(i ==0 ) normalize = sum;        
            result[i] = sum/normalize;
        }
    ......
    ......
    }
1
I'm having a similar problem. Haven't been able to identify the cause yet.Michael

1 Answers

0
votes

I am using this same program from: https://github.com/fotock/PitchDetectorExample/tree/1c68491f9c9bff2e851f5711c47e1efe4092f4de

Although I have not put this on an iPhone yet, only simulator, I was having problems from time time with the program crashing. I found that I needed to manually update it with from a "fork" of the code on github found here: https://github.com/fotock/PitchDetectorExample/network

I added Jordan Liggitt's bug fixes manually and now the app does not crash. I hope this helps because if it does not, then I will be facing the same issues when I load this app on an iPhone.

Hope it works!

Update I have now installed this on an iPhone vs the simulator and it works as it should without errors or crashing.