Android Audio Record类和MediaRecord类中的采样率 [英] Sample Rate in Android Audio Record class and MediaRecord class

查看:977
本文介绍了Android Audio Record类和MediaRecord类中的采样率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在Android AudioRecord类和Media record类中设置音频采样率有何区别?在音频记录类中,我们在创建类之类的对象时设置采样率

i want to know what is the difference between setting audio sample rate in Android AudioRecord class and Media record class? In audio record class we set sample rate while creating an object of the class like

recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
                                            SampleRateInHz, RECORDER_CHANNELS,RECORDER_AUDIO_ENCODING, bufferSize); 

在MediaRecorder类中,我们通过函数调用进行显式设置.即

while in MediaRecorder class we set explicitly through a function call. i.e.

mrec.setAudioSamplingRate(samplingRate);

我都尝试过,但是采样率的效果只能在音频记录中看到,而在通过mediaRecorder类记录时却看不到.我不明白两者之间的区别.

I tried both but effect of sample rate can only be seen while audio recording not while recording throug mediaRecorder class. I can not understand what is the differnce between both.

推荐答案

作为android sdk文档的 MediaRecord 用于录制音频和视频.记录控件基于简单的状态机.除非需要访问原始音频数据并进行处理(例如,应用您自己的DSP效果),否则您将始终使用MediaRecord记录声音, .在这种情况下,您将使用AudioRecord.setAudioSamplingRate MediaRecord的设置与将SampleRateInHz传递到AudioRecord的操作相同,设置所需的采样率.采样率越高,您将获得越好的音质和频率范围.理想的人耳可以听到20至20000 hz.如果将采样率设置为4100hz,则频率响应将等于4100/2,几乎是20000hz.但是设备支持的频率范围是不同的.您应该始终检查设备是否支持您所需的频率.

AS of android sdk documentation, MediaRecord is used to record audio and video. The recording control is based on a simple state machine. You will always use MediaRecord to record sounds unless you need to access the raw audio data and process them(eg, apply your own DSP effects).In this scenario you will use AudioRecord.setAudioSamplingRateof MediaRecord does the same as passing SampleRateInHz to the AudioRecord, setting the desired sampling rate.The higher the sampling rate the better sound quality and frequency range you will get.An ideal uman ear can hear sound from 20 to 20000 hz.If you set your sampling rate to 4100hz then your frequency response will equal to 4100/2 which is almost 20000hz.However the supported freq range by devices are different. you should always check if the device supports your desired frequency.

为了检查特定的频率是否有效,您可以使用以下代码:

In order to check if a specific freq works, you may use the following piece of code:

    int bufferSize = AudioRecord.getMinBufferSize(rate[i],AudioFormat.CHANNEL_IN_MONO,AudioFormat.ENCODING_PCM_16BIT);

如果bufferSize值大于0,则表明设备支持您提供的频率.

if bufferSize value is bigger than 0 then you the requency you provided is supported by device.

这篇关于Android Audio Record类和MediaRecord类中的采样率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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