I have done that before – recognize a tone in real time using FFT's. I believe I may have used Klaus' FFT library or I may have used my own. Search this Forum for "Canalrun FFT", maybe I uploaded it, I don't remember.
Barry.
I have been lurking on this thread. Back around post #10 I mentioned a project I had done years ago. I was able to find that project and have included a Dropbox link:
https://www.dropbox.com/s/cryql0u29xbz85y/CRSpec.zip?dl=0
It is too big to attach.
The link points to a zip file that includes the APK, B4A project with source, library files, and Java library source. I compiled the library using Eclipse and the Simple Library Compiler.
The library source contains the source code for a fast implementation of an FFT. I think the speed gain in this particular FFT implementation might come from the fact that it pre-computes and stores the FFT coefficients.
The library also contains code to read audio data from the microphone. My implementation allows the audio data buffer size to be set. I set this to the same size as my FFT – to make things easier.
The example app displays real-time spectrum. The audio input is from the microphone. It also includes five generated sign waveforms to test the FFT execution (the above display is generated by Test3).
A little warning: I built this app with an old version of B4A, 4.30. The App requires the permission READ_AUDIO which I believe now has to be allowed at run time. I use a target SDK of 19. I test with android 6.0. I'm not sure how it will operate on more modern devices.
I use a sample rate of 22050, an audio buffer and FFT size of 1024. I compute and display the square root of magnitude squares. According to my rough timing calculations the FFT with signal generation, scaling, and mag squares requires about 0.8 ms on my Samsung S5. With a sample rate at 22050 and an audio buffer of 1024, this gives a buffer rate of about 46 ms - real-time is easily achieved.
One of the original applications earlier in this thread was to detect the duration of a tone (beep). Detecting a tone is similar to my ultimate application using this library.
What I might do is determine the frequency of the beep: The beep will show up as a peak in one of the displayed magnitude bins. Figure out which bin it shows up in then continuously process FFTs looking for a signal threshold crossing in that bin. Count the number of consecutive audio buffers with that threshold crossing to get the duration.
Barry.