Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have good result by using following calculations,for get a visualizer like <a href="http://postimage.org/image/9zowasxg9/" rel="nofollow">this</a> image. I am using nearly 19 images for displaying like this.These are responding by getFFT() method inputs.And be sure to enable both equalizer and visualizer,Otherwise it gives high values and fft values are responded to device volume.Actually i am not able to give explanation of the code because of my english.so i past code here.</p> <p><strong>VisualizerView:</strong></p> <pre><code>public class VisualizerView extends View { private byte[] mBytes; private float[] mPoints; Paint mForePaint = new Paint(); // private int width;// height; private Paint mPaint; Bitmap mBmpArray[]; int wTilesize; int hTilesize; int no_of_colomuns; private Bitmap peakBitmap; private float changeFromTop, changeFromLeft; private int images_drawn_starting_point ; int magnitudePoints[]; int max[] = new int[34]; int temp[]=new int[32]; private final int[][] images = { { R.drawable.blue_fade_1, R.drawable.blue_fade_2, R.drawable.blue_fade_3, R.drawable.blue_fade_4, R.drawable.blue_fade_5, R.drawable.blue_fade_6, R.drawable.blue_fade_7, R.drawable.blue_fade_8, R.drawable.blue_fade_9, R.drawable.blue_fade_10, R.drawable.blue_fade_11, R.drawable.blue_fade_12, R.drawable.blue_fade_13, R.drawable.blue_fade_14, R.drawable.blue_fade_15, R.drawable.blue_fade_16, R.drawable.blue_fade_17, R.drawable.blue_fade_18, R.drawable.blue_fade_19 }}; private final int IMAGES_LENTH = 19; public VisualizerView(Context context) { super(context); mBmpArray = new Bitmap[20]; init(); } public VisualizerView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public VisualizerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); images_drawn_starting_point = h; int temp; wTilesize = w / 34; // hTilesize = h / 30; temp = h - ((IMAGES_LENTH - 1) ); hTilesize = temp / (IMAGES_LENTH ); no_of_colomuns = ( w / (wTilesize)); magnitudePoints = new int[no_of_colomuns]; changeFromLeft = wTilesize + 3f;//For spacing left changeFromTop = hTilesize + 2.5f;//For spacing Right } public void init() { mPaint = new Paint(); mPaint.setColor(Color.BLACK); mPaint.setStrokeWidth(5f); } @Override public void draw(Canvas canvas) { super.draw(canvas); int h = canvas.getHeight(); int w = canvas.getWidth(); canvas.drawRect(new Rect(0, 0, w, h), mPaint); if (mBytes == null) { return; } if (mPoints == null || mPoints.length &lt; mBytes.length * 4) { mPoints = new float[mBytes.length * 4]; } double magnitude; //VisualizerActivity.THEME_COLOR=0 for (int j = 0; j &lt; IMAGES_LENTH; j++) loadTile(j,getResources().getDrawable(images[VisualizerActivity.THEME_COLOR][j])); for (int i = 0; i &lt; no_of_colomuns; i++) { byte rfk = mBytes[2 * i]; byte ifk = mBytes[2 * i + 1]; magnitude = ((rfk * rfk + ifk * ifk)); int dbValue = (int) (10 * Math.log10(magnitude)); magnitude = Math.round(dbValue * 8); try { magnitudePoints[i] = (int) magnitude; } catch (Exception e) { e.printStackTrace(); } } int left; int top; int index; try { index = 0; left = 0; int m = 1; if (VisualizerActivity.THEME_STYLE == 0) { // common for (int i = 0; i &lt; no_of_colomuns; i++) { top = images_drawn_starting_point; index = 18; for (int j = 0; j &lt; IMAGES_LENTH; j++) { if (j &gt; magnitudePoints[m] / IMAGES_LENTH) { canvas.drawBitmap(mBmpArray[0], left, top, mPaint); index++; } else { canvas.drawBitmap(mBmpArray[index--], left, top, mPaint); } top -= changeFromTop;// hTilesize+1.5; } m++; left += changeFromLeft;// wTilesize+2.5; } } } catch (Exception e) { e.getMessage(); } } public void loadTile(int key, Drawable tile) { try { Bitmap bitmap = Bitmap.createBitmap(wTilesize, hTilesize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); tile.setBounds(0, 0, wTilesize, hTilesize); tile.draw(canvas); mBmpArray[key] = bitmap; } catch (Exception e) { e.printStackTrace(); } } public void updateVisualizerWithFft(byte[] bytes) { if (AudioPlayer.player != null) { if (AudioPlayer.player.isPlaying()) { mBytes = bytes; } } invalidate(); } } </code></pre> <p><strong>In VisualizerActivity.java:</strong></p> <pre><code>AudioPlayer.mVisualizer.setCaptureSize(Visualizer .getCaptureSizeRange()[1]); AudioPlayer.mVisualizer.setDataCaptureListener( new Visualizer.OnDataCaptureListener() { public void onWaveFormDataCapture( Visualizer visualizer, byte[] bytes, int samplingRate) { // mVisualizerView.updateVisualizer(bytes); } public void onFftDataCapture(Visualizer visualizer, byte[] bytes, int samplingRate) { mVisualizerView.updateVisualizerWithFft(bytes); } }, Visualizer.getMaxCaptureRate() / 2, false, true); </code></pre>
 

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