Use triangle strip instead of individual lines.

Make the visualization display use a triangle strip instead
of individual vertical lines.
b/5553287

Change-Id: I2a0084941e62ec008a8edc5f88e9fc7137c33a7e
diff --git a/src/com/android/musicvis/GenericWaveRS.java b/src/com/android/musicvis/GenericWaveRS.java
index f34a4c0..6e5d8ef 100644
--- a/src/com/android/musicvis/GenericWaveRS.java
+++ b/src/com/android/musicvis/GenericWaveRS.java
@@ -60,8 +60,8 @@
     protected float [] mPointData = new float[1024*8];
 
     private Allocation mLineIdxAlloc;
-    // 2 indices per line
-    private short [] mIndexData = new short[1024*2];
+    // 2 initial, plus one for each triangle, 2 triangles per sample
+    private short [] mIndexData = new short[2+1024*2];
 
     private ProgramVertex mPVBackground;
     private ProgramVertexFixedFunction.Constants mPVAlloc;
@@ -142,8 +142,8 @@
         mLineIdxAlloc = Allocation.createSized(mRS, Element.U16(mRS), mIndexData.length,
                                                Allocation.USAGE_GRAPHICS_VERTEX |
                                                Allocation.USAGE_SCRIPT);
-        // This will be a line mesh
-        meshBuilder.addIndexSetAllocation(mLineIdxAlloc, Primitive.LINE);
+        // This will be a triangle strip mesh
+        meshBuilder.addIndexSetAllocation(mLineIdxAlloc, Primitive.TRIANGLE_STRIP);
 
         // Create the Allocation for the vertices
         mCubeMesh = meshBuilder.create();
diff --git a/src/com/android/musicvis/waveform.rs b/src/com/android/musicvis/waveform.rs
index c3d75f2..1c5116d 100644
--- a/src/com/android/musicvis/waveform.rs
+++ b/src/com/android/musicvis/waveform.rs
@@ -62,12 +62,9 @@
     float amp3 = sin(0.011f * wave3amp) * 40;
     float amp4 = sin(0.031f * wave4amp) * 20;
     // calculate how many invisible lines there are on each side
-    int skip = (1024 - gWidth) / 2;
-    if (skip < 0) skip = 0;
-    int end = 1024 - skip;
-    for (int i = skip; i < end; i++) {
-        float val = sin(0.013f * (wave1pos + i)) * amp1
-                  + sin(0.029f * (wave2pos + i)) * amp2;
+    for (int i = 0; i < 1024; i++) {
+        float val = fabs(sin(0.013f * (wave1pos + i)) * amp1
+                  + sin(0.029f * (wave2pos + i)) * amp2);
         float off = sin(0.005f * (wave3pos + i)) * amp3
                   + sin(0.017f * (wave4pos + i)) * amp4;
         if (val < 2.f && val > -2.f) val = 2.f;
@@ -89,19 +86,13 @@
 
     int i;
 
-    // calculate how many invisible lines there are on each side
-    int width = gWidth;
-    if (width > 1024) width = 1024;
-    int skip = (1024 - width) / 2;
-    int end = 1024 - skip;
-
     if (gIdle) {
 
         // idle state animation
         float *points = (float*)gPoints;
         if (fadeoutcounter > 0) {
             // fade waveform to 0
-            for (i = skip; i < end; i++) {
+            for (i = 0; i < 1024; i++) {
                 float val = fabs(points[i*8+1]);
                 val = val * FADEOUT_FACTOR;
                 if (val < 2.f) val = 2.f;
@@ -127,7 +118,7 @@
             if (waveCounter != gWaveCounter) {
                 waveCounter = gWaveCounter;
                 float *points = (float*)gPoints;
-                for (i = skip; i < end; i++) {
+                for (i = 0; i < 1024; i++) {
                     float val = fabs(points[i*8+1]);
                     points[i*8+1] = (val * (FADEIN_LENGTH - fadeincounter) + idle[i*8+1] * fadeincounter) / FADEIN_LENGTH;
                     points[i*8+5] = (-val * (FADEIN_LENGTH - fadeincounter) + idle[i*8+5] * fadeincounter) / FADEIN_LENGTH;
@@ -158,7 +149,7 @@
     rsMatrixScale(&mat1, scale, scale, scale);
     rsgProgramVertexLoadModelMatrix(&mat1);
 
-    rsgDrawMesh(gCubeMesh, 0, skip * 2, width * 2);
+    rsgDrawMesh(gCubeMesh);
 
     return 1;
 }