record audio in java and determine real time if a tone of x frequency was played if so do something

后端 未结 2 790
一向
一向 2021-01-23 04:17

I want to be able to detect a tone of a predetermined frequency using java. What I am doing is playing a tone (the frequency of the tone is variable by user input) and I am try

2条回答
  •  不知归路
    2021-01-23 04:41

    If you're just looking for a specific frequency then an FFT-based method is probably a bad choice for your particular application, for two reasons:

    1. it's overkill - you're computing an entire spectrum just to detect the magnitude at one point

    2. to get 3 ms resolution for your onset detection you'll need a large overlap between successive FFTs, which will require much more CPU bandwidth than just processing successive blocks of samples

    A better choice for detecting the presence or absence of a single tone is the Goertzel algorithm (aka Goertzel filter). It's effectively a DFT evaluated at a single frequency domain bin, and is widely used for tone detection. It's much less computationally expensive than an FFT, very simple to implement, and you can test its output on every sample, so no resolution problem (other than those dictated by the laws of physics). You'll need to low pass filter the magnitude of the output and then use some kind of threshold detection to determine the onset time of your tone.

    Note that there are a number of useful questions and answers on SO already about tone detection and using the Goertzel algorithm (e.g. Precise tone onset/duration measurement?) - I suggest reading these along with the Wikipedia entry as a good starting point.

提交回复
热议问题