Sample Rate in Android Audio Record class and MediaRecord class

为君一笑 提交于 2019-12-25 16:46:14

问题


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); 

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

mrec.setAudioSamplingRate(samplingRate);

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.


回答1:


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);

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



来源:https://stackoverflow.com/questions/16354269/sample-rate-in-android-audio-record-class-and-mediarecord-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!