Home | History | Annotate | Download | only in audioquality
      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;
     18 
     19 import android.content.Context;
     20 import android.content.res.AssetManager;
     21 import android.util.Log;
     22 
     23 import java.io.IOException;
     24 import java.io.InputStream;
     25 
     26 public class AudioAssets {
     27 
     28     private static final String TAG = "AudioQualityVerifier";
     29 
     30     private static final String STIM_BASENAME = "audioquality/stim_dt_";
     31 
     32     public static byte[] getStim(Context context, int which) {
     33         return readAsset(context, STIM_BASENAME + which);
     34     }
     35 
     36     public static byte[] getPinkNoise(Context context, int ampl, int duration) {
     37         return readAsset(context, "audioquality/pink_" + ampl + "_" + duration + "s");
     38     }
     39 
     40     private static byte[] readAsset(Context context, String filename) {
     41         AssetManager assetManager = context.getAssets();
     42         InputStream ais;
     43         try {
     44             ais = assetManager.open(filename);
     45         } catch (IOException e) {
     46             Log.e(TAG, "Cannot load asset " + filename, e);
     47             return null;
     48         }
     49         byte[] buffer = Utils.readFile(ais);
     50         return buffer;
     51     }
     52 }
     53