在Android 5.0L的更新中提到(http://geeknizer.com/audio-improvements-in-android-5-0-l-audiophile/), Android开始支持96000Hz的采样率。但是,当我尝试在Galaxy S6上这样做时:
void checkAvailableSampleRate(){
for (int rate : new int[] {44100, 48000, 96000}) { // add the rates you wish to check against
int bufferSize = AudioRecord.getMinBufferSize(rate, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT);
if (bufferSize > 0) {
// buffer size is valid, Sample rate supported
Log.d(C.LOG_TAG,"Sample rate "+rate+" is supportted");
// just used for debugging
AudioRecord temp = new AudioRecord(MediaRecorder.AudioSource.MIC, rate, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
Log.d(C.LOG_TAG,"make audioRecord successfully ");
}
}
}
我无法使96000Hz工作....
下面是我得到的输出:
Sample rate 44100 is supportted
Make audioRecord successfully
Sample rate 48000 is supportted
Make audioRecord successfully
Sample rate 96000 is supportted
我的应用程序崩溃在这里,所以这意味着我可以得到minBuffer时采样率设置为96000Hz,但无法创建一个AudioRecord实例。
,这里是错误:
. lang。IllegalArgumentException: 96000Hz是不支持的样本率。
对我来说很奇怪的是,AudioRecord. getminbuffersize()在96000Hz下工作正常,但当我尝试创建96000Hz的AudioRecord时,应用程序崩溃了。
有没有人尝试在Android中录制96000Hz的音频?
-------------------------------------
这是我的gradle设置的更新:
android {
compileSdkVersion 21
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "edu.umich.cse.echotag"
minSdkVersion 21
targetSdkVersion 21
ndk {
moduleName "detection"
}
} ....
操作系统可能支持96k,但硬件也需要支持96k才能正常工作。
getMinBufferSize
可能不是检查硬件支持的采样率的可靠方法。我怎样才能知道我的平板电脑支持什么采样率?
AudioManager
可以查询设备的本机参数。如果您想检查是否支持96k,这可能很有用。
AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
Log.d(TAG, "onCreate: "+am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER));
Log.d(TAG, "onCreate: "+am.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE));
Log.d(TAG, "onCreate: "+am.getProperty(AudioManager.PROPERTY_SUPPORT_MIC_NEAR_ULTRASOUND));
Log.d(TAG, "onCreate: "+am.getProperty(AudioManager.PROPERTY_SUPPORT_SPEAKER_NEAR_ULTRASOUND));
more reading http://geeknizer.com/audio-improvements-in-android-5-0-l-audiophile/
希望对你有帮助