Android audio 一 源码路径
Android audio 二 AudioRecord 分析上
Android audio 三 AudioRecord 分析下
Android audio 四 AudioTrack 分析上
Android audio 五 AudioTrack 分析下
Android audio 六 AudioRecord AudiTrack 拾音放音例子
本例采用 AudioRecord AudiTrack cpp的方法实现拾音放音的例子,加深理解 Android 音频 native 层代码代码。
下载链接
sp <AudioTrack> pTrack;sp <AudioRecord> pRecord;
// 创建拾音 AudioRecord 实例pRecord = new AudioRecord(AUDIO_SOURCE_DEFAULT,48000,AUDIO_FORMAT_PCM_16_BIT,AUDIO_CHANNEL_IN_MONO,pAck,recordframeSize,NULL,NULL,0,AUDIO_SESSION_ALLOCATE,AudioRecord::TRANSFER_SYNC,AUDIO_INPUT_FLAG_NONE,-1,-1,NULL);// 创建拾音 AudioTrack实例pTrack = new AudioTrack( AUDIO_STREAM_MUSIC,48000,AUDIO_FORMAT_PCM_16_BIT,0x01,frameCount * 2,AUDIO_OUTPUT_FLAG_NONE,NULL,NULL,0,AUDIO_SESSION_ALLOCATE,AudioTrack::TRANSFER_SYNC,NULL,-1,-1,NULL,false,1.0f);// 拾音放音在同一线程中do{// num_read = fread(pBuffer, 1, 1024, wavFile);num_read = pRecord->read(pBuffer, 2048, true);if (num_read > 0){adLOGI("num_read %d", num_read);pTrack->write(pBuffer, num_read, 1);}}while (capturing && (num_read > 0));