android.media.audiofx.AutomaticGainControl Java Examples

The following examples show how to use android.media.audiofx.AutomaticGainControl. 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: Recorder.java    From soundcom with Apache License 2.0 5 votes vote down vote up
public Recorder(String uniquename) {
    //Initilize our recorder object
    /*recorder = new AudioRecord(
            MediaRecorder.AudioSource.MIC,
            44100,
            AudioFormat.CHANNEL_IN_MONO,
            AudioFormat.ENCODING_PCM_16BIT,
            AudioRecord.getMinBufferSize(44100,AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT)
            );
            */

    int bufferSize = AudioRecord.getMinBufferSize(RECORDER_SAMPLERATE,
            RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING);

    System.out.println("BUFFER SIZE VALUE IS " + bufferSize);

    int buffercount = 4088 / bufferSize;
    if (buffercount < 1)
        buffercount = 1;
    recorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT,
            RECORDER_SAMPLERATE, RECORDER_CHANNELS,
            RECORDER_AUDIO_ENCODING, 44100);

    if (AutomaticGainControl.isAvailable()) {
        System.out.println("AGC IS AVAILIABLE");
        AutomaticGainControl agc = AutomaticGainControl.create(
                recorder.getAudioSessionId()
        );
        agc.setEnabled(false);
    }
    else{
        System.out.println("AGC NOT AVAILIABLE");
    }

    //recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    //recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    //recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);


}
 
Example #3
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 #4
Source File: AudioPostProcessEffect.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
public void enableAutoGainControl() {
  if (AutomaticGainControl.isAvailable() && automaticGainControl == null) {
    automaticGainControl = AutomaticGainControl.create(microphoneId);
    automaticGainControl.setEnabled(true);
    Log.i(TAG, "AutoGainControl enabled");
  } else {
    Log.e(TAG, "This device don't support AutoGainControl");
  }
}
 
Example #5
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 #6
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 #7
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 #8
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");
        }
    }
}