Usages of

android.media.audiofx.NoiseSuppressor.hasControl()
//TODO: Do this the correct Device Manager way @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private static void setEchoCancel(AudioRecord record) { if (Build.VERSION.SDK_INT >= 16) { boolean aecIsAvailable = AcousticEchoCanceler.isAvailable(); Csjlogger.info(TAG, "AcousticEchoCanceler.isAvailable() = " + aecIsAvailable); if (aecIsAvailable) { AcousticEchoCanceler aec = AcousticEchoCanceler.create(record.getAudioSessionId()); //If Echo Cancel is to be enabled then do so if (LmiAudioCapturerDeviceInfo.getEnableEchoCancel()) { if(!aec.getEnabled()) { aec.setEnabled(true); } } else { if (aec.getEnabled()) { aec.setEnabled(false); } } Csjlogger.info(TAG, "AEC_enabled=" + aec.getEnabled() + ", hasControl=" + aec.hasControl()); } boolean agcIsAvailable = AutomaticGainControl.isAvailable(); Csjlogger.info(TAG, "AutomaticGainControl.isAvailable() = " + agcIsAvailable); if (agcIsAvailable) { AutomaticGainControl agc = AutomaticGainControl.create(record.getAudioSessionId()); if(!agc.getEnabled()) { agc.setEnabled(true); } Csjlogger.info(TAG, "AGC_enabled=" + agc.getEnabled() + ", hasControl=" + agc.hasControl()); } boolean nsIsAvailable = NoiseSuppressor.isAvailable(); Csjlogger.info(TAG, "NoiseSuppressor.isAvailable() = " + nsIsAvailable); if (nsIsAvailable) { NoiseSuppressor ns = NoiseSuppressor.create(record.getAudioSessionId()); if (LmiAudioCapturerDeviceInfo.getEnableNoiseSuppression()) { if (!ns.getEnabled()) ns.setEnabled(true); } else { if (ns.getEnabled()) ns.setEnabled(false); } Csjlogger.info(TAG, "NoiseSuppressor_enabled=" + ns.getEnabled() + ", hasControl=" + ns.hasControl()); } } }
private NoiseSuppressor ns; // code omitted ... @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private synchronized void preInit() { Log.d(TAG, "initializing"); final int bufferSize = AudioRecord.getMinBufferSize(audioConfig.sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT) * 10; Log.d(TAG, "Audio buffer size: " + bufferSize); rec = new AudioRecord(MediaRecorder.AudioSource.VOICE_COMMUNICATION, audioConfig.sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize); Log.d(TAG, "Audio Source ID: " + rec.getAudioSource() ); audioSessionId = rec.getAudioSessionId(); Log.d(TAG, "Audio session ID: " + rec.getAudioSessionId()); AudioSetup.setAudioSessionId(audioSessionId); if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.JELLY_BEAN) { Log.d(TAG, "Audio effects not available on this version of Android"); return; } if (NoiseSuppressor.isAvailable()) { ns = NoiseSuppressor.create(audioSessionId); final boolean nsOn = ns.getEnabled(); Log.d(TAG, "NoiseSuppressor is available" + (nsOn ? " and is " : " but is not") + " enabled by default; enabling."); if (!nsOn) { ns.setEnabled(true); } Log.d(TAG, "NoiseSuppressor" + (ns.hasControl()?" has":" doesn't have") + " control"); } else { Log.w(TAG, "NoiseSuppressor is not available"); } // AEC does not work on N7, no matter what it claims if (AcousticEchoCanceler.isAvailable() && android.os.Build.MODEL.compareTo("Nexus 7") != 0) { aec = AcousticEchoCanceler.create(audioSessionId); final boolean aecOn = aec.getEnabled(); Log.d(TAG, "AcousticEchoCanceler is available" + (aecOn ? " and is" : " but is not") + " enabled by default; enabling."); if (! aecOn ) { aec.setEnabled(true); } Log.d(TAG, "AcousticEchoCanceler" + (aec.hasControl()?" has":" doesn't have") + " control"); } else { Log.w(TAG, "AcousticEchoCanceler is not available, using Speex AEC"); sec = SpeexAEC.getInstance(audioConfig); } if (AutomaticGainControl.isAvailable()) { agc = AutomaticGainControl.create(audioSessionId); final boolean agcOn = agc.getEnabled(); Log.d(TAG, "AutomaticGainControl is available" + (agcOn ? " and is" : " but is not") + " enabled by default; enabling."); if (! agcOn ) { agc.setEnabled(true); } Log.d(TAG, "AutomaticGainControl" + (agc.hasControl()?" has":" doesn't have") + " control"); } else { Log.w(TAG, "AutomaticGainControl is not available"); } if (ns != null && !ns.getEnabled()) { Log.e(TAG, "NoiseSuppressor could no be enabled"); } if (aec != null && !aec.getEnabled()) { Log.e(TAG, "AcousticEchoCanceler could no be enabled"); } if (agc != null && !agc.getEnabled()) { Log.e(TAG, "AutomaticGainControl could no be enabled"); } }
//TODO: Do this the correct Device Manager way @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private static void setEchoCancel(AudioRecord record) { if (Build.VERSION.SDK_INT >= 16) { boolean aecIsAvailable = AcousticEchoCanceler.isAvailable(); Log.i(TAG, "AcousticEchoCanceler.isAvailable() = " + aecIsAvailable); if (aecIsAvailable) { AcousticEchoCanceler aec = AcousticEchoCanceler.create(record.getAudioSessionId()); //If Echo Cancel is to be enabled then do so if (LmiAudioCapturerDeviceInfo.getEnableEchoCancel()) { if(!aec.getEnabled()) { aec.setEnabled(true); } } else { if (aec.getEnabled()) { aec.setEnabled(false); } } Log.i(TAG, "AEC_enabled=" + aec.getEnabled() + ", hasControl=" + aec.hasControl()); } boolean agcIsAvailable = AutomaticGainControl.isAvailable(); Log.i(TAG, "AutomaticGainControl.isAvailable() = " + agcIsAvailable); if (agcIsAvailable) { AutomaticGainControl agc = AutomaticGainControl.create(record.getAudioSessionId()); if(!agc.getEnabled()) { agc.setEnabled(true); } Log.i(TAG, "AGC_enabled=" + agc.getEnabled() + ", hasControl=" + agc.hasControl()); } boolean nsIsAvailable = NoiseSuppressor.isAvailable(); Log.i(TAG, "NoiseSuppressor.isAvailable() = " + nsIsAvailable); if (nsIsAvailable) { NoiseSuppressor ns = NoiseSuppressor.create(record.getAudioSessionId()); if (LmiAudioCapturerDeviceInfo.getEnableNoiseSuppression()) { if (!ns.getEnabled()) ns.setEnabled(true); } else { if (ns.getEnabled()) ns.setEnabled(false); } Log.i(TAG, "NoiseSuppressor_enabled=" + ns.getEnabled() + ", hasControl=" + ns.hasControl()); } } }
Usage snippet has been bookmarked! Review your bookmarks
Thank you! Review your likes