音频编码
说明:
此处使用MediaCodec对由MIC采集的数据进行硬编码
- 采集音频数据
参数设置:
输入:MediaRecorder.AudioSource.MIC
采样率:44100
声道:AudioFormat.CHANNEL_IN_MONO//单声道
采样大小:AudioFormat.ENCODING_PCM_16BIT//2个字节
比特率:64000
mBufferSizeInBytes = AudioRecord.getMinBufferSize(mSampleRateInHz, mChannelConfig, mAudioFormat)
mAudioRecord = AudioRecord(
mAudioSource,//输入
mSampleRateInHz, //采样率
mChannelConfig, //声道
mAudioFormat, //采样大小
mBufferSizeInBytes)//缓冲大小
if(AudioRecord.ERROR_BAD_VALUE == mBufferSizeInBytes
|| AudioRecord.ERROR == mBufferSizeInBytes){
Log.e(TAG, "unable to getMinBufferSize")
isRecording = false
return
}
if(mAudioRecord?.state == AudioRecord.STATE_UNINITIALIZED){
Log.e(TAG, "AudioRecord is uninitialized")
isRecording = false
return
}
val thread = Thread(RecordTask())
thread.start()
inner class RecordTask: Runnable