1 /* 2 * Copyright (C) 2016 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 import android.app.Activity; 20 import android.os.Bundle; 21 import android.util.Log; 22 import android.view.View; 23 import android.widget.TextView; 24 25 26 /** 27 * Creates a list of time intervals where glitches occurred. 28 */ 29 30 public class GlitchesStringBuilder { 31 private static final String TAG = "GlitchesStringBuilder"; 32 33 34 public static String getGlitchString(int fftsamplingsize, int FFTOverlapSamples, 35 int[] glitchesData, int samplingRate, 36 boolean glitchingIntervalTooLong, int numberOfGlitches) { 37 int newSamplesPerFFT = fftsamplingsize - FFTOverlapSamples; 38 39 // the time span of new samples for a single FFT in ms 40 double newSamplesInMs = ((double) newSamplesPerFFT / samplingRate) * 41 Constant.MILLIS_PER_SECOND; 42 log("newSamplesInMs: " + Double.toString(newSamplesInMs)); 43 44 // the time span of all samples for a single FFT in ms 45 double allSamplesInMs = ((double) fftsamplingsize / samplingRate) * 46 Constant.MILLIS_PER_SECOND; 47 log("allSamplesInMs: " + Double.toString(allSamplesInMs)); 48 49 StringBuilder listOfGlitches = new StringBuilder(); 50 listOfGlitches.append("Total Glitching Interval too long: " + 51 glitchingIntervalTooLong + "\n"); 52 listOfGlitches.append("Estimated number of glitches: " + numberOfGlitches + "\n"); 53 listOfGlitches.append("List of glitching intervals: \n"); 54 55 for (int i = 0; i < glitchesData.length; i++) { 56 int timeInMs; // starting time of glitches 57 //append the time of glitches to "listOfGlitches" 58 timeInMs = (int) (glitchesData[i] * newSamplesInMs); // round down 59 listOfGlitches.append(timeInMs + "~" + (timeInMs + (int) allSamplesInMs) + "ms\n"); 60 } 61 62 return listOfGlitches.toString(); 63 } 64 65 /** Generate String of Glitch Times in ms return separated. */ 66 public static String getGlitchStringForFile(int fftSamplingSize, int FFTOverlapSamples, 67 int[] glitchesData, int samplingRate) { 68 int newSamplesPerFFT = fftSamplingSize - FFTOverlapSamples; 69 70 // the time span of new samples for a single FFT in ms 71 double newSamplesInMs = ((double) newSamplesPerFFT / samplingRate) * 72 Constant.MILLIS_PER_SECOND; 73 74 StringBuilder listOfGlitches = new StringBuilder(); 75 76 for (int i = 0; i < glitchesData.length; i++) { 77 int timeInMs; // starting time of glitches 78 //append the time of glitches to "listOfGlitches" 79 timeInMs = (int) (glitchesData[i] * newSamplesInMs); // round down 80 listOfGlitches.append(timeInMs + "\n"); 81 } 82 83 return listOfGlitches.toString(); 84 } 85 86 /** Generate array of Glitch Times in ms */ 87 public static int[] getGlitchMilliseconds(int fftSamplingSize, int FFTOverlapSamples, 88 int[] glitchesData, int samplingRate) { 89 int[] glitchMilliseconds = new int[glitchesData.length]; 90 int newSamplesPerFFT = fftSamplingSize - FFTOverlapSamples; 91 92 // the time span of new samples for a single FFT in ms 93 double newSamplesInMs = ((double) newSamplesPerFFT / samplingRate) * 94 Constant.MILLIS_PER_SECOND; 95 96 for (int i = 0; i < glitchesData.length; i++) { 97 glitchMilliseconds[i] = (int) (glitchesData[i] * newSamplesInMs); // round down 98 } 99 100 return glitchMilliseconds; 101 } 102 103 private static void log(String msg) { 104 Log.v(TAG, msg); 105 } 106 107 } 108