blob: 2f73524d9ffd0659aa91110c5ed3dc89bc4f023d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
package com.pheelicks.visualizer;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
public class CircleRenderer extends Renderer
{
private Paint mPaint;
/**
* Renders the audio data onto a pulsing circle
* @param canvas
* @param paint - Paint to draw lines with
*/
public CircleRenderer(Canvas canvas,
Paint paint)
{
super(canvas);
mPaint = paint;
}
@Override
public void onRender(AudioData data, Rect rect)
{
for (int i = 0; i < data.bytes.length - 1; i++) {
float[] cartPoint = {
(float)i / (data.bytes.length - 1),
rect.height() / 2 + ((byte) (data.bytes[i] + 128)) * (rect.height() / 2) / 128
};
float[] polarPoint = toPolar(cartPoint, rect);
mPoints[i * 4] = polarPoint[0];
mPoints[i * 4 + 1] = polarPoint[1];
float[] cartPoint2 = {
(float)(i + 1) / (data.bytes.length - 1),
rect.height() / 2 + ((byte) (data.bytes[i + 1] + 128)) * (rect.height() / 2) / 128
};
float[] polarPoint2 = toPolar(cartPoint2, rect);
mPoints[i * 4 + 2] = polarPoint2[0];
mPoints[i * 4 + 3] = polarPoint2[1];
}
mCanvas.drawLines(mPoints, mPaint);
// Controls the pulsing rate
modulation += 0.04;
}
@Override
public void onRender(FFTData data, Rect rect)
{
// Do nothing, we only display audio data
}
float modulation = 0;
float aggresive = 0.33f;
private float[] toPolar(float[] cartesian, Rect rect)
{
double cX = rect.width()/2;
double cY = rect.height()/2;
double angle = (cartesian[0]) * 2 * Math.PI;
double radius = ((rect.width()/2) * (1 - aggresive) + aggresive * cartesian[1]/2) * (1.2 + Math.sin(modulation))/2.2;
float[] out = {
(float)(cX + radius * Math.sin(angle)),
(float)(cY + radius * Math.cos(angle))
};
return out;
}
}
|