Visualization2RS.java revision 7eb6bcc2cbc062abea4f3c9d3e542215697c7b66
1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.musicvis.vis2;
18
19import com.android.musicvis.GenericWaveRS;
20import com.android.musicvis.R;
21
22import android.media.MediaPlayer;
23
24class Visualization2RS extends GenericWaveRS {
25
26    Visualization2RS(int width, int height) {
27        super(width, height, R.drawable.fire);
28    }
29
30    @Override
31    public void update() {
32
33        int len = MediaPlayer.snoop(mVizData, 0);
34
35        int outlen = mPointData.length / 8;
36        if (len > outlen) len = outlen;
37
38        if (len == 0) {
39            if (mWorldState.idle == 0) {
40                mWorldState.idle = 1;
41                //mState.data(mWorldState);
42                updateWorldState();
43            }
44            return;
45        }
46        if (mWorldState.idle != 0) {
47            mWorldState.idle = 0;
48            //mState.data(mWorldState);
49            updateWorldState();
50        }
51        // TODO: might be more efficient to push this in to renderscript
52        for(int i = 0; i < len; i++) {
53            int amp = mVizData[i] / 128;
54            mPointData[i*8+1] = amp;
55            mPointData[i*8+5] = -amp;
56        }
57        mPointAlloc.data(mPointData);
58    }
59
60}
61