Android AudioRecord初始化延迟 [英] Android AudioRecord Initialization delay

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

问题描述

以下是相关代码的示例,正​​在处理:

Here is a sample of the relevant code im working on:

AudioRecord recorder = setupAudio();
recorder.startRecording();

SetupAudio方法:

SetupAudio method:

public AudioRecord setupAudio() {

        AudioRecord recorder;

        minBufferSizeInBytes = AudioRecord.getMinBufferSize(
                RECORDER_SAMPLERATE, AudioFormat.CHANNEL_IN_MONO,
                AudioFormat.ENCODING_PCM_16BIT);

        Log.e("MoverAudio","BufferSize: " + minBufferSizeInBytes);

        recorder = new AudioRecord(MediaRecorder.AudioSource.CAMCORDER,
                RECORDER_SAMPLERATE, AudioFormat.CHANNEL_IN_MONO,
                AudioFormat.ENCODING_PCM_16BIT, minBufferSizeInBytes);

        return recorder;
    }

RECORDER_SAMPLERATE = 8000;

RECORDER_SAMPLERATE = 8000;

我正在尝试找出是否有任何方法可以缩短初始化时间.

Im trying to find out if there is any way to improve the time it takes to initialize.

当前对3种设备进行即时测试,结果如下:

Currently im testing it with 3 devices with the following results:

Galaxy S3

Galaxy S3

  • setupAudio:〜200ms
  • startRecording():〜280ms

Galaxy S3 mini

Galaxy S3 mini

  • setupAudio:〜10ms
  • startRecording():〜290ms

Galaxy Nexus

Galaxy Nexus

  • setupAudio:〜10ms
  • startRecording():〜235ms

BufferSizes:

BufferSizes:

  • Nexus:704
  • s3:1024
  • s3 mini:640

但是,仅来自银河系联系的数据可用. 对于我的应用程序,我必须能够尽快获取音频数据.使用当前值,只有Nexus在可接受的时间内.

However, only the data from the galaxy nexus is usable. For the purpose of my application I have to be able to get the audio Data as soon as possible. With the current values only the Nexus is within acceptable time.

S3 mini看起来速度较快,因为它仅比Nexus花费更多,但是最初的〜200ms样本被列为0,因此不可用.

The S3 mini may seem fast since it only takes a bit more than the Nexus, however the first ~200ms of sample are listed as 0, so it's not usable.

根据我对收集到的数据进行分析后的了解,S3和S3 mini上的音频似乎已经过某种程度的过滤,因为看到的结果是FFT更加整洁,低频声音总是不那么明显. 这是S3mini和Galaxy Nexus录制的音频的示例:

From what i understand after analyzing the data gathered, the audio on the S3 and S3 mini seems to be somehow filtered seeing that the resulting FFT is a lot more clean and the low frequency sounds are always a lot less visible. Here is an example of both S3mini and Galaxy Nexus recorded audio:

http://img41.imageshack.us/img41/4177/ox7h.png S3 Mini

http://img690.imageshack.us/img690/8717/iya6.png Galaxy Nexus

http://img690.imageshack.us/img690/8717/iya6.png Galaxy Nexus

推荐答案

如果请求长缓冲区,则必须等待操作系统以当前采样率填充它.如果您要求的采样率不是硬件ADC正在运行的采样率,则必须另外等待重采样器滤波器的延迟.不同的Android设备和操作系统版本可能支持不同的最小缓冲区大小和本机硬件采样率.

If you request a long buffer, then you have to wait for the OS to fill it at the current sample rate. If you request a sample rate other than what the hardware ADC is running, then you have to additionally wait for the resampler filter delay. Different Android devices and OS versions may support different minimum buffer sizes and native hardware sample rates.

隐藏延迟的一种技术是在应用程序的生命周期中更早地开始录制,并不断丢弃音频样本,直到应用程序需要它们为止.这样就没有启动开销了.

One technique to hide the latency is to start recording earlier in the app's life cycle, and just keep throwing away audio samples until the app needs them. Then there is no startup overhead.

已添加:在某些设备/OS版本上,数据可能确实会以某种硬件采样率(例如在44.1k或48kHz时为4096)捕获到更长的OS驱动程序缓冲区中,并且只有在填充了其中一些缓冲区之后,才进行了转换到另一个采样率,然后切成较短的请求缓冲区长度,音频命令开始将数据发送到应用.要绕过,即使有可能,您可能需要修改操作系统并编写自己的ADC驱动程序.但是,请尝试使用较高的采样率(44.1k或48k),并首先请求使用较短的缓冲区.

Added: On some devices/OS versions, the data may really be captured into longer OS driver buffers at some hardware sample rate (for instance 4096 at 44.1k or 48kHz) and only after a couple of those buffers are filled, converted to another sample rate, and the chopped into the shorter requested buffer lengths, with the audio command start sending data to an app. To bypass, if even possible, you might need to mod the OS and write your own ADC driver. But try using a higher sample rate (44.1k or 48k) and request shorter buffers first.

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

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