android音频采集

1:创建一个AudioRecord类


AudioRecord *mpAudioRecord=new AudioRecord();


2:设置采集参数


       2.2版本:


        mpAudioRecord->set(AUDIO_SOURCE_DEFAULT, 0, 0,

AudioSystem::CHANNEL_IN_MONO, 0, 0,  AudioRecordCallback, this,  0,0);


      2.3版本:(多了一个参数)


       mpAudioRecord->set(AUDIO_SOURCE_DEFAULT, 0, 0,

AudioSystem::CHANNEL_IN_MONO, 0, 0,  AudioRecordCallback, this,  0,0,0);
 

3:检查设置是否成功:


       if (mpAudioRecord->initCheck() != NO_ERROR)
         

return -1;  //error!
 

4:启动采集:
      

mpAudioRecord->start();
 

5:采集回调函数的定义:
 

void Caudioplayer::AudioRecordCallback(int event, void* user, void *info)
{

        if (event != AudioTrack::EVENT_MORE_DATA)
                 return;
        Caudioplayer *audioplayer=static_cast<Caudioplayer*>(user);
        AudioTrack::Buffer *buffer = static_cast<AudioTrack::Buffer *>(info);
        short *lpOut = buffer->i16;
        Mutex::Autolock lock(audioplayer->mLock);
        copy_size=4096>buffer->size?buffer->size:4096;
        memcpy(tembuffer,lpOut,copy_size);
}





本文转自 fanxiaojun 51CTO博客,原文链接:http://blog.51cto.com/2343338/998112,如需转载请自行联系原作者

上一篇:spring mvc与mybatis事务整合


下一篇:【转载】ASP.NET线程安全与静态变量的生命周期浅谈