简体   繁体   English

如何降低Android中录制的音频可视化的速度?

[英]How To Slow Speed Of Recorded Audio Visualization In Android?

How To Slow Speed Of Recorded Audio Visualization In Android ? 如何降低Android中录制的音频可视化的速度?

I am able to record the voice from mic and play the recorded audio with visualization, But the speed of visualization is to fast, how can i slow the speed of visualization. 我可以录制麦克风中的声音并使用可视化播放录制的音频,但是可视化的速度要快,我如何才能减慢可视化的速度。 Below code is used to draw the visualization in android.. 下面的代码用于在android中绘制可视化效果。

public class VisualizerView1 extends View {

    private byte[] mBytes;
    private float[] mPoints;
    private Rect mRect = new Rect();
    private Paint mForePaint = new Paint();

    public VisualizerView1(Context context) {
        super(context);
        init1();
    }

    private void init1() {
        mBytes = null;
        mForePaint.setStrokeWidth(2f);
        mForePaint.setAntiAlias(true);
        mForePaint.setColor(Color.rgb(0, 255, 128));
    }

    public void updateVisualizer(byte[] bytes) {
        mBytes = bytes;
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (mBytes == null) {
            return;
        }
        if (mPoints == null || mPoints.length < mBytes.length * 4) {
            mPoints = new float[mBytes.length * 4];
        }
        mRect.set(0, 0, getWidth(), getHeight());

        for (int i = 0; i < mBytes.length - 1; i++) {
            mPoints[i * 4] = mRect.width() * i / (mBytes.length - 1);
            mPoints[i * 4 + 1] = mRect.height() / 2 + ((byte) (mBytes[i] + 128)) * (mRect.height() / 2) / 128;
            mPoints[i * 4 + 2] = mRect.width() * (i + 1) / (mBytes.length - 1);
            mPoints[i * 4 + 3] = mRect.height() / 2 + ((byte) (mBytes[i + 1] + 128)) * (mRect.height() / 2) / 128;
        }
        canvas.drawLines(mPoints, mForePaint);
    }

}

I have experimented with some visualizer code where i just "skip" every second frame. 我已经尝试过一些可视化工具代码,在这些代码中,我每隔第二帧就“跳过”一次。 Maybe this is what was you were looking for at the time. 也许这就是您当时正在寻找的东西。

I added a boolean, then just tests if this is true, and simply skip the code if not 我添加了一个布尔值,然后只是测试这是否正确,否则就跳过代码

private boolean frameSkip = false;


@Override
protected void onDraw(Canvas canvas) 
{
    if(frameSkip)
    {
        frameSkip = false;
    }
    else
    {
        frameSkip = true;
        ...Your code here
    }
    canvas.drawLines(mPoints, mForePaint);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM