2

I've been researching this off-and-on for a few months.

I'm looking for a library or working example code to detect the frequency in sound card audio input, or detect presence of a given set of frequencies. I'm leaning towards Java, but the real requirement is that it should be something higher-level/simpler than C, and preferably cross-platform. Linux will be the target platform but I want to leave options open for Mac or possibly even Windows. Python would be acceptable too, and if anyone knows of a language that would make this easier/has better pre-written libraries, I'd be willing to consider it.

Essentially I have a defined set of frequency pairs that will appear in the soundcard audio input and I need to be able to detect this pair and then... do something, such as for example record the following audio up to a maximum duration, and then perform some action. A potential run could feature say 5-10 pairs, defined at runtime, can't be compiled in: something like frequency 1 for ~ 1 second, a maximum delay of ~1 second, frequency 2 for ~1 second.

I found suggestions of either doing an FFT or Goertzel algorithm, but was unable to find any more than the simplest example code that seemed to give no useful results. I also found some limitations with Java audio and not being able to sample at a high enough rate to get the resolution I need.

Any suggestions for libraries to use or maybe working code? I'll admit that I'm not the most mathematically inclined, so I've been lost in some of the more technical descriptions of how the algorithms actually work.

Kheldar
  • 5,361
  • 3
  • 34
  • 63
Jason Antman
  • 2,620
  • 2
  • 24
  • 26
  • Do you know ahead of time what the frequencies of the tones are going to be, i.e. is it just a case of detecting a known frequency, or do you need to detect, say, one of N different frequencies ? Also, what is the S/N ratio like ? Is there significant background noise ? – Paul R Nov 30 '10 at 16:30
  • S/N is... bad. This will be coming over VHF 2-way radio. I'd say a fairly strong signal by radio standards, but that's pretty bad by any other standards. Yes I know ahead of time what the frequencies are (at runtime, not at compile time) but I need to detect one of 10 set frequencies, possibly very close together... everything is within about 300-2000Hz, but in the set of 10, any two could be maybe 20-40Hz apart. – Jason Antman Dec 08 '10 at 19:44
  • 1
    10 years ago I ported and optimized an FFT algo from C to Java. It was about 80 lines long at max. I'm not sure you need a "library" for such a trivial thing as an FFT. Sadly I don't have that code handy (it is on some backup CD somewhere). An FFT is simple and does produce useful result even in the presence of huge noise. I really think you need to be at least a bit math-inclined to do what you want to do and also a little bit math-inclined if you want to be a programmer :( – SyntaxT3rr0r Dec 08 '10 at 20:17
  • There is an excellent article on using FFT in Java to detect frequency values. http://blog.bjornroche.com/2012/07/frequency-detection-using-fft-aka-pitch.html I found this researching a similar problem for iOS. – Gregg Harrington Dec 10 '18 at 00:40

2 Answers2

0

Check out SNDPeek, its a cross-platform C++ application that extracts all kinds of information from live audio; https://github.com/RobQuistNL/sndpeek

Rob
  • 4,927
  • 4
  • 26
  • 41
0

If you are aiming at detecting frequency pairs then your job is very similar to a DTMF detector.

Try searching for DTMF in places like sourgeforge, you'll find detectors in many programming languages. The frequency pairs placing along the spectrum seems to be even more stringent than your specs so you should be fine adapting a DTMF detector to your input.

Kheldar
  • 5,361
  • 3
  • 34
  • 63
fefanto
  • 46
  • 1