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.Utils;
     21 
     22 import android.content.Context;
     23 
     24 /**
     25  * An extension to LoopbackExperiment, in which the "playback and record"
     26  * cycle is repeated several times. A family of stimuli is defined, and
     27  * the experiment outcome may depend on the whole sequence of recordings.
     28  */
     29 public class SequenceExperiment extends LoopbackExperiment {
     30     public SequenceExperiment(boolean enable) {
     31         super(enable);
     32     }
     33 
     34     protected int getTrials() {
     35         return 1;
     36     }
     37 
     38     protected byte[] getStim(Context context, int trial) {
     39         int stimNum = 2;
     40         byte[] data = Utils.getStim(context, stimNum);
     41         return data;
     42     }
     43 
     44     protected void compare(byte[][] stim, byte[][] record) {
     45         setScore(getString(R.string.aq_complete));
     46         setReport(getString(R.string.aq_loopback_report));
     47     }
     48 
     49     @Override
     50     public void run() {
     51         int n = getTrials();
     52         byte[][] playbackData = new byte[n][];
     53         byte[][] recordedData = new byte[n][];
     54         for (int trial = 0; trial < n; trial++) {
     55             playbackData[trial] = getStim(mContext, trial);
     56             recordedData[trial] = loopback(playbackData[trial]);
     57             setRecording(recordedData[trial], trial);
     58         }
     59         compare(playbackData, recordedData);
     60         mTerminator.terminate(false);
     61     }
     62 
     63     @Override
     64     public int getTimeout() {
     65         return TIMEOUT * getTrials();
     66     }
     67 }
     68