AudioCapture.rar

  • PUDN用户
    了解作者
  • Java
    开发工具
  • 1KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 5
    下载次数
  • 2013-10-21 00:42
    上传日期
Audio Capture Source Code for Andriod.
AudioCapture.rar
  • AudioCapture.java
    4.9KB
内容介绍
package com.android.musicvis; import android.util.Log; import android.media.audiofx.Visualizer; import java.util.Arrays; public class AudioCapture { private byte [] mRawVizData; private int [] mFormattedVizData; private byte [] mRawNullData = new byte[0]; private int [] mFormattedNullData = new int[0]; private Visualizer mVisualizer; private int mType; private static long MAX_IDLE_TIME_MS = 3000; private long mLastValidCaptureTimeMs; public static final int TYPE_PCM = 0; public static final int TYPE_FFT = 1; public AudioCapture(int type, int size) { mType = type; int[] range = new int[2]; range = Visualizer.getCaptureSizeRange(); if (size < range[0]) { size = range[0]; } if (size > range[1]) { size = range[1]; } mRawVizData = new byte[size]; mFormattedVizData = new int[size]; mVisualizer = null; try { mVisualizer = new Visualizer(0); if (mVisualizer != null) { if (mVisualizer.getEnabled()) { mVisualizer.setEnabled(false); } mVisualizer.setCaptureSize(mRawVizData.length); } } catch (UnsupportedOperationException e) { Log.e("AudioCapture", "Visualizer cstor UnsupportedOperationException"); } catch (IllegalStateException e) { Log.e("AudioCapture", "Visualizer cstor IllegalStateException"); } catch (RuntimeException e) { Log.e("AudioCapture", "Visualizer cstor RuntimeException"); } } public void start() { if (mVisualizer != null) { try { if (!mVisualizer.getEnabled()) { mVisualizer.setEnabled(true); mLastValidCaptureTimeMs = System.currentTimeMillis(); } } catch (IllegalStateException e) { Log.e("AudioCapture", "start() IllegalStateException"); } } } public void stop() { if (mVisualizer != null) { try { if (mVisualizer.getEnabled()) { mVisualizer.setEnabled(false); } } catch (IllegalStateException e) { Log.e("AudioCapture", "stop() IllegalStateException"); } } } public void release() { if (mVisualizer != null) { mVisualizer.release(); mVisualizer = null; } } public byte[] getRawData() { if (captureData()) { return mRawVizData; } else { return mRawNullData; } } public int[] getFormattedData(int num, int den) { if (captureData()) { if (mType == TYPE_PCM) { for (int i = 0; i < mFormattedVizData.length; i++) { // convert from unsigned 8 bit to signed 16 bit int tmp = ((int)mRawVizData[i] & 0xFF) - 128; // apply scaling factor mFormattedVizData[i] = (tmp * num) / den; } } else { for (int i = 0; i < mFormattedVizData.length; i++) { // apply scaling factor mFormattedVizData[i] = ((int)mRawVizData[i] * num) / den; } } return mFormattedVizData; } else { return mFormattedNullData; } } private boolean captureData() { int status = Visualizer.ERROR; boolean result = true; try { if (mVisualizer != null) { if (mType == TYPE_PCM) { status = mVisualizer.getWaveForm(mRawVizData); } else { status = mVisualizer.getFft(mRawVizData); } } } catch (IllegalStateException e) { Log.e("AudioCapture", "captureData() IllegalStateException: "+this); } finally { if (status != Visualizer.SUCCESS) { Log.e("AudioCapture", "captureData() : "+this+" error: "+ status); result = false; } else { // return idle state indication if silence lasts more than MAX_IDLE_TIME_MS byte nullValue = 0; int i; if (mType == TYPE_PCM) { nullValue = (byte)0x80; } for (i = 0; i < mRawVizData.length; i++) { if (mRawVizData[i] != nullValue) break; } if (i == mRawVizData.length) { if ((System.currentTimeMillis() - mLastValidCaptureTimeMs) > MAX_IDLE_TIME_MS) { result = false; } } else { mLastValidCaptureTimeMs = System.currentTimeMillis(); } } } return result; } }
评论
    相关推荐
    • FastStone Capture
      FastStone Capture,是一个仿站必备工具。通过它能很容易的截图、精准度量高、宽,提出颜色CSS代码。
    • FastStone Capture
      NULL 博文链接:https://jorgar.iteye.com/blog/726789
    • FastStone Capture
      FastStone Capture 小巧免安装,功能丰富强大,可以说是最小巧好用的录屏、截图软件了!不了解的可以自己百度搜。
    • FastStone Capture
      FSCapture是一款抓屏工具,其7.0版本强大功能包括:1.捕捉活动窗口; Faststone Capture界面截图2.捕捉窗口/对象;3.捕捉矩形区域;4.捕捉手绘区域;5.捕捉整个屏幕;6.捕捉滚动窗口;7.捕捉固定区域;8.屏幕放大器...
    • ScreenCapture
      一款自己写的Windows截屏小程序。
    • ScreenCapture
      ios 利用系统方法实现截取超出屏幕显示范围区域的截图.......
    • FastStone Capture
      FastStone Capture 是最火软件小编感觉最好用的截图软件!它集成了图像浏览、编辑和截图功能,支持包括BMP, JPEG, JPEG 2000, GIF, PNG, PCX, TIFF, WMF, ICO 和TGA在内的所有主流图片格式,其独有的光滑和毛刺处理...
    • CaptureScreen
      屏幕截图软件,可简单、快速对屏幕进行截图
    • ScreenCapture
      此文件包含组成 ScreenCapture 应用程序的每个文件的内容摘要。 ScreenCapture.vcproj 这是使用“应用程序向导”生成的 VC++ 项目的主项目文件。 它包含有关生成文件的 Visual C++ 版本的信息,以及 有关用...
    • capture.zip
      Capture desktop screen and region screen to file (jpg and bmp).