Use new Visualizer class for animated wall papers based on audio output level.

Replaced use of MediaPLayer.snoop() by new Visualizer API to get audio visualization
data for wall papers in musicvis package.

Change-Id: Ib128b2952cecd70039d97c785516e5956365a5be
diff --git a/src/com/android/musicvis/vis5/Visualization5RS.java b/src/com/android/musicvis/vis5/Visualization5RS.java
index e92ef2c..fab7ac0 100644
--- a/src/com/android/musicvis/vis5/Visualization5RS.java
+++ b/src/com/android/musicvis/vis5/Visualization5RS.java
@@ -18,8 +18,8 @@
 
 import com.android.musicvis.R;
 import com.android.musicvis.RenderScriptScene;
+import com.android.musicvis.AudioCapture;
 
-import android.media.MediaPlayer;
 import android.os.Handler;
 import android.renderscript.Allocation;
 import android.renderscript.Element;
@@ -89,7 +89,8 @@
     // 2 indices per line
     private short [] mIndexData = new short[256*2];
 
-    private short [] mVizData = new short[1024];
+    private AudioCapture mAudioCapture = null;
+    private int [] mVizData = new int[1024];
 
     private static final int RSID_STATE = 0;
     private static final int RSID_POINTS = 1;
@@ -308,6 +309,10 @@
     public void start() {
         super.start();
         mVisible = true;
+        if (mAudioCapture == null) {
+            mAudioCapture = new AudioCapture(AudioCapture.TYPE_PCM, 1024);
+        }
+        mAudioCapture.start();
         updateWave();
     }
 
@@ -315,6 +320,11 @@
     public void stop() {
         super.stop();
         mVisible = false;
+        if (mAudioCapture != null) {
+            mAudioCapture.stop();
+            mAudioCapture.release();
+            mAudioCapture = null;
+        }
     }
 
     void updateWave() {
@@ -324,7 +334,12 @@
         }
         mHandler.postDelayed(mDrawCube, 20);
 
-        int len = MediaPlayer.snoop(mVizData, 0);
+        int len = 0;
+        if (mAudioCapture != null) {
+            // arbitrary scalar to get better range: 1024 = 4 * 256 (256 for 8 to 16 bit)
+            mVizData = mAudioCapture.getFormattedData(1024, 1);
+            len = mVizData.length;
+        }
 
         // Simulate running the signal through a rectifier by
         // taking the average of the absolute sample values.
@@ -337,7 +352,7 @@
                 }
                 volt += val;
             }
-            volt = volt * 4 / len; // arbitrary scalar to get better range
+            volt = volt / len;
         }
 
         // There are several forces working on the needle: a force applied by the
@@ -404,5 +419,4 @@
 
         mState.data(mWorldState);
     }
-
 }