Merge "HifiUltrasound test update" into mnc-dev
diff --git a/apps/CtsVerifier/res/layout/hifi_ultrasound_popup_instru.xml b/apps/CtsVerifier/res/layout/hifi_ultrasound_popup_instru.xml
new file mode 100644
index 0000000..42af6e9
--- /dev/null
+++ b/apps/CtsVerifier/res/layout/hifi_ultrasound_popup_instru.xml
@@ -0,0 +1,21 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:background="@android:color/black"
+ android:padding="5dp"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/instru"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_weight="5" />
+
+ <Button
+ android:id="@+id/ok"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:text="@string/hifi_ultrasound_test_ok"
+ android:layout_weight="1" />
+</LinearLayout>
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index fa4203d..7e67e9f 100644
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -287,46 +287,53 @@
<string name="empty"></string>
<!-- Strings for HifiUltrasoundTestActivity -->
- <string name="hifi_ultrasound_test">Hifi Ultrasound Test (microphone)</string>
+ <string name="hifi_ultrasound_test">Hifi Ultrasound Microphone Test</string>
<string name="hifi_ultrasound_test_info">
- This is a test for microphone near-ultrasound (18500Hz - 20000Hz) response.\n
+ This is a test for near-ultrasound (18500Hz - 20000Hz) microphone response.\n
This test requires two devices.\n</string>
<string name="hifi_ultrasound_test_play">PLAY</string>
<string name="hifi_ultrasound_test_record">RECORD</string>
<string name="hifi_ultrasound_test_plot">PLOT</string>
<string name="hifi_ultrasound_test_dismiss">DISMISS</string>
+ <string name="hifi_ultrasound_test_ok">OK</string>
<string name="hifi_ultrasound_test_instruction1">
- Set the volume of the reference device at 70% and hold it with one hand.\n
+ Open Hifi Ultrasound Microphone Test on the test device and the reference device.\n
+ Set the media volume of the reference device at 70% and hold it with one hand.\n
Hold the testing device with the other hand\n
Press the RECORD button on the testing device, then the PLAY button on the reference device within one second.\n
- After the test, report result on the testing device.\n</string>
+ After the test, report result on the testing (recording) device.\n</string>
<string name="hifi_ultrasound_test_pass">PASS</string>
<string name="hifi_ultrasound_test_fail">FAIL</string>
<string name="hifi_ultrasound_test_default_false_string">false</string>
- <string name="hifi_ultrasound_test_mic_prop">persist.audio.mic.ultrasound</string>
- <string name="hifi_ultrasound_test_spkr_prop">persist.audio.spkr.ultrasound</string>
<string name="hifi_ultrasound_test_mic_no_support">
Device does not support near-ultrasound recording.\n
- Please click pass if this is the testing device.\n</string>
+ All new phones and tablets MUST support near-ultrasound recording.\n
+ Report FAIL if this is a new device, report PASS if this is an updating device.\n</string>
<string name="hifi_ultrasound_test_spkr_no_support">
Device does not support near-ultrasound playback.\n
If this is your reference device, please use a different reference device.\n</string>
- <string name="hifi_ultrasound_speaker_test">Hifi Ultrasound Test (speaker)</string>
+ <string name="hifi_ultrasound_speaker_test">Hifi Ultrasound Speaker Test</string>
<string name="hifi_ultrasound_speaker_test_info">
- This is a test for speaker near-ultrasound (18500Hz - 20000Hz) response.\n
+ This is a test for near-ultrasound (18500Hz - 20000Hz) speaker response.\n
This test requires two devices.\n</string>
<string name="hifi_ultrasound_speaker_test_instruction1">
- Set the volume of the testing device at 70% and hold it with one hand.\n
+ Open Hifi Ultrasound Speaker Test on the test device and the reference device.\n
+ Set the media volume of the testing device at 70% and hold it with one hand.\n
Hold the reference device with the other hand\n
Press the RECORD button on the reference device, then the PLAY button on the testing device within one second.\n
- After the test, report result on the testing device.\n</string>
+ After the test, report result on the testing (playback) device.\n</string>
<string name="hifi_ultrasound_speaker_test_mic_no_support">
Device does not support near-ultrasound recording.\n
If this is your reference device, please use a different reference device.\n</string>
<string name="hifi_ultrasound_speaker_test_spkr_no_support">
Device does not support near-ultrasound playback.\n
- Please click pass if this is the testing device.\n</string>
+ All new phones and tablets MUST support near-ultrasound playback.\n
+ Report FAIL if this is a new device, report PASS if this is an updating device.\n</string>
+ <string name="hifi_ultrasound_speaker_test_test_side">
+ Please wait for the result on the reference device then report here.</string>
+ <string name="hifi_ultrasound_speaker_test_reference_side">
+ Please report on the testing device.\n</string>
<!-- Strings for Location tests -->
<string name="location_gps_test">GPS Test</string>
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/HifiUltrasoundSpeakerTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/HifiUltrasoundSpeakerTestActivity.java
index fa5ad81..dc81e19 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/HifiUltrasoundSpeakerTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/HifiUltrasoundSpeakerTestActivity.java
@@ -43,272 +43,310 @@
public class HifiUltrasoundSpeakerTestActivity extends PassFailButtons.Activity {
- public enum Status {
- START, RECORDING, DONE, PLAYER
- }
+ public enum Status {
+ START, RECORDING, DONE, PLAYER
+ }
- private static final String TAG = "HifiUltrasoundTestActivity";
+ private static final String TAG = "HifiUltrasoundTestActivity";
- private Status status = Status.START;
- private boolean onPlotScreen = false;
- private TextView info;
- private Button playerButton;
- private Button recorderButton;
- private AudioTrack audioTrack;
- private LayoutInflater layoutInflater;
- private View popupView;
- private PopupWindow popupWindow;
- private boolean micSupport = true;
- private boolean spkrSupport = true;
+ private Status status = Status.START;
+ private boolean onPlotScreen = false;
+ private boolean onInstruScreen = false;
+ private TextView info;
+ private Button playerButton;
+ private Button recorderButton;
+ private AudioTrack audioTrack;
+ private LayoutInflater layoutInflater;
+ private View popupView;
+ private View instruView;
+ private PopupWindow popupWindow;
+ private PopupWindow instruWindow;
+ private boolean micSupport = true;
+ private boolean spkrSupport = true;
- @Override
- public void onBackPressed () {
- if (onPlotScreen) {
- popupWindow.dismiss();
- onPlotScreen = false;
- recorderButton.setEnabled(true);
- } else {
- super.onBackPressed();
- }
- }
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.hifi_ultrasound);
- setInfoResources(R.string.hifi_ultrasound_speaker_test,
- R.string.hifi_ultrasound_speaker_test_info, -1);
- setPassFailButtonClickListeners();
- getPassButton().setEnabled(false);
-
- info = (TextView) findViewById(R.id.info_text);
- info.setMovementMethod(new ScrollingMovementMethod());
- info.setText(R.string.hifi_ultrasound_speaker_test_instruction1);
-
- AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
- String micSupportString = audioManager.getProperty(
- getResources().getString(R.string.hifi_ultrasound_test_mic_prop));
- String spkrSupportString = audioManager.getProperty(
- getResources().getString(R.string.hifi_ultrasound_test_spkr_prop));
-
- if (micSupportString == null) {
- micSupportString = "null";
- }
- if (spkrSupportString == null) {
- spkrSupportString = "null";
- }
- if (micSupportString.equalsIgnoreCase(getResources().getString(
- R.string.hifi_ultrasound_test_default_false_string))) {
- micSupport = false;
- getPassButton().setEnabled(true);
- info.append(getResources().getString(R.string.hifi_ultrasound_speaker_test_mic_no_support));
- }
- if (spkrSupportString.equalsIgnoreCase(getResources().getString(
- R.string.hifi_ultrasound_test_default_false_string))) {
- spkrSupport = false;
- info.append(getResources().getString(R.string.hifi_ultrasound_speaker_test_spkr_no_support));
- }
-
- layoutInflater = (LayoutInflater) getBaseContext().getSystemService(
- LAYOUT_INFLATER_SERVICE);
- popupView = layoutInflater.inflate(R.layout.hifi_ultrasound_popup, null);
- popupWindow = new PopupWindow(
- popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
-
- final AudioRecordHelper audioRecorder = AudioRecordHelper.getInstance();
- final int recordRate = audioRecorder.getSampleRate();
-
- recorderButton = (Button) findViewById(R.id.recorder_button);
+ @Override
+ public void onBackPressed () {
+ if (onPlotScreen) {
+ popupWindow.dismiss();
+ onPlotScreen = false;
+ recorderButton.setEnabled(true);
+ } else if (onInstruScreen) {
+ instruWindow.dismiss();
+ onInstruScreen = false;
+ if (status == Status.PLAYER) {
+ playerButton.setEnabled(spkrSupport);
+ } else {
recorderButton.setEnabled(micSupport);
- recorderButton.setOnClickListener(new View.OnClickListener() {
- private WavAnalyzerTask wavAnalyzerTask = null;
- private void stopRecording() {
- audioRecorder.stop();
- wavAnalyzerTask = new WavAnalyzerTask(audioRecorder.getByte());
- wavAnalyzerTask.execute();
- status = Status.DONE;
- }
- @Override
- public void onClick(View v) {
- switch (status) {
- case START:
- info.append("Recording at " + recordRate + "Hz using ");
- final int source = audioRecorder.getAudioSource();
- switch (source) {
- case 1:
- info.append("MIC");
- break;
- case 6:
- info.append("VOICE_RECOGNITION");
- break;
- default:
- info.append("UNEXPECTED " + source);
- break;
- }
- info.append("\n");
- status = Status.RECORDING;
- playerButton.setEnabled(false);
- recorderButton.setEnabled(false);
- audioRecorder.start();
+ }
+ if (status == Status.PLAYER) {
+ getPassButton().setEnabled(true);
+ }
+ } else {
+ super.onBackPressed();
+ }
+ }
- final View finalV = v;
- new Thread() {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.hifi_ultrasound);
+ setInfoResources(R.string.hifi_ultrasound_speaker_test,
+ R.string.hifi_ultrasound_speaker_test_info, -1);
+ setPassFailButtonClickListeners();
+ getPassButton().setEnabled(false);
+
+ info = (TextView) findViewById(R.id.info_text);
+ info.setMovementMethod(new ScrollingMovementMethod());
+ info.setText(R.string.hifi_ultrasound_speaker_test_instruction1);
+
+ AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+ String micSupportString = audioManager.getProperty(
+ AudioManager.PROPERTY_SUPPORT_MIC_NEAR_ULTRASOUND);
+ String spkrSupportString = audioManager.getProperty(
+ AudioManager.PROPERTY_SUPPORT_SPEAKER_NEAR_ULTRASOUND);
+ Log.d(TAG, "PROPERTY_SUPPORT_MIC_NEAR_ULTRASOUND = " + micSupportString);
+ Log.d(TAG, "PROPERTY_SUPPORT_SPEAKER_NEAR_ULTRASOUND = " + spkrSupportString);
+
+ if (micSupportString == null) {
+ micSupportString = "null";
+ }
+ if (spkrSupportString == null) {
+ spkrSupportString = "null";
+ }
+ if (micSupportString.equalsIgnoreCase(getResources().getString(
+ R.string.hifi_ultrasound_test_default_false_string))) {
+ micSupport = false;
+ getPassButton().setEnabled(true);
+ info.append(getResources().getString(R.string.hifi_ultrasound_speaker_test_mic_no_support));
+ }
+ if (spkrSupportString.equalsIgnoreCase(getResources().getString(
+ R.string.hifi_ultrasound_test_default_false_string))) {
+ spkrSupport = false;
+ info.append(getResources().getString(R.string.hifi_ultrasound_speaker_test_spkr_no_support));
+ }
+
+ layoutInflater = (LayoutInflater) getBaseContext().getSystemService(
+ LAYOUT_INFLATER_SERVICE);
+ popupView = layoutInflater.inflate(R.layout.hifi_ultrasound_popup, null);
+ popupWindow = new PopupWindow(
+ popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+ instruView = layoutInflater.inflate(R.layout.hifi_ultrasound_popup_instru, null);
+ instruWindow = new PopupWindow(
+ instruView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+
+ final AudioRecordHelper audioRecorder = AudioRecordHelper.getInstance();
+ final int recordRate = audioRecorder.getSampleRate();
+
+ recorderButton = (Button) findViewById(R.id.recorder_button);
+ recorderButton.setEnabled(micSupport);
+ recorderButton.setOnClickListener(new View.OnClickListener() {
+ private WavAnalyzerTask wavAnalyzerTask = null;
+ private void stopRecording() {
+ audioRecorder.stop();
+ wavAnalyzerTask = new WavAnalyzerTask(audioRecorder.getByte());
+ wavAnalyzerTask.execute();
+ status = Status.DONE;
+ }
+ @Override
+ public void onClick(View v) {
+ switch (status) {
+ case START:
+ info.append("Recording at " + recordRate + "Hz using ");
+ final int source = audioRecorder.getAudioSource();
+ switch (source) {
+ case 1:
+ info.append("MIC");
+ break;
+ case 6:
+ info.append("VOICE_RECOGNITION");
+ break;
+ default:
+ info.append("UNEXPECTED " + source);
+ break;
+ }
+ info.append("\n");
+ status = Status.RECORDING;
+ playerButton.setEnabled(false);
+ recorderButton.setEnabled(false);
+ audioRecorder.start();
+
+ final View finalV = v;
+ new Thread() {
+ @Override
+ public void run() {
+ Double recordingDuration_millis = new Double(1000 * (2.5
+ + Common.PREFIX_LENGTH_S
+ + Common.PAUSE_BEFORE_PREFIX_DURATION_S
+ + Common.PAUSE_AFTER_PREFIX_DURATION_S
+ + Common.PIP_NUM * (Common.PIP_DURATION_S + Common.PAUSE_DURATION_S)
+ * Common.REPETITIONS));
+ Log.d(TAG, "Recording for " + recordingDuration_millis + "ms");
+ try {
+ Thread.sleep(recordingDuration_millis.intValue());
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ runOnUiThread(new Runnable() {
@Override
public void run() {
- Double recordingDuration_millis = new Double(1000 * (2.5
- + Common.PREFIX_LENGTH_S
- + Common.PAUSE_BEFORE_PREFIX_DURATION_S
- + Common.PAUSE_AFTER_PREFIX_DURATION_S
- + Common.PIP_NUM * (Common.PIP_DURATION_S + Common.PAUSE_DURATION_S)
- * Common.REPETITIONS));
- Log.d(TAG, "Recording for " + recordingDuration_millis + "ms");
- try {
- Thread.sleep(recordingDuration_millis.intValue());
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- stopRecording();
- }
- });
+ stopRecording();
}
- }.start();
+ });
+ }
+ }.start();
- break;
+ break;
- case DONE:
- plotResponse(wavAnalyzerTask);
- break;
+ case DONE:
+ plotResponse(wavAnalyzerTask);
+ break;
- default: break;
- }
- }
- });
+ default: break;
+ }
+ }
+ });
- playerButton = (Button) findViewById(R.id.player_button);
- playerButton.setEnabled(spkrSupport);
- playerButton.setOnClickListener(new View.OnClickListener() {
+ playerButton = (Button) findViewById(R.id.player_button);
+ playerButton.setEnabled(spkrSupport);
+ playerButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ recorderButton.setEnabled(false);
+ status = Status.PLAYER;
+ play();
+
+ Button okButton = (Button)instruView.findViewById(R.id.ok);
+ okButton.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
- recorderButton.setEnabled(false);
- status = Status.PLAYER;
- play();
- getPassButton().setEnabled(true);
+ instruWindow.dismiss();
+ onInstruScreen = false;
+ if (status == Status.PLAYER) {
+ playerButton.setEnabled(spkrSupport);
+ } else {
+ recorderButton.setEnabled(micSupport);
+ }
+ getPassButton().setEnabled(true);
}
});
+ TextView instruction = (TextView)instruView.findViewById(R.id.instru);
+ instruction.setText(R.string.hifi_ultrasound_speaker_test_test_side);
+ instruWindow.showAtLocation(info, Gravity.CENTER, 0, 0);
+ recorderButton.setEnabled(false);
+ playerButton.setEnabled(false);
+ onInstruScreen = true;
+ }
+ });
+ }
+
+ private void plotResponse(WavAnalyzerTask wavAnalyzerTask) {
+ Button dismissButton = (Button)popupView.findViewById(R.id.dismiss);
+ dismissButton.setOnClickListener(new Button.OnClickListener(){
+ @Override
+ public void onClick(View v) {
+ popupWindow.dismiss();
+ onPlotScreen = false;
+ recorderButton.setEnabled(true);
+ }});
+ popupWindow.showAtLocation(info, Gravity.CENTER, 0, 0);
+ onPlotScreen = true;
+
+ recorderButton.setEnabled(false);
+
+ XYPlot plot = (XYPlot) popupView.findViewById(R.id.responseChart);
+ plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 2000);
+
+ Double[] frequencies = new Double[Common.PIP_NUM];
+ for (int i = 0; i < Common.PIP_NUM; i++) {
+ frequencies[i] = new Double(Common.FREQUENCIES_ORIGINAL[i]);
}
+ if (wavAnalyzerTask != null) {
- private void plotResponse(WavAnalyzerTask wavAnalyzerTask) {
- Button dismissButton = (Button)popupView.findViewById(R.id.dismiss);
- dismissButton.setOnClickListener(new Button.OnClickListener(){
- @Override
- public void onClick(View v) {
- popupWindow.dismiss();
- onPlotScreen = false;
- recorderButton.setEnabled(true);
- }});
- popupWindow.showAtLocation(info, Gravity.CENTER, 0, 0);
- onPlotScreen = true;
-
- recorderButton.setEnabled(false);
-
- XYPlot plot = (XYPlot) popupView.findViewById(R.id.responseChart);
- plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 2000);
-
- Double[] frequencies = new Double[Common.PIP_NUM];
- for (int i = 0; i < Common.PIP_NUM; i++) {
- frequencies[i] = new Double(Common.FREQUENCIES_ORIGINAL[i]);
- }
-
- if (wavAnalyzerTask != null) {
-
- double[][] power = wavAnalyzerTask.getPower();
- for(int i = 0; i < Common.REPETITIONS; i++) {
- Double[] powerWrap = new Double[Common.PIP_NUM];
- for (int j = 0; j < Common.PIP_NUM; j++) {
- powerWrap[j] = new Double(10 * Math.log10(power[j][i]));
- }
- XYSeries series = new SimpleXYSeries(
- Arrays.asList(frequencies),
- Arrays.asList(powerWrap),
- "");
- LineAndPointFormatter seriesFormat = new LineAndPointFormatter();
- seriesFormat.configure(getApplicationContext(),
- R.xml.ultrasound_line_formatter_trials);
- seriesFormat.setPointLabelFormatter(null);
- plot.addSeries(series, seriesFormat);
+ double[][] power = wavAnalyzerTask.getPower();
+ for(int i = 0; i < Common.REPETITIONS; i++) {
+ Double[] powerWrap = new Double[Common.PIP_NUM];
+ for (int j = 0; j < Common.PIP_NUM; j++) {
+ powerWrap[j] = new Double(10 * Math.log10(power[j][i]));
}
-
- double[] noiseDB = wavAnalyzerTask.getNoiseDB();
- Double[] noiseDBWrap = new Double[Common.PIP_NUM];
- for (int i = 0; i < Common.PIP_NUM; i++) {
- noiseDBWrap[i] = new Double(noiseDB[i]);
- }
-
- XYSeries noiseSeries = new SimpleXYSeries(
- Arrays.asList(frequencies),
- Arrays.asList(noiseDBWrap),
- "background noise");
- LineAndPointFormatter noiseSeriesFormat = new LineAndPointFormatter();
- noiseSeriesFormat.configure(getApplicationContext(),
- R.xml.ultrasound_line_formatter_noise);
- noiseSeriesFormat.setPointLabelFormatter(null);
- plot.addSeries(noiseSeries, noiseSeriesFormat);
-
- double[] dB = wavAnalyzerTask.getDB();
- Double[] dBWrap = new Double[Common.PIP_NUM];
- for (int i = 0; i < Common.PIP_NUM; i++) {
- dBWrap[i] = new Double(dB[i]);
- }
-
XYSeries series = new SimpleXYSeries(
Arrays.asList(frequencies),
- Arrays.asList(dBWrap),
- "median");
+ Arrays.asList(powerWrap),
+ "");
LineAndPointFormatter seriesFormat = new LineAndPointFormatter();
seriesFormat.configure(getApplicationContext(),
- R.xml.ultrasound_line_formatter_median);
+ R.xml.ultrasound_line_formatter_trials);
seriesFormat.setPointLabelFormatter(null);
plot.addSeries(series, seriesFormat);
-
- Double[] passX = new Double[] {Common.MIN_FREQUENCY_HZ, Common.MAX_FREQUENCY_HZ};
- Double[] passY = new Double[] {wavAnalyzerTask.getThreshold(), wavAnalyzerTask.getThreshold()};
- XYSeries passSeries = new SimpleXYSeries(
- Arrays.asList(passX), Arrays.asList(passY), "passing");
- LineAndPointFormatter passSeriesFormat = new LineAndPointFormatter();
- passSeriesFormat.configure(getApplicationContext(),
- R.xml.ultrasound_line_formatter_pass);
- passSeriesFormat.setPointLabelFormatter(null);
- plot.addSeries(passSeries, passSeriesFormat);
}
- }
- /**
- * Plays the generated pips.
- */
- private void play() {
- play(SoundGenerator.getInstance().getByte(), Common.PLAYING_SAMPLE_RATE_HZ);
- }
-
- /**
- * Plays the sound data.
- */
- private void play(byte[] data, int sampleRate) {
- if (audioTrack != null) {
- audioTrack.stop();
- audioTrack.release();
+ double[] noiseDB = wavAnalyzerTask.getNoiseDB();
+ Double[] noiseDBWrap = new Double[Common.PIP_NUM];
+ for (int i = 0; i < Common.PIP_NUM; i++) {
+ noiseDBWrap[i] = new Double(noiseDB[i]);
}
- audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
- sampleRate, AudioFormat.CHANNEL_OUT_MONO,
- AudioFormat.ENCODING_PCM_16BIT, Math.max(data.length, AudioTrack.getMinBufferSize(
- sampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT)),
- AudioTrack.MODE_STATIC);
- audioTrack.write(data, 0, data.length);
- audioTrack.play();
+
+ XYSeries noiseSeries = new SimpleXYSeries(
+ Arrays.asList(frequencies),
+ Arrays.asList(noiseDBWrap),
+ "background noise");
+ LineAndPointFormatter noiseSeriesFormat = new LineAndPointFormatter();
+ noiseSeriesFormat.configure(getApplicationContext(),
+ R.xml.ultrasound_line_formatter_noise);
+ noiseSeriesFormat.setPointLabelFormatter(null);
+ plot.addSeries(noiseSeries, noiseSeriesFormat);
+
+ double[] dB = wavAnalyzerTask.getDB();
+ Double[] dBWrap = new Double[Common.PIP_NUM];
+ for (int i = 0; i < Common.PIP_NUM; i++) {
+ dBWrap[i] = new Double(dB[i]);
+ }
+
+ XYSeries series = new SimpleXYSeries(
+ Arrays.asList(frequencies),
+ Arrays.asList(dBWrap),
+ "median");
+ LineAndPointFormatter seriesFormat = new LineAndPointFormatter();
+ seriesFormat.configure(getApplicationContext(),
+ R.xml.ultrasound_line_formatter_median);
+ seriesFormat.setPointLabelFormatter(null);
+ plot.addSeries(series, seriesFormat);
+
+ Double[] passX = new Double[] {Common.MIN_FREQUENCY_HZ, Common.MAX_FREQUENCY_HZ};
+ Double[] passY = new Double[] {wavAnalyzerTask.getThreshold(), wavAnalyzerTask.getThreshold()};
+ XYSeries passSeries = new SimpleXYSeries(
+ Arrays.asList(passX), Arrays.asList(passY), "passing");
+ LineAndPointFormatter passSeriesFormat = new LineAndPointFormatter();
+ passSeriesFormat.configure(getApplicationContext(),
+ R.xml.ultrasound_line_formatter_pass);
+ passSeriesFormat.setPointLabelFormatter(null);
+ plot.addSeries(passSeries, passSeriesFormat);
}
+ }
+
+ /**
+ * Plays the generated pips.
+ */
+ private void play() {
+ play(SoundGenerator.getInstance().getByte(), Common.PLAYING_SAMPLE_RATE_HZ);
+ }
+
+ /**
+ * Plays the sound data.
+ */
+ private void play(byte[] data, int sampleRate) {
+ if (audioTrack != null) {
+ audioTrack.stop();
+ audioTrack.release();
+ }
+ audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
+ sampleRate, AudioFormat.CHANNEL_OUT_MONO,
+ AudioFormat.ENCODING_PCM_16BIT, Math.max(data.length, AudioTrack.getMinBufferSize(
+ sampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT)),
+ AudioTrack.MODE_STATIC);
+ audioTrack.write(data, 0, data.length);
+ audioTrack.play();
+ }
/**
* AsyncTask class for the analyzing.
@@ -354,6 +392,26 @@
info.append(result);
recorderButton.setEnabled(true);
recorderButton.setText(R.string.hifi_ultrasound_test_plot);
+
+ Button okButton = (Button)instruView.findViewById(R.id.ok);
+ okButton.setOnClickListener(new Button.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ instruWindow.dismiss();
+ onInstruScreen = false;
+ if (status == HifiUltrasoundSpeakerTestActivity.Status.PLAYER) {
+ playerButton.setEnabled(spkrSupport);
+ } else {
+ recorderButton.setEnabled(micSupport);
+ }
+ }
+ });
+ TextView instruction = (TextView) instruView.findViewById(R.id.instru);
+ instruction.setText(R.string.hifi_ultrasound_speaker_test_reference_side);
+ instruWindow.showAtLocation(info, Gravity.CENTER, 0, 0);
+ recorderButton.setEnabled(false);
+ playerButton.setEnabled(false);
+ onInstruScreen = true;
}
@Override
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/HifiUltrasoundTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/HifiUltrasoundTestActivity.java
index 690e109..85b3e37 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/HifiUltrasoundTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/HifiUltrasoundTestActivity.java
@@ -43,270 +43,271 @@
public class HifiUltrasoundTestActivity extends PassFailButtons.Activity {
- public enum Status {
- START, RECORDING, DONE, PLAYER
+ public enum Status {
+ START, RECORDING, DONE, PLAYER
+ }
+
+ private static final String TAG = "HifiUltrasoundTestActivity";
+
+ private Status status = Status.START;
+ private boolean onPlotScreen = false;
+ private TextView info;
+ private Button playerButton;
+ private Button recorderButton;
+ private AudioTrack audioTrack;
+ private LayoutInflater layoutInflater;
+ private View popupView;
+ private PopupWindow popupWindow;
+ private boolean micSupport = true;
+ private boolean spkrSupport = true;
+
+ @Override
+ public void onBackPressed () {
+ if (onPlotScreen) {
+ popupWindow.dismiss();
+ onPlotScreen = false;
+ recorderButton.setEnabled(true);
+ } else {
+ super.onBackPressed();
+ }
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.hifi_ultrasound);
+ setInfoResources(R.string.hifi_ultrasound_test, R.string.hifi_ultrasound_test_info, -1);
+ setPassFailButtonClickListeners();
+ getPassButton().setEnabled(false);
+
+ info = (TextView) findViewById(R.id.info_text);
+ info.setMovementMethod(new ScrollingMovementMethod());
+ info.setText(R.string.hifi_ultrasound_test_instruction1);
+
+ AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+ String micSupportString = audioManager.getProperty(
+ AudioManager.PROPERTY_SUPPORT_MIC_NEAR_ULTRASOUND);
+ String spkrSupportString = audioManager.getProperty(
+ AudioManager.PROPERTY_SUPPORT_SPEAKER_NEAR_ULTRASOUND);
+ Log.d(TAG, "PROPERTY_SUPPORT_MIC_NEAR_ULTRASOUND = " + micSupportString);
+ Log.d(TAG, "PROPERTY_SUPPORT_SPEAKER_NEAR_ULTRASOUND = " + spkrSupportString);
+
+ if (micSupportString == null) {
+ micSupportString = "null";
+ }
+ if (spkrSupportString == null) {
+ spkrSupportString = "null";
+ }
+ if (micSupportString.equalsIgnoreCase(getResources().getString(
+ R.string.hifi_ultrasound_test_default_false_string))) {
+ micSupport = false;
+ getPassButton().setEnabled(true);
+ info.append(getResources().getString(R.string.hifi_ultrasound_test_mic_no_support));
+ }
+ if (spkrSupportString.equalsIgnoreCase(getResources().getString(
+ R.string.hifi_ultrasound_test_default_false_string))) {
+ spkrSupport = false;
+ info.append(getResources().getString(R.string.hifi_ultrasound_test_spkr_no_support));
}
- private static final String TAG = "HifiUltrasoundTestActivity";
+ layoutInflater = (LayoutInflater) getBaseContext().getSystemService(
+ LAYOUT_INFLATER_SERVICE);
+ popupView = layoutInflater.inflate(R.layout.hifi_ultrasound_popup, null);
+ popupWindow = new PopupWindow(
+ popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
- private Status status = Status.START;
- private boolean onPlotScreen = false;
- private TextView info;
- private Button playerButton;
- private Button recorderButton;
- private AudioTrack audioTrack;
- private LayoutInflater layoutInflater;
- private View popupView;
- private PopupWindow popupWindow;
- private boolean micSupport = true;
- private boolean spkrSupport = true;
+ final AudioRecordHelper audioRecorder = AudioRecordHelper.getInstance();
+ final int recordRate = audioRecorder.getSampleRate();
- @Override
- public void onBackPressed () {
- if (onPlotScreen) {
- popupWindow.dismiss();
- onPlotScreen = false;
- recorderButton.setEnabled(true);
- } else {
- super.onBackPressed();
- }
- }
+ recorderButton = (Button) findViewById(R.id.recorder_button);
+ recorderButton.setEnabled(micSupport);
+ recorderButton.setOnClickListener(new View.OnClickListener() {
+ private WavAnalyzerTask wavAnalyzerTask = null;
+ private void stopRecording() {
+ audioRecorder.stop();
+ wavAnalyzerTask = new WavAnalyzerTask(audioRecorder.getByte());
+ wavAnalyzerTask.execute();
+ status = Status.DONE;
+ }
+ @Override
+ public void onClick(View v) {
+ switch (status) {
+ case START:
+ info.append("Recording at " + recordRate + "Hz using ");
+ final int source = audioRecorder.getAudioSource();
+ switch (source) {
+ case 1:
+ info.append("MIC");
+ break;
+ case 6:
+ info.append("VOICE_RECOGNITION");
+ break;
+ default:
+ info.append("UNEXPECTED " + source);
+ break;
+ }
+ info.append("\n");
+ status = Status.RECORDING;
+ playerButton.setEnabled(false);
+ recorderButton.setEnabled(false);
+ audioRecorder.start();
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.hifi_ultrasound);
- setInfoResources(R.string.hifi_ultrasound_test, R.string.hifi_ultrasound_test_info, -1);
- setPassFailButtonClickListeners();
- getPassButton().setEnabled(false);
-
- info = (TextView) findViewById(R.id.info_text);
- info.setMovementMethod(new ScrollingMovementMethod());
- info.setText(R.string.hifi_ultrasound_test_instruction1);
-
- AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
- String micSupportString = audioManager.getProperty(
- getResources().getString(R.string.hifi_ultrasound_test_mic_prop));
- String spkrSupportString = audioManager.getProperty(
- getResources().getString(R.string.hifi_ultrasound_test_spkr_prop));
-
- if (micSupportString == null) {
- micSupportString = "null";
- }
- if (spkrSupportString == null) {
- spkrSupportString = "null";
- }
- if (micSupportString.equalsIgnoreCase(getResources().getString(
- R.string.hifi_ultrasound_test_default_false_string))) {
- micSupport = false;
- getPassButton().setEnabled(true);
- info.append(getResources().getString(R.string.hifi_ultrasound_test_mic_no_support));
- }
- if (spkrSupportString.equalsIgnoreCase(getResources().getString(
- R.string.hifi_ultrasound_test_default_false_string))) {
- spkrSupport = false;
- info.append(getResources().getString(R.string.hifi_ultrasound_test_spkr_no_support));
- }
-
- layoutInflater = (LayoutInflater) getBaseContext().getSystemService(
- LAYOUT_INFLATER_SERVICE);
- popupView = layoutInflater.inflate(R.layout.hifi_ultrasound_popup, null);
- popupWindow = new PopupWindow(
- popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
-
- final AudioRecordHelper audioRecorder = AudioRecordHelper.getInstance();
- final int recordRate = audioRecorder.getSampleRate();
-
- recorderButton = (Button) findViewById(R.id.recorder_button);
- recorderButton.setEnabled(micSupport);
- recorderButton.setOnClickListener(new View.OnClickListener() {
- private WavAnalyzerTask wavAnalyzerTask = null;
- private void stopRecording() {
- audioRecorder.stop();
- wavAnalyzerTask = new WavAnalyzerTask(audioRecorder.getByte());
- wavAnalyzerTask.execute();
- status = Status.DONE;
- }
- @Override
- public void onClick(View v) {
- switch (status) {
- case START:
- info.append("Recording at " + recordRate + "Hz using ");
- final int source = audioRecorder.getAudioSource();
- switch (source) {
- case 1:
- info.append("MIC");
- break;
- case 6:
- info.append("VOICE_RECOGNITION");
- break;
- default:
- info.append("UNEXPECTED " + source);
- break;
+ final View finalV = v;
+ new Thread() {
+ @Override
+ public void run() {
+ Double recordingDuration_millis = new Double(1000 * (2.5
+ + Common.PREFIX_LENGTH_S
+ + Common.PAUSE_BEFORE_PREFIX_DURATION_S
+ + Common.PAUSE_AFTER_PREFIX_DURATION_S
+ + Common.PIP_NUM * (Common.PIP_DURATION_S + Common.PAUSE_DURATION_S)
+ * Common.REPETITIONS));
+ Log.d(TAG, "Recording for " + recordingDuration_millis + "ms");
+ try {
+ Thread.sleep(recordingDuration_millis.intValue());
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
}
- info.append("\n");
- status = Status.RECORDING;
- playerButton.setEnabled(false);
- recorderButton.setEnabled(false);
- audioRecorder.start();
-
- final View finalV = v;
- new Thread() {
+ runOnUiThread(new Runnable() {
@Override
public void run() {
- Double recordingDuration_millis = new Double(1000 * (2.5
- + Common.PREFIX_LENGTH_S
- + Common.PAUSE_BEFORE_PREFIX_DURATION_S
- + Common.PAUSE_AFTER_PREFIX_DURATION_S
- + Common.PIP_NUM * (Common.PIP_DURATION_S + Common.PAUSE_DURATION_S)
- * Common.REPETITIONS));
- Log.d(TAG, "Recording for " + recordingDuration_millis + "ms");
- try {
- Thread.sleep(recordingDuration_millis.intValue());
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- stopRecording();
- }
- });
+ stopRecording();
}
- }.start();
+ });
+ }
+ }.start();
- break;
+ break;
- case DONE:
- plotResponse(wavAnalyzerTask);
- break;
+ case DONE:
+ plotResponse(wavAnalyzerTask);
+ break;
- default: break;
- }
- }
- });
+ default: break;
+ }
+ }
+ });
- playerButton = (Button) findViewById(R.id.player_button);
- playerButton.setEnabled(spkrSupport);
- playerButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- recorderButton.setEnabled(false);
- status = Status.PLAYER;
- play();
- }
- });
+ playerButton = (Button) findViewById(R.id.player_button);
+ playerButton.setEnabled(spkrSupport);
+ playerButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ recorderButton.setEnabled(false);
+ status = Status.PLAYER;
+ play();
+ }
+ });
+ }
+
+ private void plotResponse(WavAnalyzerTask wavAnalyzerTask) {
+ Button dismissButton = (Button)popupView.findViewById(R.id.dismiss);
+ dismissButton.setOnClickListener(new Button.OnClickListener(){
+ @Override
+ public void onClick(View v) {
+ popupWindow.dismiss();
+ onPlotScreen = false;
+ recorderButton.setEnabled(true);
+ }});
+ popupWindow.showAtLocation(info, Gravity.CENTER, 0, 0);
+ onPlotScreen = true;
+
+ recorderButton.setEnabled(false);
+
+ XYPlot plot = (XYPlot) popupView.findViewById(R.id.responseChart);
+ plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 2000);
+
+ Double[] frequencies = new Double[Common.PIP_NUM];
+ for (int i = 0; i < Common.PIP_NUM; i++) {
+ frequencies[i] = new Double(Common.FREQUENCIES_ORIGINAL[i]);
}
+ if (wavAnalyzerTask != null) {
- private void plotResponse(WavAnalyzerTask wavAnalyzerTask) {
- Button dismissButton = (Button)popupView.findViewById(R.id.dismiss);
- dismissButton.setOnClickListener(new Button.OnClickListener(){
- @Override
- public void onClick(View v) {
- popupWindow.dismiss();
- onPlotScreen = false;
- recorderButton.setEnabled(true);
- }});
- popupWindow.showAtLocation(info, Gravity.CENTER, 0, 0);
- onPlotScreen = true;
-
- recorderButton.setEnabled(false);
-
- XYPlot plot = (XYPlot) popupView.findViewById(R.id.responseChart);
- plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 2000);
-
- Double[] frequencies = new Double[Common.PIP_NUM];
- for (int i = 0; i < Common.PIP_NUM; i++) {
- frequencies[i] = new Double(Common.FREQUENCIES_ORIGINAL[i]);
- }
-
- if (wavAnalyzerTask != null) {
-
- double[][] power = wavAnalyzerTask.getPower();
- for(int i = 0; i < Common.REPETITIONS; i++) {
- Double[] powerWrap = new Double[Common.PIP_NUM];
- for (int j = 0; j < Common.PIP_NUM; j++) {
- powerWrap[j] = new Double(10 * Math.log10(power[j][i]));
- }
- XYSeries series = new SimpleXYSeries(
- Arrays.asList(frequencies),
- Arrays.asList(powerWrap),
- "");
- LineAndPointFormatter seriesFormat = new LineAndPointFormatter();
- seriesFormat.configure(getApplicationContext(),
- R.xml.ultrasound_line_formatter_trials);
- seriesFormat.setPointLabelFormatter(null);
- plot.addSeries(series, seriesFormat);
+ double[][] power = wavAnalyzerTask.getPower();
+ for(int i = 0; i < Common.REPETITIONS; i++) {
+ Double[] powerWrap = new Double[Common.PIP_NUM];
+ for (int j = 0; j < Common.PIP_NUM; j++) {
+ powerWrap[j] = new Double(10 * Math.log10(power[j][i]));
}
-
- double[] noiseDB = wavAnalyzerTask.getNoiseDB();
- Double[] noiseDBWrap = new Double[Common.PIP_NUM];
- for (int i = 0; i < Common.PIP_NUM; i++) {
- noiseDBWrap[i] = new Double(noiseDB[i]);
- }
-
- XYSeries noiseSeries = new SimpleXYSeries(
- Arrays.asList(frequencies),
- Arrays.asList(noiseDBWrap),
- "background noise");
- LineAndPointFormatter noiseSeriesFormat = new LineAndPointFormatter();
- noiseSeriesFormat.configure(getApplicationContext(),
- R.xml.ultrasound_line_formatter_noise);
- noiseSeriesFormat.setPointLabelFormatter(null);
- plot.addSeries(noiseSeries, noiseSeriesFormat);
-
- double[] dB = wavAnalyzerTask.getDB();
- Double[] dBWrap = new Double[Common.PIP_NUM];
- for (int i = 0; i < Common.PIP_NUM; i++) {
- dBWrap[i] = new Double(dB[i]);
- }
-
XYSeries series = new SimpleXYSeries(
Arrays.asList(frequencies),
- Arrays.asList(dBWrap),
- "median");
+ Arrays.asList(powerWrap),
+ "");
LineAndPointFormatter seriesFormat = new LineAndPointFormatter();
seriesFormat.configure(getApplicationContext(),
- R.xml.ultrasound_line_formatter_median);
+ R.xml.ultrasound_line_formatter_trials);
seriesFormat.setPointLabelFormatter(null);
plot.addSeries(series, seriesFormat);
-
- Double[] passX = new Double[] {Common.MIN_FREQUENCY_HZ, Common.MAX_FREQUENCY_HZ};
- Double[] passY = new Double[] {wavAnalyzerTask.getThreshold(), wavAnalyzerTask.getThreshold()};
- XYSeries passSeries = new SimpleXYSeries(
- Arrays.asList(passX), Arrays.asList(passY), "passing");
- LineAndPointFormatter passSeriesFormat = new LineAndPointFormatter();
- passSeriesFormat.configure(getApplicationContext(),
- R.xml.ultrasound_line_formatter_pass);
- passSeriesFormat.setPointLabelFormatter(null);
- plot.addSeries(passSeries, passSeriesFormat);
}
- }
- /**
- * Plays the generated pips.
- */
- private void play() {
- play(SoundGenerator.getInstance().getByte(), Common.PLAYING_SAMPLE_RATE_HZ);
- }
-
- /**
- * Plays the sound data.
- */
- private void play(byte[] data, int sampleRate) {
- if (audioTrack != null) {
- audioTrack.stop();
- audioTrack.release();
+ double[] noiseDB = wavAnalyzerTask.getNoiseDB();
+ Double[] noiseDBWrap = new Double[Common.PIP_NUM];
+ for (int i = 0; i < Common.PIP_NUM; i++) {
+ noiseDBWrap[i] = new Double(noiseDB[i]);
}
- audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
- sampleRate, AudioFormat.CHANNEL_OUT_MONO,
- AudioFormat.ENCODING_PCM_16BIT, Math.max(data.length, AudioTrack.getMinBufferSize(
- sampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT)),
- AudioTrack.MODE_STATIC);
- audioTrack.write(data, 0, data.length);
- audioTrack.play();
+
+ XYSeries noiseSeries = new SimpleXYSeries(
+ Arrays.asList(frequencies),
+ Arrays.asList(noiseDBWrap),
+ "background noise");
+ LineAndPointFormatter noiseSeriesFormat = new LineAndPointFormatter();
+ noiseSeriesFormat.configure(getApplicationContext(),
+ R.xml.ultrasound_line_formatter_noise);
+ noiseSeriesFormat.setPointLabelFormatter(null);
+ plot.addSeries(noiseSeries, noiseSeriesFormat);
+
+ double[] dB = wavAnalyzerTask.getDB();
+ Double[] dBWrap = new Double[Common.PIP_NUM];
+ for (int i = 0; i < Common.PIP_NUM; i++) {
+ dBWrap[i] = new Double(dB[i]);
+ }
+
+ XYSeries series = new SimpleXYSeries(
+ Arrays.asList(frequencies),
+ Arrays.asList(dBWrap),
+ "median");
+ LineAndPointFormatter seriesFormat = new LineAndPointFormatter();
+ seriesFormat.configure(getApplicationContext(),
+ R.xml.ultrasound_line_formatter_median);
+ seriesFormat.setPointLabelFormatter(null);
+ plot.addSeries(series, seriesFormat);
+
+ Double[] passX = new Double[] {Common.MIN_FREQUENCY_HZ, Common.MAX_FREQUENCY_HZ};
+ Double[] passY = new Double[] {wavAnalyzerTask.getThreshold(), wavAnalyzerTask.getThreshold()};
+ XYSeries passSeries = new SimpleXYSeries(
+ Arrays.asList(passX), Arrays.asList(passY), "passing");
+ LineAndPointFormatter passSeriesFormat = new LineAndPointFormatter();
+ passSeriesFormat.configure(getApplicationContext(),
+ R.xml.ultrasound_line_formatter_pass);
+ passSeriesFormat.setPointLabelFormatter(null);
+ plot.addSeries(passSeries, passSeriesFormat);
}
+ }
+
+ /**
+ * Plays the generated pips.
+ */
+ private void play() {
+ play(SoundGenerator.getInstance().getByte(), Common.PLAYING_SAMPLE_RATE_HZ);
+ }
+
+ /**
+ * Plays the sound data.
+ */
+ private void play(byte[] data, int sampleRate) {
+ if (audioTrack != null) {
+ audioTrack.stop();
+ audioTrack.release();
+ }
+ audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
+ sampleRate, AudioFormat.CHANNEL_OUT_MONO,
+ AudioFormat.ENCODING_PCM_16BIT, Math.max(data.length, AudioTrack.getMinBufferSize(
+ sampleRate, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT)),
+ AudioTrack.MODE_STATIC);
+ audioTrack.write(data, 0, data.length);
+ audioTrack.play();
+ }
/**
* AsyncTask class for the analyzing.