Android的AudioRecord问题吗? [英] Android AudioRecord questions?

查看:191
本文介绍了Android的AudioRecord问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在瞎搞了Android API的AudioRecord特征,发现了一些奇怪的行为吧。

I have been messing around with the AudioRecord feature of the Android API and found some strange behaviors with it.

背景信息: 我的手机是HTC不可思议 我使用的Eclipse插件为Android开发的模拟器。 目标平台或操作系统是2.2 ......既然是我的手机使用。

Background info: My phone is a HTC Incredible I am using the Eclipse plugin for Android development with the emulator. Targeted platform or OS is 2.2... Since it is what my phone uses.

有些code:

bufferSize = AudioRecord.getMinBufferSize(FREQUENCY, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT);
audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, FREQUENCY, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);

这是在code我用它来设置AudioRecord API使用。现在,模拟器也喜欢频率设置为8000为它工作。回来与缓冲区大小640对于手机我用44100的一个问题在这里似乎得到的PCM数据的波动似乎是8位有符号的浪潮。我得到的值从-127到128。我认为值 AudioFormat.ENCODING_PCM_16BIT 会产生不同的东西。

This is the code I use to setup the AudioRecord API with. Now, for the emulator it likes FREQUENCY to be set to 8000 for it to work. Comes back with a buffer size 640. For the phone I use 44100. One issue here is it seems the resulting PCM data for the wave seems to be an eight bit signed wave. I get values from -127 to 128. I thought the value AudioFormat.ENCODING_PCM_16BIT would produce something different.

我处理一个线程音频,

public void run() {
  while(isRecording) {
    audioRecord.startRecording();
    byte[] data = new byte[bufferSize];
    audioRecord.read(data, 0, bufferSize);
    listener.setData(data);
    handleData(data);
  }
  audioRecord.release();
}

我有办法以图形方式显示于使用 SurfaceView 相应的波的实时性。似乎有一个很大的噪音从MIC到来。我得到这个噪声仿真器和手机为好。我是否需要通过某种过滤器(S)的运行数据?我想用这个数据来计算一些有趣的FFT和东西只是为了玩的浪潮。但我需要降低噪音不知何故。

I have a way to graphically display to corresponding wave in real time using a SurfaceView. There seems to be a lot of noise coming from the MIC. I get this noise from the emulator and the phone as well. Do I need to run the data through some sort of filter(s)? I would like to use this data to calculate some fun FFT and stuff just to play around with the wave. But I need to reduce the noise somehow.

有没有其他人的经验这一点。有没有人有办法解决吗?

Has anyone else experience this as well. Does anyone have a solution?

我AP preciated你的时间和响应, 谢谢, DK

I appreciated your time and responses, thanks, dk

推荐答案

当您阅读从AudioFormat.ENCODING_PCM_16BIT字节流,它可以使你俩上下每个样品的2个连续的字节字节。这会显得极其嘈杂的,如果你只是把每个字节是一个样本(而不是一半样本,它实际上是),再加上签售会是错误的第一个字节(它在小尾数顺序)。

When you read bytes from a "AudioFormat.ENCODING_PCM_16BIT" stream, it actually gives you both the upper and lower bytes of each sample as 2 sequential bytes. This will seem extremely noisy if you just take each byte to be a sample (instead of the half sample it actually is), plus the signing will be wrong for the first byte (it's in little endian order).

要得到有意义的数据输出流,通过短裤读,如:

To get meaningful data out of the stream, read via shorts, e.g.

public void run() {
  while(isRecording) {
    audioRecord.startRecording();
    short[] data = new short[bufferSize/2];
    audioRecord.read(data, 0, bufferSize/2);
    listener.setData(data);
    handleData(data);
  }
  audioRecord.release();
}

这篇关于Android的AudioRecord问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆