Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does my FFT gives a different visualizer output than Windows Media Player?
    primarykey
    data
    text
    <p>I am trying to implement an audio spectrum analyzer in android using the <a href="http://developer.android.com/reference/android/media/audiofx/Visualizer.html" rel="noreferrer">Visualizer</a> class.</p> <p>I am getting FFT data in the <code>onFftDataCapture()</code> method of <code>OnDataCaptureListener()</code> event and I'm drawing that on the canvas using <code>drawLines()</code>.</p> <p>But the spectrum display is not showing properly. I can see changes on left side of graph only. But in Window Media Player, the output of the same song is different. What I am missing?</p> <p>Can anyone help me on this with an example or a link?</p> <p><strong>CODE</strong></p> <pre><code>mVisualizer.setDataCaptureListener( new Visualizer.OnDataCaptureListener() { public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes, int samplingRate) {} public void onFftDataCapture(Visualizer visualizer, byte[] bytes, int samplingRate) { mVisualizerView.updateVisualizer(bytes, samplingRate); } }, Visualizer.getMaxCaptureRate() / 2, false, true); </code></pre> <p><strong>onPaint()</strong></p> <pre><code> for (int i = 0; i &lt; mBytes.length / 2; i++) { mPoints[i * 4] = i * 8; mPoints[i * 4 + 1] = 0; mPoints[i * 4 + 2] = i * 8; byte rfk = mBytes[2 * i]; byte ifk = mBytes[2 * i + 1]; magnitude = (float) (rfk * rfk + ifk * ifk); int dbValue = (int) (10 * Math.log10(magnitude)); mPoints[i * 4 + 3] = (float) (dbValue * 7); } canvas.drawLines(mPoints, mForePaint); </code></pre> <p>Where <code>mVisualizer</code> is Visualizer class object, and <code>mBytes</code> is FFT Data got from <code>onFftDataCapture</code> event.</p> <p>You can read more about FFT data returned by event <a href="http://developer.android.com/reference/android/media/audiofx/Visualizer.html#getFft%28byte%5B%5D%29" rel="noreferrer">here</a>.</p> <p>This is what values I get <code>onFftDataCapture()</code> :</p> <p><code>[90, -1, -27, 102, 13, -18, 40, 33, -7, 16, -23, -23, -2, -8, -11, -9, -8, -33, -29, 44, 4, -9, -15, -1, -2, -17, -7, 1, 1, 0, 3, -11, -5, 10, -24, -6, -23, 1, -9, -21, -2, 4, 9, -10, -14, -5, -16, 8, 6, -16, 14, 3, 7, 15, 10, -2, -15, -14, -5, 10, 8, 23, -1, -16, -2, -6, 4, 9, -1, 0, 0, 9, 1, 4, -2, 6, -6, -6, 8, -4, 6, 6, -4, -5, -5, -2, 3, 0, -1, 0, -7, 0, 2, 1, 0, 1, -1, 0, -1, 1, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -1]</code></p> <p>Any idea, link would be helpful.</p> <p><img src="https://i.stack.imgur.com/AcSPT.png" alt="Partial value drawing"></p> <p><img src="https://i.stack.imgur.com/LASMQ.png" alt="full value drawing"></p> <p><strong>Update for @Chris Stratton</strong></p> <p>Now i am playing <a href="http://en.wikipedia.org/wiki/File:Square_wave_1000.ogg" rel="noreferrer">square wave at 1000 Hz</a> file and took screen shot of that. What you suggest now?</p> <p><img src="https://i.stack.imgur.com/SFzMc.png" alt="1 KHz spectrum"></p> <p><strong>Updated after @ruhalde suggestion</strong></p> <p>Now I am playing <a href="http://www.burninwave.com/#freqsweep" rel="noreferrer">Frequency sweep (20-20000 Hz)</a> file and this file generated following output.</p> <p><img src="https://i.stack.imgur.com/gO6xz.png" alt="Frequency sweep (20-20000 Hz) output"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload