Home | History | Annotate | Download | only in experiments
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.cts.verifier.audioquality.experiments;
     18 
     19 import com.android.cts.verifier.R;
     20 import com.android.cts.verifier.audioquality.AudioQualityVerifierActivity;
     21 import com.android.cts.verifier.audioquality.Native;
     22 import com.android.cts.verifier.audioquality.Utils;
     23 
     24 import android.content.Context;
     25 
     26 /**
     27  * Experiment to look for excessive DC bias in the recordings.
     28  * It calculates the mean of the observed samples.
     29  */
     30 public class BiasExperiment extends LoopbackExperiment {
     31     private static final float ONSET_THRESH = 10.0f;
     32     private static final float TOLERANCE = 200.0f;
     33 
     34     public BiasExperiment() {
     35         super(true);
     36     }
     37 
     38     @Override
     39     protected String lookupName(Context context) {
     40         return context.getString(R.string.aq_bias_exp);
     41     }
     42 
     43     @Override
     44     protected void compare(byte[] stim, byte[] record) {
     45         short[] pcm = Utils.byteToShortArray(record);
     46         float[] results = mNative.measureRms(pcm, AudioQualityVerifierActivity.SAMPLE_RATE, ONSET_THRESH);
     47         float rms = results[Native.MEASURE_RMS_RMS];
     48         float duration = results[Native.MEASURE_RMS_DURATION];
     49         float mean = results[Native.MEASURE_RMS_MEAN];
     50         if (mean < -TOLERANCE || mean > TOLERANCE) {
     51             setScore(getString(R.string.aq_fail));
     52         } else {
     53             setScore(getString(R.string.aq_pass));
     54         }
     55         setReport(String.format(getString(R.string.aq_bias_report),
     56                 mean, TOLERANCE, rms, duration));
     57     }
     58 }
     59