status_t AudioALSAFMController::setFmEnable(const bool enable, const audio_devices_t output_device) { // Lock to Protect HW Registers & AudioMode // TODO(Harvey): get stream manager lock here? AudioAutoTimeoutLock _l(mLock); ALOGD("+%s(), mFmEnable = %d => enable = %d", __FUNCTION__, mFmEnable, enable); // Check Current Status if (enable == mFmEnable) { ALOGW("-%s(), enable == mFmEnable, return.", __FUNCTION__); return INVALID_OPERATION; } // Update Enable Status mFmEnable = enable; // get current device ALOGD("%s(), output_device = 0x%x", __FUNCTION__, output_device); AudioALSASampleRateController *pAudioALSASampleRateController = AudioALSASampleRateController::getInstance(); if (mFmEnable == true) // Open { #if 0 // local print only ALOGD("IsFMMergeInterfaceSupported = %d", WCNChipController::GetInstance()->IsFMMergeInterfaceSupported()); ALOGD("IsFmChipPadSelConnSys = %d", WCNChipController::GetInstance()->IsFmChipPadSelConnSys()); ALOGD("IsFmChipUseSlaveMode = %d", WCNChipController::GetInstance()->IsFmChipUseSlaveMode()); ALOGD("GetFmChipSamplingRate = %d", WCNChipController::GetInstance()->GetFmChipSamplingRate()); ALOGD("IsBTMergeInterfaceSupported = %d", WCNChipController::GetInstance()->IsBTMergeInterfaceSupported()); ALOGD("BTChipHWInterface = %d", WCNChipController::GetInstance()->BTChipHWInterface()); ALOGD("BTUseCVSDRemoval = %d", WCNChipController::GetInstance()->BTUseCVSDRemoval()); ALOGD("BTChipSamplingRate = %d", WCNChipController::GetInstance()->BTChipSamplingRate()); ALOGD("BTChipSamplingRateNumber = %d", WCNChipController::GetInstance()->BTChipSamplingRateNumber()); ALOGD("BTChipSyncFormat = %d", WCNChipController::GetInstance()->BTChipSyncFormat()); ALOGD("BTChipSyncLength = %d", WCNChipController::GetInstance()->BTChipSyncLength()); ALOGD("BTChipSecurityHiLo = %d", WCNChipController::GetInstance()->BTChipSecurityHiLo()); ALOGD("GetBTCurrentSamplingRateNumber = %d", WCNChipController::GetInstance()->GetBTCurrentSamplingRateNumber()); #endif // set default 44100 Hz pAudioALSASampleRateController->setPrimaryStreamOutSampleRate(44100); pAudioALSASampleRateController->setScenarioStatus(PLAYBACK_SCENARIO_FM); WCNChipController::GetInstance()->SetFmChipSampleRate(getFmDownlinkSamplingRate()); // Set Audio Digital/Analog HW Register if (checkFmNeedUseDirectConnectionMode(output_device) == true) { setFmDirectConnection(true, true); mHardwareResourceManager->startOutputDevice(output_device, getFmDownlinkSamplingRate()); } else { mIsFmDirectConnectionMode = false; } // Set Direct/Indirect Mode to FMAudioPlayer doDeviceChangeCallback(); } else // Close { // Disable Audio Digital/Analog HW Register if (mIsFmDirectConnectionMode == true) { mHardwareResourceManager->stopOutputDevice(); } setFmDirectConnection(false, true); // reset FM playback status pAudioALSASampleRateController->resetScenarioStatus(PLAYBACK_SCENARIO_FM); } ALOGD("-%s()", __FUNCTION__); return NO_ERROR; }
status_t AudioALSACaptureDataProviderEchoRefExt::open() { ALOGD("%s()", __FUNCTION__); ASSERT(mClientLock.tryLock() != 0); // lock by base class attach AudioAutoTimeoutLock _l(mEnableLock); AudioAutoTimeoutLock _l2(*AudioALSADriverUtility::getInstance()->getStreamSramDramLock()); ASSERT(mEnable == false); AudioALSASampleRateController *pAudioALSASampleRateController = AudioALSASampleRateController::getInstance(); pAudioALSASampleRateController->setScenarioStatus(PLAYBACK_SCENARIO_ECHO_REF_EXT); // config attribute (will used in client SRC/Enh/... later) // TODO(Sam): query the mConfig? mStreamAttributeSource.audio_format = AUDIO_FORMAT_PCM_16_BIT; mStreamAttributeSource.audio_channel_mask = AUDIO_CHANNEL_IN_STEREO; mStreamAttributeSource.num_channels = android_audio_legacy::AudioSystem::popCount(mStreamAttributeSource.audio_channel_mask); mStreamAttributeSource.sample_rate = AudioALSASampleRateController::getInstance()->getPrimaryStreamOutSampleRate(); mConfig.channels = mStreamAttributeSource.num_channels; mConfig.rate = mStreamAttributeSource.sample_rate; // Buffer size: 2048(period_size) * 2(ch) * 2(byte) * 8(period_count) = 64 kb mConfig.period_size = 2048; mConfig.period_count = 8; mConfig.format = PCM_FORMAT_S16_LE; mConfig.start_threshold = 0; mConfig.stop_threshold = 0; mConfig.silence_threshold = 0; #if 0 //latency time, set as DataProvider buffer size mStreamAttributeSource.latency = (kReadBufferSize * 1000) / (mStreamAttributeSource.num_channels * mStreamAttributeSource.sample_rate * (mStreamAttributeSource.audio_format == AUDIO_FORMAT_PCM_8_BIT ? 1 : //8 1byte/frame (mStreamAttributeSource.audio_format == AUDIO_FORMAT_PCM_32_BIT ? 4 : //24bit 3bytes/frame 2))); //default 2bytes/sample #else //latency time, set as hardware buffer size mStreamAttributeSource.latency = (mConfig.period_size * mConfig.period_count * 1000) / mConfig.rate; #endif ALOGD("%s(), audio_format = %d, audio_channel_mask=%x, num_channels=%d, sample_rate=%d, latency=%dms", __FUNCTION__, mStreamAttributeSource.audio_format, mStreamAttributeSource.audio_channel_mask, mStreamAttributeSource.num_channels, mStreamAttributeSource.sample_rate, mStreamAttributeSource.latency); ALOGD("%s(), format = %d, channels=%d, rate=%d", __FUNCTION__, mConfig.format, mConfig.channels, mConfig.rate); #ifdef NXP_SMARTPA_SUPPORT MTK_Tfa98xx_EchoReferenceConfigure(1); #endif OpenPCMDump(LOG_TAG); // enable pcm ASSERT(mPcm == NULL); mPcm = pcm_open(0, 16, PCM_IN | PCM_MONOTONIC, &mConfig); ASSERT(mPcm != NULL && pcm_is_ready(mPcm) == true); pcm_start(mPcm); // create reading thread mEnable = true; int ret = pthread_create(&hReadThread, NULL, AudioALSACaptureDataProviderEchoRefExt::readThread, (void *)this); if (ret != 0) { ALOGE("%s() create thread fail!!", __FUNCTION__); return UNKNOWN_ERROR; } return NO_ERROR; }