android.media.audiofx.AcousticEchoCanceler Java Examples

The following examples show how to use android.media.audiofx.AcousticEchoCanceler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayService.java    From music_player with Open Software License 3.0 7 votes vote down vote up
private void initialAudioEffect(final int audioSessionId) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                loudnessEnhancer = new LoudnessEnhancer(audioSessionId);
                mBass = new BassBoost(0, audioSessionId);
                mVirtualizer = new Virtualizer(0, audioSessionId);
                mEqualizer = new Equalizer(0, audioSessionId);
                canceler = AcousticEchoCanceler.create(audioSessionId);
                control = AutomaticGainControl.create(audioSessionId);
                suppressor = NoiseSuppressor.create(audioSessionId);
                getPreference();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
}
 
Example #2
Source File: VoIPController.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void setConfig(double recvTimeout, double initTimeout, int dataSavingOption, long callID){
	ensureNativeInstance();
	boolean sysAecAvailable=false, sysNsAvailable=false;
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
		try{
			sysAecAvailable=AcousticEchoCanceler.isAvailable();
			sysNsAvailable=AcousticEchoCanceler.isAvailable();
		}catch(Throwable x){

		}
	}
	SharedPreferences preferences=MessagesController.getGlobalMainSettings();
	boolean dump=preferences.getBoolean("dbg_dump_call_stats", false);
	nativeSetConfig(nativeInst, recvTimeout, initTimeout, dataSavingOption,
			!(sysAecAvailable && VoIPServerConfig.getBoolean("use_system_aec", true)),
			!(sysNsAvailable && VoIPServerConfig.getBoolean("use_system_ns", true)),
			true, BuildConfig.DEBUG ? getLogFilePath("voip"+callID) : getLogFilePath(callID), BuildConfig.DEBUG && dump ? getLogFilePath("voipStats") : null);
}
 
Example #3
Source File: AudioRecordJNI.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private static boolean isGoodAudioEffect(AudioEffect effect){
	Pattern globalImpl=makeNonEmptyRegex("adsp_good_impls"), globalName=makeNonEmptyRegex("adsp_good_names");
	AudioEffect.Descriptor desc=effect.getDescriptor();
	VLog.d(effect.getClass().getSimpleName()+": implementor="+desc.implementor+", name="+desc.name);
	if(globalImpl!=null && globalImpl.matcher(desc.implementor).find()){
		return true;
	}
	if(globalName!=null && globalName.matcher(desc.name).find()){
		return true;
	}
	if(effect instanceof AcousticEchoCanceler){
		Pattern impl=makeNonEmptyRegex("aaec_good_impls"), name=makeNonEmptyRegex("aaec_good_names");
		if(impl!=null && impl.matcher(desc.implementor).find())
			return true;
		if(name!=null && name.matcher(desc.name).find())
			return true;
	}
	if(effect instanceof NoiseSuppressor){
		Pattern impl=makeNonEmptyRegex("ans_good_impls"), name=makeNonEmptyRegex("ans_good_names");
		if(impl!=null && impl.matcher(desc.implementor).find())
			return true;
		if(name!=null && name.matcher(desc.name).find())
			return true;
	}
	return false;
}
 
Example #4
Source File: VoIPController.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void setConfig(double recvTimeout, double initTimeout, int dataSavingOption, long callID){
	ensureNativeInstance();
	boolean sysAecAvailable=false, sysNsAvailable=false;
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
		try{
			sysAecAvailable=AcousticEchoCanceler.isAvailable();
			sysNsAvailable=NoiseSuppressor.isAvailable();
		}catch(Throwable x){

		}
	}
	SharedPreferences preferences=MessagesController.getGlobalMainSettings();
	boolean dump=preferences.getBoolean("dbg_dump_call_stats", false);
	nativeSetConfig(nativeInst, recvTimeout, initTimeout, dataSavingOption,
			!(sysAecAvailable && VoIPServerConfig.getBoolean("use_system_aec", true)),
			!(sysNsAvailable && VoIPServerConfig.getBoolean("use_system_ns", true)),
			true, BuildVars.DEBUG_VERSION ? getLogFilePath("voip"+callID) : getLogFilePath(callID), BuildVars.DEBUG_VERSION && dump ? getLogFilePath("voipStats") : null,
			BuildVars.DEBUG_VERSION);
}
 
Example #5
Source File: AudioRecordJNI.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static boolean isGoodAudioEffect(AudioEffect effect){
	Pattern globalImpl=makeNonEmptyRegex("adsp_good_impls"), globalName=makeNonEmptyRegex("adsp_good_names");
	AudioEffect.Descriptor desc=effect.getDescriptor();
	VLog.d(effect.getClass().getSimpleName()+": implementor="+desc.implementor+", name="+desc.name);
	if(globalImpl!=null && globalImpl.matcher(desc.implementor).find()){
		return true;
	}
	if(globalName!=null && globalName.matcher(desc.name).find()){
		return true;
	}
	if(effect instanceof AcousticEchoCanceler){
		Pattern impl=makeNonEmptyRegex("aaec_good_impls"), name=makeNonEmptyRegex("aaec_good_names");
		if(impl!=null && impl.matcher(desc.implementor).find())
			return true;
		if(name!=null && name.matcher(desc.name).find())
			return true;
	}
	if(effect instanceof NoiseSuppressor){
		Pattern impl=makeNonEmptyRegex("ans_good_impls"), name=makeNonEmptyRegex("ans_good_names");
		if(impl!=null && impl.matcher(desc.implementor).find())
			return true;
		if(name!=null && name.matcher(desc.name).find())
			return true;
	}
	return false;
}
 
Example #6
Source File: VoIPController.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void setConfig(double recvTimeout, double initTimeout, int dataSavingOption, long callID){
	ensureNativeInstance();
	boolean sysAecAvailable=false, sysNsAvailable=false;
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
		try{
			sysAecAvailable=AcousticEchoCanceler.isAvailable();
			sysNsAvailable=NoiseSuppressor.isAvailable();
		}catch(Throwable x){

		}
	}
	SharedPreferences preferences=MessagesController.getGlobalMainSettings();
	boolean dump=preferences.getBoolean("dbg_dump_call_stats", false);
	nativeSetConfig(nativeInst, recvTimeout, initTimeout, dataSavingOption,
			!(sysAecAvailable && VoIPServerConfig.getBoolean("use_system_aec", true)),
			!(sysNsAvailable && VoIPServerConfig.getBoolean("use_system_ns", true)),
			true, BuildVars.DEBUG_VERSION ? getLogFilePath("voip"+callID) : getLogFilePath(callID), BuildVars.DEBUG_VERSION && dump ? getLogFilePath("voipStats") : null,
			BuildVars.DEBUG_VERSION);
}
 
Example #7
Source File: VoIPController.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void setConfig(double recvTimeout, double initTimeout, int dataSavingOption, long callID){
	ensureNativeInstance();
	boolean sysAecAvailable=false, sysNsAvailable=false;
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
		try{
			sysAecAvailable=AcousticEchoCanceler.isAvailable();
			sysNsAvailable=AcousticEchoCanceler.isAvailable();
		}catch(Throwable x){

		}
	}
	SharedPreferences preferences=MessagesController.getGlobalMainSettings();
	boolean dump=preferences.getBoolean("dbg_dump_call_stats", false);
	nativeSetConfig(nativeInst, recvTimeout, initTimeout, dataSavingOption,
			!(sysAecAvailable && VoIPServerConfig.getBoolean("use_system_aec", true)),
			!(sysNsAvailable && VoIPServerConfig.getBoolean("use_system_ns", true)),
			true, BuildConfig.DEBUG ? getLogFilePath("voip"+callID) : getLogFilePath(callID), BuildConfig.DEBUG && dump ? getLogFilePath("voipStats") : null);
}
 
Example #8
Source File: MicOpusRecorder.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * エコーキャンセラーの使用状態を取得します.
 *
 * @return エコーキャンセラーを使用する場合はtrue、それ以外はfalse
 */
public boolean isUseAEC() {
    if (AcousticEchoCanceler.isAvailable()) {
        return mUseAEC;
    }
    return false;
}
 
Example #9
Source File: AudioManagerAndroid.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static boolean shouldUseAcousticEchoCanceler() {
    // Verify that this device is among the supported/tested models.
    List<String> supportedModels = Arrays.asList(SUPPORTED_AEC_MODELS);
    if (!supportedModels.contains(Build.MODEL)) {
        return false;
    }
    if (DEBUG && AcousticEchoCanceler.isAvailable()) {
        logd("Approved for use of hardware acoustic echo canceler.");
    }

    // As a final check, verify that the device supports acoustic echo
    // cancellation.
    return AcousticEchoCanceler.isAvailable();
}
 
Example #10
Source File: SaiyAudio.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Attempt to set enhancers available on modern devices.
 * <p/>
 * These are hardware dependent, not build version. Although the APIs weren't available to
 * devices until API Level 16
 */
@SuppressWarnings("NewApi")
private void setEnhancers(final int sessionId) {

    if (!DEBUG) {
        NoiseSuppressor.create(sessionId);
        AcousticEchoCanceler.create(sessionId);
        AutomaticGainControl.create(sessionId);
    } else {
        if (NoiseSuppressor.create(sessionId) == null) {
            MyLog.i(CLS_NAME, "NoiseSuppressor null");
        } else {
            MyLog.i(CLS_NAME, "NoiseSuppressor success");
        }

        if (AcousticEchoCanceler.create(sessionId) == null) {
            MyLog.i(CLS_NAME, "AcousticEchoCanceler null");
        } else {
            MyLog.i(CLS_NAME, "AcousticEchoCanceler success");
        }

        if (AutomaticGainControl.create(sessionId) == null) {
            MyLog.i(CLS_NAME, "AutomaticGainControl null");
        } else {
            MyLog.i(CLS_NAME, "AutomaticGainControl success");
        }
    }
}
 
Example #11
Source File: AudioPostProcessEffect.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
public void enableEchoCanceler() {
  if (AcousticEchoCanceler.isAvailable() && acousticEchoCanceler == null) {
    acousticEchoCanceler = AcousticEchoCanceler.create(microphoneId);
    acousticEchoCanceler.setEnabled(true);
    Log.i(TAG, "EchoCanceler enabled");
  } else {
    Log.e(TAG, "This device don't support EchoCanceler");
  }
}
 
Example #12
Source File: RecordAudioinBytes.java    From Alexa-Voice-Service with MIT License 5 votes vote down vote up
private void checkthingsforrecoder() {
    int audioSessionId = getAudioSessionId();

    if(NoiseSuppressor.isAvailable())
    {
      //  NoiseSuppressor.create(audioSessionId);
    }
    if(AutomaticGainControl.isAvailable())
    {
       // AutomaticGainControl.create(audioSessionId);
    }
    if(AcousticEchoCanceler.isAvailable()){
       // AcousticEchoCanceler.create(audioSessionId);
    }
}
 
Example #13
Source File: SpeechRecord.java    From AlexaAndroid with GNU General Public License v2.0 4 votes vote down vote up
public SpeechRecord(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes,
                    boolean noise, boolean gain, boolean echo)
        throws IllegalArgumentException {

    super(audioSource, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        Log.i("Trying to enhance audio because running on SDK " + Build.VERSION.SDK_INT);

        int audioSessionId = getAudioSessionId();

        if (noise) {
            if (NoiseSuppressor.create(audioSessionId) == null) {
                Log.i("NoiseSuppressor: failed");
            } else {
                Log.i("NoiseSuppressor: ON");
            }
        } else {
            Log.i("NoiseSuppressor: OFF");
        }

        if (gain) {
            if (AutomaticGainControl.create(audioSessionId) == null) {
                Log.i("AutomaticGainControl: failed");
            } else {
                Log.i("AutomaticGainControl: ON");
            }
        } else {
            Log.i("AutomaticGainControl: OFF");
        }

        if (echo) {
            if (AcousticEchoCanceler.create(audioSessionId) == null) {
                Log.i("AcousticEchoCanceler: failed");
            } else {
                Log.i("AcousticEchoCanceler: ON");
            }
        } else {
            Log.i("AcousticEchoCanceler: OFF");
        }
    }
}
 
Example #14
Source File: SpeechRecord.java    From AlexaAndroid with GNU General Public License v2.0 4 votes vote down vote up
public SpeechRecord(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes,
                    boolean noise, boolean gain, boolean echo)
        throws IllegalArgumentException {

    super(audioSource, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        Log.i("Trying to enhance audio because running on SDK " + Build.VERSION.SDK_INT);

        int audioSessionId = getAudioSessionId();

        if (noise) {
            if (NoiseSuppressor.create(audioSessionId) == null) {
                Log.i("NoiseSuppressor: failed");
            } else {
                Log.i("NoiseSuppressor: ON");
            }
        } else {
            Log.i("NoiseSuppressor: OFF");
        }

        if (gain) {
            if (AutomaticGainControl.create(audioSessionId) == null) {
                Log.i("AutomaticGainControl: failed");
            } else {
                Log.i("AutomaticGainControl: ON");
            }
        } else {
            Log.i("AutomaticGainControl: OFF");
        }

        if (echo) {
            if (AcousticEchoCanceler.create(audioSessionId) == null) {
                Log.i("AcousticEchoCanceler: failed");
            } else {
                Log.i("AcousticEchoCanceler: ON");
            }
        } else {
            Log.i("AcousticEchoCanceler: OFF");
        }
    }
}
 
Example #15
Source File: SpeechRecord.java    From speechutils with Apache License 2.0 4 votes vote down vote up
public SpeechRecord(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes,
                    boolean noise, boolean gain, boolean echo)
        throws IllegalArgumentException {

    super(audioSource, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        Log.i("Trying to enhance audio because running on SDK " + Build.VERSION.SDK_INT);

        int audioSessionId = getAudioSessionId();

        if (noise) {
            if (NoiseSuppressor.create(audioSessionId) == null) {
                Log.i("NoiseSuppressor: failed");
            } else {
                Log.i("NoiseSuppressor: ON");
            }
        } else {
            Log.i("NoiseSuppressor: OFF");
        }

        if (gain) {
            if (AutomaticGainControl.create(audioSessionId) == null) {
                Log.i("AutomaticGainControl: failed");
            } else {
                Log.i("AutomaticGainControl: ON");
            }
        } else {
            Log.i("AutomaticGainControl: OFF");
        }

        if (echo) {
            if (AcousticEchoCanceler.create(audioSessionId) == null) {
                Log.i("AcousticEchoCanceler: failed");
            } else {
                Log.i("AcousticEchoCanceler: ON");
            }
        } else {
            Log.i("AcousticEchoCanceler: OFF");
        }
    }
}
 
Example #16
Source File: MicOpusRecorder.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
/**
 * 音声をレコードして、MediaCodec に渡します.
 */
private void recordAudio() throws NativeInterfaceException {
    int samplingRate = mSamplingRate.getValue();
    int channels = mChannels == 1 ? AudioFormat.CHANNEL_IN_MONO : AudioFormat.CHANNEL_IN_STEREO;
    int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
    int bufferSize = AudioRecord.getMinBufferSize(samplingRate, channels, audioFormat) * 4;
    int oneFrameDataCount = mSamplingRate.getValue() / mFrameSize.getFps();

    mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.DEFAULT,
            samplingRate,
            channels,
            audioFormat,
            bufferSize);

    if (mAudioRecord.getState() != AudioRecord.STATE_INITIALIZED) {
        if (mAudioRecordCallback != null) {
            mAudioRecordCallback.onEncoderError();
        }
        return;
    }

    if (mUseAEC && AcousticEchoCanceler.isAvailable()) {
        // ノイズキャンセラー
        mEchoCanceler = AcousticEchoCanceler.create(mAudioRecord.getAudioSessionId());
        if (mEchoCanceler != null) {
            int ret = mEchoCanceler.setEnabled(true);
            if (ret != AudioEffect.SUCCESS) {
                if (DEBUG) {
                    Log.w(TAG, "AcousticEchoCanceler is not supported.");
                }
            }
        }
    }

    OpusEncoder opusEncoder = null;

    try {
        opusEncoder = new OpusEncoder(mSamplingRate, mChannels, mFrameSize, mBitRate, mApplication);

        mAudioRecord.startRecording();

        short[] emptyBuffer = new short[oneFrameDataCount];
        short[] pcmBuffer = new short[oneFrameDataCount];
        byte[] opusFrameBuffer = opusEncoder.bufferAllocate();
        while (!mStopFlag) {
            int readSize = mAudioRecord.read(pcmBuffer, 0, oneFrameDataCount);
            if (readSize > 0) {
                int opusFrameBufferLength;
                if (isMute()) {
                    opusFrameBufferLength = opusEncoder.encode(emptyBuffer, readSize, opusFrameBuffer);
                } else {
                    opusFrameBufferLength = opusEncoder.encode(pcmBuffer, readSize, opusFrameBuffer);
                }

                if (opusFrameBufferLength > 0 && mAudioRecordCallback != null) {
                    mAudioRecordCallback.onPeriodicNotification(opusFrameBuffer, opusFrameBufferLength);
                }
            } else if (readSize == AudioRecord.ERROR_INVALID_OPERATION) {
                if (DEBUG) {
                    Log.e(TAG, "Invalid operation error.");
                }
                break;
            } else if (readSize == AudioRecord.ERROR_BAD_VALUE) {
                if (DEBUG) {
                    Log.e(TAG, "Bad value error.");
                }
                break;
            } else if (readSize == AudioRecord.ERROR) {
                if (DEBUG) {
                    Log.e(TAG, "Unknown error.");
                }
                break;
            }
        }
    } finally {
        if (mEchoCanceler != null) {
            mEchoCanceler.release();
            mEchoCanceler = null;
        }

        if (opusEncoder != null) {
            opusEncoder.release();
        }
    }
}
 
Example #17
Source File: MicAACLATMEncoder.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
/**
 * AudioRecord を開始します.
 */
private void startAudioRecord() {
    AudioQuality audioQuality = getAudioQuality();

    mBufferSize = AudioRecord.getMinBufferSize(audioQuality.getSamplingRate(),
            audioQuality.getChannel(), audioQuality.getFormat()) * 2;

    if (DEBUG) {
        Log.d(TAG, "AudioQuality: " + audioQuality);
    }

    mMuteBuffer = new byte[mBufferSize];

    mAudioRecord = new AudioRecord(MediaRecorder.AudioSource.DEFAULT,
            audioQuality.getSamplingRate(),
            audioQuality.getChannel(),
            audioQuality.getFormat(),
            mBufferSize);

    if (mAudioRecord.getState() != AudioRecord.STATE_INITIALIZED) {
        postOnError(new MediaEncoderException("AudioRecord is already initialized."));
        return;
    }

    if (mAudioQuality.isUseAEC() && AcousticEchoCanceler.isAvailable()) {
        // ノイズキャンセラー
        mEchoCanceler = AcousticEchoCanceler.create(mAudioRecord.getAudioSessionId());
        if (mEchoCanceler != null) {
            int ret = mEchoCanceler.setEnabled(true);
            if (ret != AudioEffect.SUCCESS) {
                if (DEBUG) {
                    Log.w(TAG, "AcousticEchoCanceler is not supported.");
                }
            }
        }
    }

    mAudioRecord.startRecording();

    mAudioThread = new AudioRecordThread();
    mAudioThread.setName("MicAACLATMEncoder");
    mAudioThread.start();
}