I am not familiar with the application of signal processing or PLL, do you have a reference or a short explanation of how the algorithm above works?
It's a simple control system for acquiring and tracking a tone basically. With a second order loop filter (PI) it can track the tone with a zero phase offset meaning you can reconstruct the absolute phase of the input signal.
I've drawn a diagram here:
PLL diagramWhat is InputNeg, is it the difference in values of two signals calculated from successive measurements?
In the case of this code it assumes the input has the format of sin(x), so whether that is negative or positive (1 bit quantization). To do a phase comparison you would run a PLL for each microphone and then compare the NCO counter to tell the absolute phase difference between them.
Would a sound signal with multiple harmonics need something like a low pass filter, or will the PLL loop above handle the higher harmonics as long as the PLL update frequency is some factor higher than the highest significant harmonic?
It might lock to a harmonic or even one of the subharmonics if you are unlucky. It's best if you can tell which exact frequency range the harmonic will be in, in that case you can clamp the value of
lfAcc to stay inside that frequency range.
That's the downside with a PLL approach, with an FFT you would be able to find the global maximum
I will buy some cheap electret microphones and a couple of op amps to start playing around, so I could also implement your PLL idea if I manage to understand enough of the implementation details.
Could be cool to see