As you find, the musical pitch is not the same as the peak frequency.
But trying to research algorithms while trying to work with real-time audio is not easy.
I suggest you share the problems. Record some music sounds (guitar folds, etc.) on your Mac to raw audio files. Try the step estimation algorithms of your choice on these recorded sample sets. Then, after you get this work, figure out how to integrate your code into iOS audio and speed up (for FFT) frameworks.
source share