21
21
import android .view .View ;
22
22
23
23
/**
24
- * A class that draws waveform data received from a
24
+ * A class that draws visualizations of data received from a
25
25
* {@link Visualizer.OnDataCaptureListener#onWaveFormDataCapture }
26
26
*/
27
27
class VisualizerView extends View {
@@ -30,7 +30,6 @@ class VisualizerView extends View {
30
30
private byte [] mBytes ;
31
31
private byte [] mFFTBytes ;
32
32
private float [] mPoints ;
33
- private float [] mFFTPoints ;
34
33
private Rect mRect = new Rect ();
35
34
36
35
private Paint mCirclePaint = new Paint ();
@@ -125,6 +124,7 @@ private void rotateColours()
125
124
126
125
BarGraphRenderer mBarGraphRendererTop ;
127
126
BarGraphRenderer mBarGraphRendererBottom ;
127
+ CircleRenderer mCircleRenderer ;
128
128
129
129
@ Override
130
130
protected void onDraw (Canvas canvas ) {
@@ -140,25 +140,6 @@ protected void onDraw(Canvas canvas) {
140
140
141
141
mRect .set (0 , 0 , getWidth (), getHeight ());
142
142
143
- for (int i = 0 ; i < mBytes .length - 1 ; i ++) {
144
- float [] cartPoint = {
145
- (float )i / (mBytes .length - 1 ),
146
- mRect .height () / 2 + ((byte ) (mBytes [i ] + 128 )) * (mRect .height () / 2 ) / 128
147
- };
148
-
149
- float [] polarPoint = toPolar (cartPoint );
150
- mPoints [i * 4 ] = polarPoint [0 ];
151
- mPoints [i * 4 + 1 ] = polarPoint [1 ];
152
-
153
- float [] cartPoint2 = {
154
- (float )(i + 1 ) / (mBytes .length - 1 ),
155
- mRect .height () / 2 + ((byte ) (mBytes [i + 1 ] + 128 )) * (mRect .height () / 2 ) / 128
156
- };
157
-
158
- float [] polarPoint2 = toPolar (cartPoint2 );
159
- mPoints [i * 4 + 2 ] = polarPoint2 [0 ];
160
- mPoints [i * 4 + 3 ] = polarPoint2 [1 ];
161
- }
162
143
163
144
if (mCanvasBitmap == null )
164
145
{
@@ -178,10 +159,9 @@ protected void onDraw(Canvas canvas) {
178
159
paint2 .setAntiAlias (true );
179
160
paint2 .setColor (Color .argb (200 , 11 , 111 , 233 ));
180
161
mBarGraphRendererTop = new BarGraphRenderer (mCanvas , 4 , paint2 , true );
181
- }
182
-
183
- mCanvas .drawLines (mPoints , mCirclePaint );
184
162
163
+ mCircleRenderer = new CircleRenderer (mCanvas , paint2 );
164
+ }
185
165
186
166
// Draw normal line - offset by amplitude
187
167
for (int i = 0 ; i < mBytes .length - 1 ; i ++) {
@@ -212,6 +192,10 @@ protected void onDraw(Canvas canvas) {
212
192
mCanvas .drawLines (mPoints , mLinePaint );
213
193
}
214
194
195
+
196
+ AudioData audioData = new AudioData (mBytes );
197
+ mCircleRenderer .render (audioData , mRect );
198
+
215
199
// FFT time!!!!
216
200
if (mFFTBytes == null ) {
217
201
return ;
@@ -237,23 +221,6 @@ protected void onDraw(Canvas canvas) {
237
221
}
238
222
239
223
canvas .drawBitmap (mCanvasBitmap , new Matrix (), null );
240
- modulation += 0.04 ;
241
224
}
242
225
243
- float modulation = 0 ;
244
- float aggresive = 0.33f ;
245
- private float [] toPolar (float [] cartesian )
246
- {
247
- double cX = mRect .width ()/2 ;
248
- double cY = mRect .height ()/2 ;
249
- double angle = (cartesian [0 ]) * 2 * Math .PI ;
250
- double radius = ((mRect .width ()/2 ) * (1 - aggresive ) + aggresive * cartesian [1 ]/2 ) * (1.2 + Math .sin (modulation ))/2.2 ;
251
- float [] out = {
252
- (float )(cX + radius * Math .sin (angle )),
253
- (float )(cY + radius * Math .cos (angle ))
254
- };
255
- return out ;
256
- }
257
-
258
-
259
226
}
0 commit comments