
本文共 4429 字,大约阅读时间需要 14 分钟。
Android AudioRecord ������������������
���Android������������AudioRecord���������������������������������������������������API������������������������������������������
1. ������Buffer Size
������������������������������������������������������������������AudioRecord.getMinBufferSize���������������������������������������������������������������������������������������������
���������������
int bufferSize = AudioRecord.getMinBufferSize(sampleRate, channel, audioFormat);
C++ ���������
static jint android_media_AudioRecord_get_min_buff_size(JNIEnv *env, jobject thiz, jint sampleRateInHertz, jint channelCount, jint audioFormat) { // ������C++ AudioRecord���getMinFrameCount������ status_t result = AudioRecord::getMinFrameCount(&frameCount, sampleRateInHertz, format, audio_channel_in_mask_from_count(channelCount)); if (result == BAD_VALUE) { return 0; } if (result != NO_ERROR) { return -1; } return frameCount * channelCount * audio_bytes_per_sample(format);}
** AudioRecord.java ������ getMinBufferSize ���������**
public static int getMinBufferSize(int sampleRateInHz, int channelConfig, int audioFormat) { // ������������������������������ C++ ������������}
2. ��������� AudioRecord ������
������������������������������������AudioRecord���������������������������������������������������������������������������������������������������������������������
������������������
AudioRecord audioRecord = new AudioRecord( MediaRecorder.AudioSource.MIC, // ��������� sampleRate, // ��������� channel, // ��������� AudioFormat.ENCODING_PCM_16BIT, // ������������ bufferSize // ���������������);
** C++ ������������������������**
// ������ native_setup ��������� AudioRecord ������int initResult = native_setup(...);if (initResult != SUCCESS) { // ���������������}
3. ������������
������������������������ startRecording()��������������������� C++ ������ start ��������������������������������������������� ID���
** Java ������**
public void startRecording() throws IllegalStateException { // ������������������ if (mState != STATE_INITIALIZED) { throw new IllegalStateException("���������������������������������"); } // ������������ native_start(MediaSyncEvent.SYNC_EVENT_NONE, 0);}
** C++ ������**
status_t AudioRecord::start(AudioSystem::sync_event_t event, audio_session_t triggerSession) { // ��������������������� if (!(flags & CBLK_INVALID)) { status = mAudioRecord->start(event, triggerSession).transactionError(); } // ������������ if (flags & CBLK_INVALID) { status = restoreRecord_l("start"); } return status;}
** AudioFlinger ���������������**
// ��� AudioFlinger ������������������������status_t AudioFlinger::RecordThread::start(...) { // ������_RECORDTHREAD ������������ status_t status = AudioSystem::startInput(...); return status;}
4. ������������������
��������������������������� AudioRecord.read ���������������������������������������������������������������������������������������
** Java ������**
byte[] data = new byte[bufferSize];int bytesRead = audioRecord.read(data, 0, bufferSize);
** C++ ������**
// ������������int read = mAudioRecord->read(...)
5. ������������
���������������������������������.AudioRecord.stop() ������������������������������������������������������������������������������������
** Java ������**
public void stop() { try { stopRecording(); } catch (IllegalStateException e) { // ������������ }}
** C++ ������**
status_t AudioRecord::stop() { // ������������ ... return status;}
** AudioFlinger ���������������**
// ������������������status_t AudioSystem::stopInput(audio_port_handle_t portId) { // ������ AudioPolicyService ������������}
6. ������������������
7. ������
������ AudioRecord ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
