bool LADPlayBuffer::LADPlayBufferInit(LADPlayer *playPointer,
                                      uint32 idx,
                                      uint32 sampleRate,
                                      uint32 chNum,
                                      int32 format,
                                      uint32 targetSR)
{
   //keep the format
   mFormat = format;

   //keep LADPlayer pointer and idx to buffer table
   pLadPlayer = playPointer;
   mIdx = idx;

   LOGD("LADPlayBufferInit sampleRate=%d ,ch=%d, format=%d",sampleRate,chNum,format);

   //set blisrc
   uint32 srcBufLen;
   BLI_GetMemSize( sampleRate, chNum, targetSR, LAD_CHANNEL_NUM, &srcBufLen);
   pSrcBuf = new int8[srcBufLen];
   pSrcHdl = BLI_Open( sampleRate, chNum, targetSR, LAD_CHANNEL_NUM, pSrcBuf);
   if ( !pSrcHdl ) return false;

   //buffer pointer setting
   mBuf.pBufBase = new int8[LAD_PLAY_BUFFER_LEN];
   mBuf.pRead = mBuf.pBufBase;
   mBuf.pWrite = mBuf.pBufBase;
   mBuf.bufLen = LAD_PLAY_BUFFER_LEN;

   LOGD("pBufBase: %p, pRead: %p, pWrite: %p, bufLen:%d \n",mBuf.pBufBase,mBuf.pRead,mBuf.pWrite,mBuf.bufLen);

   //initial mutex for buffer access
#if defined(PC_EMULATION)
   InitializeCriticalSection(&bMutex);
#else
	int ret;
   ret = pthread_mutex_init(&bMutex, NULL);
   if ( ret != 0 ) { return -1; }
#endif

   return true;
}
Beispiel #2
0
void AVB_Open()
{
   kal_uint32 uWorkingBuffer;
   kal_trace( TRACE_GROUP_SCO, L1AUDIO_AVB_OPEN, AVB.uState);
   ASSERT(AVB.uState == AVB_STATE_IDLE);
   ASSERT(AVB.uSampleRate);
   PcmSink_StartBT(PCMSINK_BT_SCO);
   mhdlHookPcmRut();
   BLI_GetMemSize(AVB.uSampleRate, AVB.uChannelNumber, AVB_SAMPLE_RATE, AVB_CHANNEL_NUM, &uWorkingBuffer);
   uWorkingBuffer = (uWorkingBuffer+3) & ~3;
   AVB.pBuffer = (kal_uint16 *)audio_alloc_mem_cacheable(uWorkingBuffer + AVB_DSP_BUFFER_SIZE + AVB_SRC_BUFFER_SIZE);                 
   ASSERT(AVB.pBuffer);
   AVB.pBLISRC = BLI_Open(AVB.uSampleRate, AVB.uChannelNumber, AVB_SAMPLE_RATE, AVB_CHANNEL_NUM, ((kal_int8*)AVB.pBuffer)+AVB_DSP_BUFFER_SIZE, audio_alloc_ext_mem_cacheable_simplified);
   ASSERT(AVB.pBLISRC);
   AVB.PCM.rb_base = ((kal_int8*)AVB.pBuffer)+AVB_DSP_BUFFER_SIZE+uWorkingBuffer;
   AVB.PCM.rb_size = AVB_SRC_BUFFER_SIZE;
   AVB.PCM.write   = 0;
   AVB.PCM.read    = 0;
   AVB.uAudID = L1Audio_GetAudioID();
   L1Audio_SetFlag( AVB.uAudID );
   L1Audio_SetEventHandler( AVB.uAudID, AVB_Process );
   AVB.uState = AVB_STATE_RUNING;
   L1Audio_HookHisrHandler( D2C_AUDIO_VIA_8KBT_ID, AVB_HISR, 0);
}
bool AudioYusuStreamIn::RecOpen()
{
   bool ret = true;
   m_no_data_count = 0;

   ALOGD("+RecOpen, mSampleRateModem:%d mSampleRate = %d",mSampleRateModem,mSampleRate);

   // this will set Mic gain base on current routing
   if(mSetSphEnh && mHw->SetMicGain(mInputSource) == false){
      ALOGD("RecOpen SetMicGain -- IN_CALL MODE");
   }

   if(mSetSphEnh == false){
      // VOICE_RECOGNITION, must disable sph enhancement
      // Remember to turn on again if we turn off it.
      int Device= mHw->Audio_Match_Input_device(mDevice,true); // turn on this deivce
      ALOGD("+RecOpen, mSetSphEnh=false mDevice = %x",Device);
      if(Device == android_audio_legacy::AudioSystem::DEVICE_IN_WIRED_HEADSET){
          mHw->mVolumeController->SetLadMicGain(Voice_Rec_Mic_Headset);
      }
      else{
          mHw->mVolumeController->SetLadMicGain(Voice_Rec_Mic_Handset);
      }
      //pLad->LAD_Set_Speech_Enhancement(mSetSphEnh);
      pLad->LAD_SetSpeechMode((ENUM_Speech_Mode)SPH_MODE_BT_CORDLESS);
      pLad->LAD_SetInputSource (LADIN_Microphone1);
      pLad->LAD_SetOutputDevice (LADOUT_SPEAKER2);

   }

   //Get Wake Lock for phone call recording
   acquire_wake_lock(PARTIAL_WAKE_LOCK, MD_RECORD_WAKELOCK_NAME);

   //Set Modem Sampling rate
   int32 mode;
   mHw->getMode(&mode);
   if ( mode == android_audio_legacy::AudioSystem::MODE_IN_CALL ) {
      mSampleRateModem = pLad->LAD_RecordSR()/*8000*/;
   }
   else if ( mSampleRate <= 8000 ) {
      mSampleRateModem = 8000;
   }
   else {
      mSampleRateModem = 16000;
   }

   //Modem Sampling rate convert to index
   int32 srIdx;
   if ( mSampleRateModem == 8000 )
      srIdx = Record_8k;
   else if ( mSampleRateModem == 16000 )
      srIdx = Record_16k;
   else {
      YAD_LOGE("RecOpen modem SR error, use 8k Hz \n");
      srIdx = Record_8k;
   }
   // call this function to decide set whick mode to modem.
   bool bStereoRecOn = false;
   SetHdrecordingMode(mode,&bStereoRecOn);

   // get real ch num for BLI
   uint8 mRealChNum;
#if defined(MTK_AUDIO_HD_REC_SUPPORT)
   if ((mHw->GetVmFlag() == true && mode == android_audio_legacy::AudioSystem::MODE_IN_CALL ) ||
   (mHw->META_Get_DualMic_Test_Mode()==TRUE) ||
   (mHw->GetCtm4WayFlag() == true && mode == android_audio_legacy::AudioSystem::MODE_IN_CALL ) ||
   (mode == android_audio_legacy::AudioSystem::MODE_IN_CALL)){
      mRealChNum = 1;
   }
   else {
      mRealChNum = (bStereoRecOn == true) ? 2 : 1;
      ALOGD(" mRealChNum = %d bStereoRecOn = %d",mRealChNum,bStereoRecOn);
   }
#else
   mRealChNum = 1;
#endif

   ALOGD("RecOpen Sampling Rate : %d, Modem Sample Rate : %d \n", mSampleRate, mSampleRateModem);

   //If modem sampling rate different from sampling rate, SRC required
   if ( (mSampleRateModem != mSampleRate) || mChNum != 1 && mFormat != android_audio_legacy::AudioSystem::VM_FMT ) {
       ALOGD("mSampleRateModem=%d, mRealChNum=%d, mSampleRate=%d need src pSrcHdl = %p mChNum = %d",
           mSampleRateModem,mRealChNum,mSampleRate,pSrcHdl,mChNum);
      uint32 srcBufLen;
      if(pSrcHdl == NULL){
          BLI_GetMemSize( mSampleRateModem, mRealChNum, mSampleRate, mChNum, &srcBufLen);
          pSrcBuf = new int8[srcBufLen];
          pSrcHdl = BLI_Open( mSampleRateModem, mRealChNum, mSampleRate, mChNum, pSrcBuf);
      }
      else{
          ALOGD("pSrcHdl exit = %p",pSrcHdl);
      }
      if ( !pSrcHdl ) return false;
   }

   // Add delay 10ms for Recording. Because record process is on-off-on (very quickly. about 2~8 tick counts),
   // modem side DSP has control flow problem. The recorded sound is bad.
   // So just add delay to work around this issue.
   // Modem side will also find out the root cause. If modem side fix this issue, remove this work around.
   usleep(10*1000);
   if( true == CanRecordFM(mode) )
   {


      pLad->LAD_SetInputSource(LADIN_FM_Radio);
      ALOGD("RecOpen, LAD_SetInputSource, LADIN_FM_Radio");


   }
   else
   {


//      pLad->LAD_SetInputSource(LADIN_Microphone1);
//      ALOGD("RecOpen, LAD_SetInputSource, LADIN_Microphone1");

   }

   //reset read and write pointer of internal buffer
   inBuf.pRead = inBuf.pBufBase;
   inBuf.pWrite = inBuf.pBufBase;
   ALOGD("SetRecDropFrameCount(%d)", m_DropFrameCount);
   pLad->LAD_SetRecDropFrameCount(m_DropFrameCount);

   //Start recording
   if ( mHw->GetVmFlag() == true && mode == android_audio_legacy::AudioSystem::MODE_IN_CALL ){
      ret &= pLad->LAD_OpenNormalRecPath(LADDATA_VM, 0);
      ALOGD("-RecOpen, LADDATA_VM");
   }
#if defined(MTK_DUAL_MIC_SUPPORT)||defined(MTK_AUDIO_HD_REC_SUPPORT)
   else if(mHw->META_Get_DualMic_Test_Mode()==TRUE){
      pLad->LAD_SetInputSource(LADIN_DualAnalogMic);
      // set rec level
      uint32 ladLevel = 0xffffff - (MAX_MIC_GAIN_DB - mHw->mDualMicTool_micGain) * 2;                                                                                                           // in 0.5dB
      ALOGD("set dual mic rec level level Rec: 0x%x, ladlevel: 0x%x",mHw->mDualMicTool_micGain,ladLevel);
      pLad->LAD_SetMicrophoneVolume(ladLevel);
      // start record
      ret &= pLad->LAD_OpenNormalRecPath(LADDATA_DUAL_MIC_VM, 0);
      ALOGD("-RecOpen, LADDATA_DUAL_MIC");
   }
#endif
   else if ( mHw->GetCtm4WayFlag() == true && mode == android_audio_legacy::AudioSystem::MODE_IN_CALL ){
      ret &= pLad->LAD_OpenNormalRecPath(LADDATA_CTM_4WAY, 0);
      ALOGD("-RecOpen, LADDATA_CTM_4WAY");
   }
#if !defined(MTK_AUDIO_HD_REC_SUPPORT)
   else{
      ret &= pLad->LAD_OpenNormalRecPath(LADDATA_PCM, srIdx);
   }
#else //MTK_AUDIO_HD_REC_SUPPORT = yes
   else if ( mode == android_audio_legacy::AudioSystem::MODE_IN_CALL ){