Home | History | Annotate | Download | only in loopback
      1 /*
      2  * Copyright (C) 2015 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 org.drrickorang.loopback;
     18 
     19 
     20 /**
     21  * This class is used to generates different kinds of tones.
     22  */
     23 
     24 public abstract class ToneGeneration {
     25     protected int     mSamplingRate;
     26     protected double  mAmplitude;  // this value should be from 0 to 1.0
     27     protected boolean mIsGlitchEnabled = false; // indicates we are inserting glitches or not
     28 
     29 
     30     public ToneGeneration(int samplingRate) {
     31         mSamplingRate = samplingRate;
     32     }
     33 
     34 
     35     /** Store samples into "tone". Value of samples are from -32768 to 32767. */
     36     public abstract void generateTone(short[] tone, int size);
     37 
     38 
     39     /**
     40      * Store samples into "tone". Value of samples are from -1.0 to 1.0.
     41      * This function is not supposed to be used to create tone that is going to pass
     42      * into AudioTrack.write() as it only takes in float.
     43      */
     44     public abstract void generateTone(double[] tone, int size);
     45 
     46 
     47     /** Reset all the phases to zero. */
     48     public abstract void resetPhases();
     49 
     50 
     51     /**
     52      * Set the value of mIsGlitchEnabled. If mIsGlitchEnabled == true, will insert glitches to
     53      * the generated tone.
     54      */
     55     public void setGlitchEnabled(boolean isGlitchEnabled) {
     56         mIsGlitchEnabled = isGlitchEnabled;
     57     }
     58 
     59     public void setAmplitude(double amplitude) {
     60         mAmplitude = amplitude;
     61     }
     62 
     63 }
     64