Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lublin <daniel@lublin.se>2020-08-13 15:04:56 +0300
committerDaniel Lublin <daniel@lublin.se>2020-08-13 15:07:26 +0300
commit1a384b73833c677b91c54aa2933ef53a28583fab (patch)
treeb8921cfd6be29760e01904e1ce6de7cd6793088c
parentcf8493956365fe684cbb300a7ab5d1d6bc7b3559 (diff)
WIP
-rw-r--r--src/main/java/se/lublin/humla/audio/AudioInput.java71
1 files changed, 46 insertions, 25 deletions
diff --git a/src/main/java/se/lublin/humla/audio/AudioInput.java b/src/main/java/se/lublin/humla/audio/AudioInput.java
index cd8f7f8..2428da1 100644
--- a/src/main/java/se/lublin/humla/audio/AudioInput.java
+++ b/src/main/java/se/lublin/humla/audio/AudioInput.java
@@ -40,6 +40,7 @@ public class AudioInput implements Runnable {
private AudioInputListener mListener;
private AudioRecord mAudioRecord;
private final int mFrameSize;
+ private AcousticEchoCanceler mAEC = null;
private Thread mRecordThread;
private boolean mRecording;
@@ -66,6 +67,8 @@ public class AudioInput implements Runnable {
throw new AudioInitializationException("Unable to initialize AudioInput.");
}
+ setupAEC();
+
int sampleRate = getSampleRate();
// FIXME: does not work properly if 10ms frames cannot be represented as integers
mFrameSize = (sampleRate * AudioHandler.FRAME_SIZE) / AudioHandler.SAMPLE_RATE;
@@ -90,35 +93,49 @@ public class AudioInput implements Runnable {
throw new AudioInitializationException("AudioRecord failed to initialize!");
}
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
-
- // TODO "On some devices, an AEC can be inserted by default in the
- // capture path by the platform according to the
- // MediaRecorder.AudioSource used. The application should call
- // AcousticEchoCanceler.getEnable() after creating the AEC to
- // check the default AEC activation state on a particular
- // AudioRecord session."
- // https://developer.android.com/reference/android/media/audiofx/AcousticEchoCanceler.html
- // vv same for AGC and NS
-
- // https://source.android.com/devices/audio/implement-pre-processing
+ return audioRecord;
+ }
- int audioSessionId = audioRecord.getAudioSessionId();
- if(AcousticEchoCanceler.isAvailable()) {
- AcousticEchoCanceler.create(audioSessionId);
- }
- if(AutomaticGainControl.isAvailable()) {
- AutomaticGainControl.create(audioSessionId);
- }
- if(NoiseSuppressor.isAvailable()) {
- NoiseSuppressor.create(audioSessionId);
- }
+ private void setupAEC() {
+ if (mAudioRecord == null) {
+ return;
+ }
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
+ return;
+ }
+ // TODO "On some devices, an AEC can be inserted by default in the
+ // capture path by the platform according to the
+ // MediaRecorder.AudioSource used. The application should call
+ // AcousticEchoCanceler.getEnable() after creating the AEC to
+ // check the default AEC activation state on a particular
+ // AudioRecord session."
+ // https://developer.android.com/reference/android/media/audiofx/AcousticEchoCanceler.html
+ // vv same for AGC and NS
+
+ // Read https://source.android.com/devices/audio/implement-pre-processing
+
+ int audioSessionId = mAudioRecord.getAudioSessionId();
+ if (AcousticEchoCanceler.isAvailable()) {
+ mAEC = AcousticEchoCanceler.create(audioSessionId);
}
- return audioRecord;
+ // TODO?
+ // if (aec != null) {
+//  int ret = aec.setEnabled(enable);
+//  if (ret != AudioEffect.SUCCESS) {
+//  return false;
+//  }
+//  }
+
+ return;
+ // if(AutomaticGainControl.isAvailable()) {
+ // AutomaticGainControl.create(audioSessionId);
+ // }
+ // if(NoiseSuppressor.isAvailable()) {
+ // NoiseSuppressor.create(audioSessionId);
+ // }
}
-
- /**
+ /**
* Starts the recording thread.
* Not thread-safe.
*/
@@ -154,6 +171,10 @@ public class AudioInput implements Runnable {
if(mAudioRecord != null) {
mAudioRecord.release();
mAudioRecord = null;
+ if (mAEC != null) {
+ mAEC.release();
+ mAEC = null;
+ }
}
}