Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. import java.io.*;
  2. import java.lang.Math;
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. import static java.lang.Math.log;
  7.  
  8. public class WavClass {
  9.     public static double lg(double x) {
  10.         return Math.log(x)/Math.log(2.0);
  11.     }
  12.     public static void main(String []args){
  13.         int N=0;
  14.         FFT fft;
  15.         double[] window;
  16.         double[] re;
  17.         double[] im;
  18.         try {
  19.             String path = new String();
  20.             Scanner in = new Scanner(System.in);
  21.             System.out.println("Input wav file path ");
  22.             path = in.nextLine();
  23.             File f = new File(path);
  24.             WavFile wf = WavFile.openWavFile(f);
  25.             int numChannels = wf.getNumChannels();
  26.             N = 1024*numChannels;
  27.             fft = new FFT(N);
  28.             int counter = 0;
  29.             window = fft.getWindow();
  30.             int[] buffer = new int[N];
  31.             ArrayList<Double> a = new ArrayList<>();
  32.             int framesRead;
  33.             do{
  34.                 framesRead = wf.readFrames(buffer, 1024);
  35.                 for(int j=0;j<N;j++)
  36.                     a.add(Math.abs((double) buffer[j]));
  37.             }
  38.             while (framesRead != 0);
  39.             System.out.print("aSize= "+a.size());
  40.             re = new double[a.size()];
  41.             im = new double[1];
  42.             System.out.print("Comleted");
  43.             System.exit(0);
  44.             fft.fft(re,im);
  45.             System.out.println("After FFT: ");
  46.             for(int i=0; i<a.size(); i++) {
  47.                 System.out.println("real: "+re[i]);
  48.             }
  49.         }
  50.         catch (Exception e){
  51.             System.out.println("Some shit happened..." + e);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement