1 package com.google.sample.oboe.manualtest; 2 3 import android.os.Bundle; 4 import android.view.View; 5 import android.widget.AdapterView; 6 import android.widget.Spinner; 7 8 public class AutomatedGlitchActivity extends BaseAutoGlitchActivity { 9 10 private Spinner mDurationSpinner; 11 12 // Test with these configurations. 13 private static final int[] PERFORMANCE_MODES = { 14 StreamConfiguration.PERFORMANCE_MODE_LOW_LATENCY, 15 StreamConfiguration.PERFORMANCE_MODE_NONE 16 }; 17 private static final int[] SAMPLE_RATES = { 48000, 44100, 16000 }; 18 private static final int MONO = 1; 19 private static final int STEREO = 2; 20 private static final int UNSPECIFIED = 0; 21 22 private class DurationSpinnerListener implements android.widget.AdapterView.OnItemSelectedListener { 23 @Override onItemSelected(AdapterView<?> parent, View view, int pos, long id)24 public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { 25 String text = parent.getItemAtPosition(pos).toString(); 26 mDurationSeconds = Integer.parseInt(text); 27 } 28 29 @Override onNothingSelected(AdapterView<?> parent)30 public void onNothingSelected(AdapterView<?> parent) { 31 mDurationSeconds = DEFAULT_DURATION_SECONDS; 32 } 33 } 34 35 @Override inflateActivity()36 protected void inflateActivity() { 37 setContentView(R.layout.activity_auto_glitches); 38 } 39 40 @Override onCreate(Bundle savedInstanceState)41 protected void onCreate(Bundle savedInstanceState) { 42 super.onCreate(savedInstanceState); 43 44 mDurationSpinner = (Spinner) findViewById(R.id.spinner_glitch_duration); 45 mDurationSpinner.setOnItemSelectedListener(new DurationSpinnerListener()); 46 } 47 48 @Override getTestName()49 public String getTestName() { 50 return "AutoGlitch"; 51 } 52 testConfiguration(int perfMode, int sharingMode, int sampleRate, int inChannels, int outChannels)53 private void testConfiguration(int perfMode, 54 int sharingMode, 55 int sampleRate, 56 int inChannels, 57 int outChannels) throws InterruptedException { 58 59 // Configure settings 60 StreamConfiguration requestedInConfig = mAudioInputTester.requestedConfiguration; 61 StreamConfiguration requestedOutConfig = mAudioOutTester.requestedConfiguration; 62 63 requestedInConfig.reset(); 64 requestedOutConfig.reset(); 65 66 requestedInConfig.setPerformanceMode(perfMode); 67 requestedOutConfig.setPerformanceMode(perfMode); 68 69 requestedInConfig.setSharingMode(sharingMode); 70 requestedOutConfig.setSharingMode(sharingMode); 71 72 requestedInConfig.setSampleRate(sampleRate); 73 requestedOutConfig.setSampleRate(sampleRate); 74 75 requestedInConfig.setChannelCount(inChannels); 76 requestedOutConfig.setChannelCount(outChannels); 77 78 setTolerance(0.3f); // FIXME remove 79 80 testConfigurations(); 81 } 82 testConfiguration(int performanceMode, int sharingMode, int sampleRate)83 private void testConfiguration(int performanceMode, 84 int sharingMode, 85 int sampleRate) throws InterruptedException { 86 testConfiguration(performanceMode, 87 sharingMode, 88 sampleRate, MONO, STEREO); 89 testConfiguration(performanceMode, 90 sharingMode, 91 sampleRate, STEREO, MONO); 92 } 93 94 @Override runTest()95 public void runTest() { 96 try { 97 testConfiguration(StreamConfiguration.PERFORMANCE_MODE_LOW_LATENCY, 98 StreamConfiguration.SHARING_MODE_EXCLUSIVE, 99 UNSPECIFIED); 100 101 for (int perfMode : PERFORMANCE_MODES) { 102 for (int sampleRate : SAMPLE_RATES) { 103 testConfiguration(perfMode, 104 StreamConfiguration.SHARING_MODE_SHARED, 105 sampleRate); 106 } 107 } 108 } catch (InterruptedException e) { 109 log(e.getMessage()); 110 showErrorToast(e.getMessage()); 111 } 112 } 113 114 } 115