Skip to content

Commit

Permalink
OboeTester: show default AEC status
Browse files Browse the repository at this point in the history
Also add NoiseSuppressor

For #2090
  • Loading branch information
philburk committed Aug 19, 2024
1 parent 5b62597 commit 50733ff
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.media.audiofx.AutomaticGainControl;
import android.media.audiofx.BassBoost;
import android.media.audiofx.LoudnessEnhancer;
import android.media.audiofx.NoiseSuppressor;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -100,7 +101,11 @@ public class StreamConfigurationView extends LinearLayout {
private LinearLayout mOutputEffectsLayout;

private CheckBox mAutomaticGainControlCheckBox;
private CharSequence mAutomaticGainControlText;
private CheckBox mAcousticEchoCancelerCheckBox;
private CharSequence mAcousticEchoCancelerText;
private CheckBox mNoiseSuppressorCheckBox;
private CharSequence mNoiseSuppressorText;
private TextView mBassBoostTextView;
private SeekBar mBassBoostSeekBar;
private TextView mLoudnessEnhancerTextView;
Expand All @@ -112,8 +117,9 @@ public class StreamConfigurationView extends LinearLayout {

private BassBoost mBassBoost;
private LoudnessEnhancer mLoudnessEnhancer;
private AcousticEchoCanceler mAcousticEchoCanceler;
private AutomaticGainControl mAutomaticGainControl;
private AcousticEchoCanceler mAcousticEchoCanceler;
private NoiseSuppressor mNoiseSuppressor;

// Create an anonymous implementation of OnClickListener
private View.OnClickListener mToggleListener = new View.OnClickListener() {
Expand Down Expand Up @@ -229,13 +235,18 @@ public void onClick(View view) {

mAutomaticGainControlCheckBox = (CheckBox) findViewById(R.id.checkBoxAutomaticGainControl);
mAcousticEchoCancelerCheckBox = (CheckBox) findViewById(R.id.checkBoxAcousticEchoCanceler);
mNoiseSuppressorCheckBox = (CheckBox) findViewById(R.id.checkBoxNoiseSuppressor);
mBassBoostTextView = (TextView) findViewById(R.id.textBassBoost);
mBassBoostSeekBar = (SeekBar) findViewById(R.id.seekBarBassBoost);
mLoudnessEnhancerTextView = (TextView) findViewById(R.id.textLoudnessEnhancer);
mLoudnessEnhancerSeekBar = (SeekBar) findViewById(R.id.seekBarLoudnessEnhancer);

mAutomaticGainControlCheckBox.setEnabled(AutomaticGainControl.isAvailable());
mAutomaticGainControlText = mAutomaticGainControlCheckBox.getText();
mAcousticEchoCancelerCheckBox.setEnabled(AcousticEchoCanceler.isAvailable());
mAcousticEchoCancelerText = mAcousticEchoCancelerCheckBox.getText();
mNoiseSuppressorCheckBox.setEnabled(NoiseSuppressor.isAvailable());
mNoiseSuppressorText = mNoiseSuppressorCheckBox.getText();

mBassBoostSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Expand Down Expand Up @@ -276,6 +287,11 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
onAcousticEchoCancelerCheckBoxChanged(isChecked);
}
});
mNoiseSuppressorCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
onNoiseSuppressorCheckBoxChanged(isChecked);
}
});

mActualSampleRateView = (TextView) findViewById(R.id.actualSampleRate);
mSampleRateSpinner = (Spinner) findViewById(R.id.spinnerSampleRate);
Expand Down Expand Up @@ -566,6 +582,9 @@ public void setupEffects(int sessionId) {
if (mAcousticEchoCancelerCheckBox.isEnabled()) {
mAcousticEchoCanceler = AcousticEchoCanceler.create(sessionId);
if (mAcousticEchoCanceler != null) {
boolean wasOn = mAcousticEchoCanceler.getEnabled();
String text = mAcousticEchoCancelerText + "(" + (wasOn ? "Y" : "N") + ")";
mAcousticEchoCancelerCheckBox.setText(text);
mAcousticEchoCanceler.setEnabled(mAcousticEchoCancelerCheckBox.isChecked());
} else {
Log.e(TAG, String.format(Locale.getDefault(), "Could not create AcousticEchoCanceler"));
Expand All @@ -575,11 +594,26 @@ public void setupEffects(int sessionId) {
if (mAutomaticGainControlCheckBox.isEnabled()) {
mAutomaticGainControl = AutomaticGainControl.create(sessionId);
if (mAutomaticGainControl != null) {
boolean wasOn = mAutomaticGainControl.getEnabled();
String text = mAutomaticGainControlText + "(" + (wasOn ? "Y" : "N") + ")";
mAutomaticGainControlCheckBox.setText(text);
mAutomaticGainControl.setEnabled(mAutomaticGainControlCheckBox.isChecked());
} else {
Log.e(TAG, String.format(Locale.getDefault(), "Could not create AutomaticGainControl"));
}
}
// If AEC is not available, the checkbox will be disabled in initializeViews().
if (mNoiseSuppressorCheckBox.isEnabled()) {
mNoiseSuppressor = NoiseSuppressor.create(sessionId);
if (mNoiseSuppressor != null) {
boolean wasOn = mNoiseSuppressor.getEnabled();
String text = mNoiseSuppressorText + "(" + (wasOn ? "Y" : "N") + ")";
mNoiseSuppressorCheckBox.setText(text);
mNoiseSuppressor.setEnabled(mNoiseSuppressorCheckBox.isChecked());
} else {
Log.e(TAG, String.format(Locale.getDefault(), "Could not create NoiseSuppressor"));
}
}
}
}

Expand Down Expand Up @@ -608,4 +642,10 @@ private void onAcousticEchoCancelerCheckBoxChanged(boolean isChecked) {
mAcousticEchoCanceler.setEnabled(isChecked);
}
}

private void onNoiseSuppressorCheckBoxChanged(boolean isChecked) {
if (mNoiseSuppressorCheckBox.isEnabled() && mNoiseSuppressor != null) {
mNoiseSuppressor.setEnabled(isChecked);
}
}
}
11 changes: 9 additions & 2 deletions apps/OboeTester/app/src/main/res/layout/stream_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,21 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8sp"
android:text="Automatic Gain Control" />
android:text="AGC" />

<CheckBox
android:id="@+id/checkBoxAcousticEchoCanceler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8sp"
android:text="Acoustic Echo Canceler" />
android:text="AEC" />

<CheckBox
android:id="@+id/checkBoxNoiseSuppressor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8sp"
android:text="NoNoise" />

</LinearLayout>

Expand Down

0 comments on commit 50733ff

Please sign in to comment.