diff options
Diffstat (limited to 'src/com/pheelicks/visualizer/renderer/BarGraphRenderer.java')
-rw-r--r-- | src/com/pheelicks/visualizer/renderer/BarGraphRenderer.java | 95 |
1 files changed, 49 insertions, 46 deletions
diff --git a/src/com/pheelicks/visualizer/renderer/BarGraphRenderer.java b/src/com/pheelicks/visualizer/renderer/BarGraphRenderer.java index b17a695..fefd36c 100644 --- a/src/com/pheelicks/visualizer/renderer/BarGraphRenderer.java +++ b/src/com/pheelicks/visualizer/renderer/BarGraphRenderer.java @@ -4,6 +4,7 @@ * Licensed under the MIT license: * http://creativecommons.org/licenses/MIT/ */ + package com.pheelicks.visualizer.renderer; import android.graphics.Canvas; @@ -15,55 +16,57 @@ import com.pheelicks.visualizer.FFTData; public class BarGraphRenderer extends Renderer { - private int mDivisions; - private Paint mPaint; - private boolean mTop; + private int mDivisions; + private Paint mPaint; + private boolean mTop; - /** - * Renders the FFT data as a series of lines, in histogram form - * @param divisions - must be a power of 2. Controls how many lines to draw - * @param paint - Paint to draw lines with - * @param top - whether to draw the lines at the top of the canvas, or the bottom - */ - public BarGraphRenderer(int divisions, - Paint paint, - boolean top) - { - super(); - mDivisions = divisions; - mPaint = paint; - mTop = top; - } + /** + * Renders the FFT data as a series of lines, in histogram form + * + * @param divisions - must be a power of 2. Controls how many lines to draw + * @param paint - Paint to draw lines with + * @param top - whether to draw the lines at the top of the canvas, or the + * bottom + */ + public BarGraphRenderer(int divisions, + Paint paint, + boolean top) + { + super(); + mDivisions = divisions; + mPaint = paint; + mTop = top; + } - @Override - public void onRender(Canvas canvas, AudioData data, Rect rect) - { - // Do nothing, we only display FFT data - } + @Override + public void onRender(Canvas canvas, AudioData data, Rect rect) + { + // Do nothing, we only display FFT data + } - @Override - public void onRender(Canvas canvas, FFTData data, Rect rect) - { - for (int i = 0; i < data.bytes.length / mDivisions; i++) { - mFFTPoints[i * 4] = i * 4 * mDivisions; - mFFTPoints[i * 4 + 2] = i * 4 * mDivisions; - byte rfk = data.bytes[mDivisions * i]; - byte ifk = data.bytes[mDivisions * i + 1]; - float magnitude = (rfk * rfk + ifk * ifk); - int dbValue = (int) (10 * Math.log10(magnitude)); + @Override + public void onRender(Canvas canvas, FFTData data, Rect rect) + { + for (int i = 0; i < data.bytes.length / mDivisions; i++) { + mFFTPoints[i * 4] = i * 4 * mDivisions; + mFFTPoints[i * 4 + 2] = i * 4 * mDivisions; + byte rfk = data.bytes[mDivisions * i]; + byte ifk = data.bytes[mDivisions * i + 1]; + float magnitude = (rfk * rfk + ifk * ifk); + int dbValue = (int) (10 * Math.log10(magnitude)); - if(mTop) - { - mFFTPoints[i * 4 + 1] = 0; - mFFTPoints[i * 4 + 3] = (dbValue * 2 - 10); - } - else - { - mFFTPoints[i * 4 + 1] = rect.height(); - mFFTPoints[i * 4 + 3] = rect.height() - (dbValue * 2 - 10); - } - } + if (mTop) + { + mFFTPoints[i * 4 + 1] = 0; + mFFTPoints[i * 4 + 3] = (dbValue * 2 - 10); + } + else + { + mFFTPoints[i * 4 + 1] = rect.height(); + mFFTPoints[i * 4 + 3] = rect.height() - (dbValue * 2 - 10); + } + } - canvas.drawLines(mFFTPoints, mPaint); - } + canvas.drawLines(mFFTPoints, mPaint); + } } |