title: How to get an amplitude of certain frequency audio signal realtime android
body: <p>I am developing lumiere application. I have a carrier signal of certain frequency (19.2 kHz if to be more precise) and I need to get the amplitude of it while the audio is being played.
  I have googled some info on audio processing and found out that in order to get frequency spectrum you have to use FFT algorithm.</p>
  
  <p>I have tried TarsosDSP library and its FFT class.</p>
  
  <pre><code>TarsosDSPAudioFormat format = new TarsosDSPAudioFormat((float) SAMPLE_RATE, 16, 1, true, false);
  TarsosDSPAudioFloatConverter converter = TarsosDSPAudioFloatConverter.getConverter(format);
  
  float[] buff = new float[bufferFloatSize];
  final float[] amps = new float[fftSize];
  
  converter.toFloatArray(tmpBuffer, buff);
  
  FFT fft = new FFT(bufferFloatSize, new HannWindow());
  fft.forwardTransform(buff);
  fft.modulus(buff, amps);
  </code></pre>
  
  <p>Then I get frequency band index and calculate its amplitude</p>
  
  <pre><code>int amp = (int) (10 * Math.log10(amps[index]);
  </code></pre>
  
  <p>But I get wrong amplitude. 
  I have an audio file with 19.2kHz signal that has constant amplitude of 0 dB but the result value of 19207 Hz amplitude varies from -39 dB to -46 dB. I checked neighboring frequencies, may be some of them have 0 dBs, but no. 
  I also checked files with -36 dB and -60 dB but the results were -39 to -48 dB and -44 to - 61 dB respectively.</p>
  
  <p>As we can see for the last file it is close, but it is not constant and I can't predict when it's right and when it's wrong.</p>
  
  <p>If there is anybody who faced this issue, please help me.
  If you know any other good FFT lib that is workable for sure - tell me</p>
  
  <p>UPDATE:
  Ok, I have added TSG's function and call it before my fft.forwardTransform() and after to compare the results;
  The results were:
  for 0 dB 19.2kHz audio file: 
  before: -39 dB
  after - 10 dB</p>
  
  <p>for -36 dB 19.2kHz audio file:
  before: -75 dB
  after: -46 dB</p>
  
  <p>for -60 dB 19.2kHz audio file:
  before: -97.7 dB
  after: -69 dB</p>
  
  <p>Now the results are constant and don't change with time or try. 
  We also can see that there is a certain pattern in the results. Before fft the result differs from the right one for -39 dBs and after for -10dBs. 
  So the question is: why are we having these mistakes?</p>