Java源码示例:android.media.audiofx.NoiseSuppressor

示例1
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();
}
 
示例2
public AACEncoder(final StreamPublisher.StreamPublisherParam params) throws IOException {
    this.samplingRate = params.samplingRate;

    bufferSize = params.audioBufferSize;
    mMediaCodec = MediaCodec.createEncoderByType(params.audioMIME);
    mMediaCodec.configure(params.createAudioMediaFormat(), null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
    mediaCodecInputStream = new MediaCodecInputStream(mMediaCodec, new MediaCodecInputStream.MediaFormatCallback() {
        @Override
        public void onChangeMediaFormat(MediaFormat mediaFormat) {
            params.setAudioOutputMediaFormat(mediaFormat);
        }
    });
    mAudioRecord = new AudioRecord(params.audioSource, samplingRate, params.channelCfg, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
    if (NoiseSuppressor.isAvailable()) {
        NoiseSuppressor noiseSuppressor = NoiseSuppressor.create(mAudioRecord.getAudioSessionId());
    }

}
 
示例3
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);
}
 
示例4
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;
}
 
示例5
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);
}
 
示例6
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;
}
 
示例7
private void checkthingsforrecoder() {
    int audioSessionId = getAudioSessionId();

    if(NoiseSuppressor.isAvailable())
    {
      //  NoiseSuppressor.create(audioSessionId);
    }
    if(AutomaticGainControl.isAvailable())
    {
       // AutomaticGainControl.create(audioSessionId);
    }
    if(AcousticEchoCanceler.isAvailable()){
       // AcousticEchoCanceler.create(audioSessionId);
    }
}
 
示例8
public void enableNoiseSuppressor() {
  if (NoiseSuppressor.isAvailable() && noiseSuppressor == null) {
    noiseSuppressor = NoiseSuppressor.create(microphoneId);
    noiseSuppressor.setEnabled(true);
    Log.i(TAG, "NoiseSuppressor enabled");
  } else {
    Log.e(TAG, "This device don't support NoiseSuppressor");
  }
}
 
示例9
/**
 * 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");
        }
    }
}
 
示例10
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");
        }
    }
}
 
示例11
public static boolean isNoiseSuppressorAvailable() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        return NoiseSuppressor.isAvailable();
    }
    return false;
}
 
示例12
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");
        }
    }
}
 
示例13
public static boolean isNoiseSuppressorAvailable() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        return NoiseSuppressor.isAvailable();
    }
    return false;
}
 
示例14
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");
        }
    }
}
 
示例15
public static boolean isNoiseSuppressorAvailable() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        return NoiseSuppressor.isAvailable();
    }
    return false;
}