Reputation: 13
I am working on a pitch detection project using Unity3D. I am very new to coding, unity & pretty much everything else I'm currently working on! :-) I came across this web page that helped get me going and am using the FFT code in my project:
http://www.kaappine.fi/tutorials/fundamental-frequencies-and-detecting-notes/
It's mostly working really well, however the frequency detected seems to vary depending on which computer I use. I have tried it on various desktops & laptops (mixture of pc & mac), and on some computers it picks up the correct frequency but on others it gives me a frequency of approx. 1.5 semitones flat. What is interesting though is that out of the 6 computers I’ve tried it on, 3 have been correct and the other 3 have all been the same 1.5 semitones flat.
It can't be down to the microphones as I have tried both the built in mics on some computers as well as separate mics and results have not varied.
Does anyone have any idea what could be the reason for this and how I could solve the issue? Any adjustments I could maybe make to the code? The project I am working on will eventually be distributed as an iPhone app so I need it to work universally across devices.
By the way I can only use C# programming language at the moment.
Many thanks in advance for any help & advice
Best wishes
Phil
Upvotes: 1
Views: 204
Reputation: 213190
1.5 semitones happens to be the same ratio as the ratio between sampling rates of 48 kHz and 44.1 kHz. My guess is that you have hard-coded 48 kHz as your sample rate but that some of your computers are actually using a sample rate of 44.1 kHz (or vice versa). You should use a suitable API to determine the sample rate in use, or explicitly set it yourself.
The math:
2^(1.5/12)
= 1.09
.48/44.1
= 1.09
.Upvotes: 2