AudioCapture.rar

  • PUDN用户
    了解作者
  • Unix_Linux
    开发工具
  • 1KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2
    下载次数
  • 2014-06-26 21:19
    上传日期
Audio Capture for Embedded Linux.
AudioCapture.rar
  • AudioCapture.c
    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; } }
评论
    相关推荐
    • AudioCapture.zip
      FFmepg 基于Windows的音频采集
    • AudioCapture.rar
      Audio Capture Source Code for Andriod.
    • AudioCapture.rar
      可实现基本的蓝牙功能,此为源文件与代码。用于基本android开发。
    • AudioCapture.rar
      Audio Capture for Embedded Linux.
    • AudioCapture.rar
      mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); ...
    • audio capture 音频采集 C++ 源码
      c++实现的一个音频采集的工程 非常好的学习的例子
    • Audio Capture-crx插件
      语言:Bahasa Indonesia,Bahasa Melayu,Deutsch,English,English (UK),English (United States),Filipino,Français,Kiswahili,Nederlands,Norsk,Tiếng Việt,Türkçe,català,dansk,eesti,español,hrvatski,...
    • AudioCapture-WindowsApi.rar
      利用windows的waveAPI完成音频的录制和播放功能,利用SpeeX库完成编码解码功能
    • Chrome Audio Capture-crx插件
      Chrome Audio Capture是Chrome扩展程序,可让用户捕获当前标签上播放的所有音频。 可以同时捕获多个选项卡。 捕获内容可以另存为.mp3或.wav文件。 用户可以选择使当前正在捕获的标签静音。 要开始在选项卡上捕获,只...
    • NS2example.rar
      在ns2下实现无线传感器网络仿真,多个节点进行网络活动