Skip to content

Commit

Permalink
OboeTester: Add sample rate tests to data paths test (#1937)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwu1 authored Nov 21, 2023
1 parent 791e54d commit f6aa353
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class TestDataPathsActivity extends BaseAutoGlitchActivity {
public static final String KEY_USE_ALL_OUTPUT_CHANNEL_MASKS = "use_all_output_channel_masks";
public static final boolean VALUE_DEFAULT_USE_ALL_OUTPUT_CHANNEL_MASKS = false;

public static final String KEY_USE_ALL_SAMPLE_RATES = "use_all_sample_rates";
public static final boolean VALUE_DEFAULT_USE_ALL_SAMPLE_RATES = false;

public static final String KEY_SINGLE_TEST_INDEX = "single_test_index";
public static final int VALUE_DEFAULT_SINGLE_TEST_INDEX = -1;

Expand Down Expand Up @@ -124,6 +127,7 @@ public class TestDataPathsActivity extends BaseAutoGlitchActivity {
private CheckBox mCheckBoxInputDevices;
private CheckBox mCheckBoxOutputDevices;
private CheckBox mCheckBoxAllOutputChannelMasks;
private CheckBox mCheckBoxAllSampleRates;

private static final int[] INPUT_PRESETS = {
StreamConfiguration.INPUT_PRESET_GENERIC,
Expand Down Expand Up @@ -166,6 +170,21 @@ public class TestDataPathsActivity extends BaseAutoGlitchActivity {
StreamConfiguration.CHANNEL_7POINT1POINT4,
};

private static final int[] SAMPLE_RATES = {
8000,
11025,
12000,
16000,
22050,
24000,
32000,
44100,
48000,
64000,
88200,
96000,
};

@NonNull
public static String comparePassedField(String prefix, Object failed, Object passed, String name) {
try {
Expand Down Expand Up @@ -290,6 +309,8 @@ protected void onCreate(Bundle savedInstanceState) {
mCheckBoxOutputDevices = (CheckBox)findViewById(R.id.checkbox_paths_output_devices);
mCheckBoxAllOutputChannelMasks =
(CheckBox)findViewById(R.id.checkbox_paths_all_output_channel_masks);
mCheckBoxAllSampleRates =
(CheckBox)findViewById(R.id.checkbox_paths_all_sample_rates);
}

@Override
Expand Down Expand Up @@ -393,18 +414,22 @@ String getOneLineSummary() {
+ ", IN" + (actualInConfig.isMMap() ? "-M" : "-L")
+ " D=" + actualInConfig.getDeviceId()
+ ", ch=" + channelText(getInputChannel(), actualInConfig.getChannelCount())
+ ", SR=" + actualInConfig.getSampleRate()
+ ", OUT" + (actualOutConfig.isMMap() ? "-M" : "-L")
+ " D=" + actualOutConfig.getDeviceId()
+ ", ch=" + channelText(getOutputChannel(), actualOutConfig.getChannelCount())
+ ", SR=" + actualOutConfig.getSampleRate()
+ ", mag = " + getMagnitudeText(mMaxMagnitude);
}

void setupDeviceCombo(int inputChannelCount,
int inputChannelMask,
int inputChannel,
int inputSampleRate,
int outputChannelCount,
int outputChannelMask,
int outputChannel) throws InterruptedException {
int outputChannel,
int outputSampleRate) throws InterruptedException {
// Configure settings
StreamConfiguration requestedInConfig = mAudioInputTester.requestedConfiguration;
StreamConfiguration requestedOutConfig = mAudioOutTester.requestedConfiguration;
Expand All @@ -418,6 +443,9 @@ void setupDeviceCombo(int inputChannelCount,
requestedInConfig.setSharingMode(StreamConfiguration.SHARING_MODE_SHARED);
requestedOutConfig.setSharingMode(StreamConfiguration.SHARING_MODE_SHARED);

requestedInConfig.setSampleRate(inputSampleRate);
requestedOutConfig.setSampleRate(outputSampleRate);

if (inputChannelMask != 0) {
requestedInConfig.setChannelMask(inputChannelMask);
} else {
Expand Down Expand Up @@ -452,8 +480,8 @@ void testPresetCombo(int inputPreset,
int outputChannel,
boolean mmapEnabled
) throws InterruptedException {
setupDeviceCombo(numInputChannels, 0, inputChannel, numOutputChannels, 0,
outputChannel);
setupDeviceCombo(numInputChannels, 0, inputChannel, 48000,
numOutputChannels, 0, outputChannel, 48000);

StreamConfiguration requestedInConfig = mAudioInputTester.requestedConfiguration;
requestedInConfig.setInputPreset(inputPreset);
Expand Down Expand Up @@ -508,20 +536,21 @@ void testInputDeviceCombo(int deviceId,
int channelCount,
int channelMask,
int inputChannel,
int inputSampleRate,
boolean mmapEnabled) throws InterruptedException {
String typeString = AudioDeviceInfoConverter.typeToString(deviceType);
if (channelMask != 0) {
setTestName("Test InDev: #" + deviceId + " " + typeString + "_" +
convertChannelMaskToText(channelMask) + "_" +
inputChannel + "/" + channelCount);
inputChannel + "/" + channelCount + "_" + inputSampleRate);
} else {
setTestName("Test InDev: #" + deviceId + " " + typeString
+ "_" + inputChannel + "/" + channelCount);
+ "_" + inputChannel + "/" + channelCount + "_" + inputSampleRate);
}

final int numOutputChannels = 2;
setupDeviceCombo(channelCount, channelMask, inputChannel, numOutputChannels, 0,
0);
setupDeviceCombo(channelCount, channelMask, inputChannel, inputSampleRate,
numOutputChannels, 0, 0, 48000);

StreamConfiguration requestedInConfig = mAudioInputTester.requestedConfiguration;
requestedInConfig.setInputPreset(StreamConfiguration.INPUT_PRESET_VOICE_RECOGNITION);
Expand All @@ -539,13 +568,14 @@ void testInputDeviceCombo(int deviceId,
int deviceType,
int channelCount,
int channelMask,
int inputChannel) throws InterruptedException {
int inputChannel,
int inputSampleRate) throws InterruptedException {
if (NativeEngine.isMMapSupported()) {
testInputDeviceCombo(deviceId, deviceType, channelCount, channelMask, inputChannel,
true);
inputSampleRate, true);
}
testInputDeviceCombo(deviceId, deviceType, channelCount, channelMask, inputChannel,
false);
inputSampleRate, false);
}

void testInputDevices() throws InterruptedException {
Expand All @@ -563,21 +593,29 @@ void testInputDevices() throws InterruptedException {
int[] channelCounts = deviceInfo.getChannelCounts();
numTested++;
// Always test mono and stereo.
testInputDeviceCombo(id, deviceType, 1, 0, 0);
testInputDeviceCombo(id, deviceType, 2, 0, 0);
testInputDeviceCombo(id, deviceType, 2, 0, 1);
testInputDeviceCombo(id, deviceType, 1, 0, 0, 48000);
testInputDeviceCombo(id, deviceType, 2, 0, 0, 48000);
testInputDeviceCombo(id, deviceType, 2, 0, 1, 48000);
if (channelCounts.length > 0) {
for (int numChannels : channelCounts) {
// Test higher channel counts.
if (numChannels > 2) {
log("numChannels = " + numChannels + "\n");
for (int channel = 0; channel < numChannels; channel++) {
testInputDeviceCombo(id, deviceType, numChannels, 0, channel);
testInputDeviceCombo(id, deviceType, numChannels, 0, channel,
48000);
}
}
}
}

runOnUiThread(() -> mCheckBoxAllSampleRates.setEnabled(false));
if (mCheckBoxAllSampleRates.isChecked()) {
for (int sampleRate : SAMPLE_RATES) {
testInputDeviceCombo(id, deviceType, 1, 0, 0, sampleRate);
}
}

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S_V2) {
int[] channelMasks = deviceInfo.getChannelMasks();
if (channelMasks.length > 0) {
Expand All @@ -592,7 +630,7 @@ void testInputDevices() throws InterruptedException {
int channelCount = Integer.bitCount(nativeChannelMask);
for (int channel = 0; channel < channelCount; channel++) {
testInputDeviceCombo(id, deviceType, channelCount, nativeChannelMask,
channel);
channel, 48000);
}
}
}
Expand Down Expand Up @@ -661,19 +699,20 @@ void testOutputDeviceCombo(int deviceId,
int channelCount,
int channelMask,
int outputChannel,
int outputSampleRate,
boolean mmapEnabled) throws InterruptedException {
String typeString = AudioDeviceInfoConverter.typeToString(deviceType);
if (channelMask != 0) {
setTestName("Test OutDev: #" + deviceId + " " + typeString
+ " Mask:" + channelMask + "_" + outputChannel + "/" + channelCount);
+ " Mask:" + channelMask + "_" + outputChannel + "/" + channelCount + "_" + outputSampleRate);
} else {
setTestName("Test InDev: #" + deviceId + " " + typeString
+ "_" + outputChannel + "/" + channelCount);
+ "_" + outputChannel + "/" + channelCount + "_" + outputSampleRate);
}

final int numInputChannels = 2; // TODO review, done because of mono problems on some devices
setupDeviceCombo(numInputChannels, 0, 0, channelCount, channelMask,
outputChannel);
setupDeviceCombo(numInputChannels, 0, 0, 48000,
channelCount, channelMask, outputChannel, outputSampleRate);

StreamConfiguration requestedOutConfig = mAudioOutTester.requestedConfiguration;
requestedOutConfig.setDeviceId(deviceId);
Expand Down Expand Up @@ -703,13 +742,14 @@ void testOutputDeviceCombo(int deviceId,
int deviceType,
int channelCount,
int channelMask,
int outputChannel) throws InterruptedException {
int outputChannel,
int outputSampleRate) throws InterruptedException {
if (NativeEngine.isMMapSupported()) {
testOutputDeviceCombo(deviceId, deviceType, channelCount, channelMask, outputChannel,
true);
outputSampleRate, true);
}
testOutputDeviceCombo(deviceId, deviceType, channelCount, channelMask, outputChannel
, false);
testOutputDeviceCombo(deviceId, deviceType, channelCount, channelMask, outputChannel,
outputSampleRate, false);
}

void logBoth(String text) {
Expand Down Expand Up @@ -738,21 +778,29 @@ void testOutputDevices() throws InterruptedException {
int[] channelCounts = deviceInfo.getChannelCounts();
numTested++;
// Always test mono and stereo.
testOutputDeviceCombo(id, deviceType, 1, 0, 0);
testOutputDeviceCombo(id, deviceType, 2, 0, 0);
testOutputDeviceCombo(id, deviceType, 2, 0, 1);
testOutputDeviceCombo(id, deviceType, 1, 0, 0, 48000);
testOutputDeviceCombo(id, deviceType, 2, 0, 0, 48000);
testOutputDeviceCombo(id, deviceType, 2, 0, 1, 48000);
if (channelCounts.length > 0) {
for (int numChannels : channelCounts) {
// Test higher channel counts.
if (numChannels > 2) {
log("numChannels = " + numChannels + "\n");
for (int channel = 0; channel < numChannels; channel++) {
testOutputDeviceCombo(id, deviceType, numChannels, 0, channel);
testOutputDeviceCombo(id, deviceType, numChannels, 0, channel,
48000);
}
}
}
}

runOnUiThread(() -> mCheckBoxAllSampleRates.setEnabled(false));
if (mCheckBoxAllSampleRates.isChecked()) {
for (int sampleRate : SAMPLE_RATES) {
testOutputDeviceCombo(id, deviceType, 1, 0, 0, sampleRate);
}
}

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S_V2
&& deviceType == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
runOnUiThread(() -> mCheckBoxAllOutputChannelMasks.setEnabled(false));
Expand All @@ -762,7 +810,8 @@ void testOutputDevices() throws InterruptedException {
log("channelMask = " + convertChannelMaskToText(channelMask) + "\n");
int channelCount = Integer.bitCount(channelMask);
for (int channel = 0; channel < channelCount; channel++) {
testOutputDeviceCombo(id, deviceType, channelCount, channelMask, channel);
testOutputDeviceCombo(id, deviceType, channelCount, channelMask,
channel, 48000);
}
}
}
Expand Down Expand Up @@ -814,6 +863,7 @@ public void runTest() {
mCheckBoxInputDevices.setEnabled(true);
mCheckBoxOutputDevices.setEnabled(true);
mCheckBoxAllOutputChannelMasks.setEnabled(true);
mCheckBoxAllSampleRates.setEnabled(true);
keepScreenOn(false);
});
}
Expand All @@ -834,6 +884,9 @@ public void startTestUsingBundle() {
boolean shouldUseAllOutputChannelMasks =
mBundleFromIntent.getBoolean(KEY_USE_ALL_OUTPUT_CHANNEL_MASKS,
VALUE_DEFAULT_USE_ALL_OUTPUT_CHANNEL_MASKS);
boolean shouldUseAllSampleRates =
mBundleFromIntent.getBoolean(KEY_USE_ALL_SAMPLE_RATES,
VALUE_DEFAULT_USE_ALL_SAMPLE_RATES);
int singleTestIndex = mBundleFromIntent.getInt(KEY_SINGLE_TEST_INDEX,
VALUE_DEFAULT_SINGLE_TEST_INDEX);

Expand All @@ -842,6 +895,7 @@ public void startTestUsingBundle() {
mCheckBoxInputDevices.setChecked(shouldUseInputDevices);
mCheckBoxOutputDevices.setChecked(shouldUseOutputDevices);
mCheckBoxAllOutputChannelMasks.setChecked(shouldUseAllOutputChannelMasks);
mCheckBoxAllSampleRates.setChecked(shouldUseAllSampleRates);
mAutomatedTestRunner.setTestIndexText(singleTestIndex);
});

Expand Down
13 changes: 13 additions & 0 deletions apps/OboeTester/app/src/main/res/layout/activity_data_paths.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,26 @@
android:layout_height="wrap_content"
android:checked="true"
android:text="OutDev" />
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<CheckBox
android:id="@+id/checkbox_paths_all_output_channel_masks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="AllOutCMs" />

<CheckBox
android:id="@+id/checkbox_paths_all_sample_rates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="AllSRs" />
</LinearLayout>

<TextView
Expand Down
1 change: 1 addition & 0 deletions apps/OboeTester/docs/AutomatedTesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ There are several optional parameters for just the "data_paths" test:
--ez use_input_devices {"true", 1, "false", 0} // Whether to test various input devices. Note use of "-ez"
--ez use_output_devices {"true", 1, "false", 0} // Whether to test various output devices. Note use of "-ez"
--ez use_all_output_channel_masks {"true", 1, "false", 0} // Whether to test all output channel masks. Note use of "-ez". Default is false
--ez use_all_sample_rates {"true", 1, "false", 0} // Whether to test all sample rates. Note use of "-ez". Default is false
--ei single_test_index {testId} // Index for testing one specific test

There are some optional parameters for just the "output" test:
Expand Down

0 comments on commit f6aa353

Please sign in to comment.