Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package recorderCoba1;
- import java.io.File;
- import javax.swing.*;
- import java.awt.Font;
- import java.awt.event.*;
- public class Starter extends JFrame implements MouseListener{
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- JButton btnStart;
- JButton btnBass;
- JButton btnSnare;
- JButton btnHihat;
- JButton btnTom;
- JButton btnFloorTom;
- JButton btnCrash;
- //JTextField txtInputFile;
- JLabel lblTitle;
- static String path = System.getProperty("user.dir");
- static boolean stop = true;
- static double[] bufferSampleBass = new double[2000]; //buffer
- static double[] bufferSampleSnare = new double[2000];
- static double[] bufferSampleHihat = new double[2000];
- static double[] bufferSampleTom = new double[2000];
- static double[] bufferSampleFloorTom = new double[2000];
- static double[] bufferSampleCrash = new double[2000];
- static double[] bufferRead2 = new double[2000];
- static Complex[] fftSampleBass; //complex hasil fft
- static Complex[] fftSampleSnare;
- static Complex[] fftSampleHihat;
- static Complex[] fftSampleTom;
- static Complex[] fftSampleFloorTom;
- static Complex[] fftSampleCrash;
- public static void main(String args[]){
- Read read = new Read();
- //FFT SAMPLE
- //FFT Sample Bass
- try{
- WavFile sampleBass = WavFile.openWavFile(new File(path+"/RecordAudio2.wav"));
- bufferSampleBass = read.ReadWav(sampleBass);
- }catch(Exception ex){
- }
- Complex[] dataBass = new Complex[2048];
- for (int i = 0; i < 2048; i++) {
- dataBass[i] = new Complex(0.0, 0.0);
- }
- for (int i = 0; i < bufferSampleBass.length; i++) {
- dataBass[i] = new Complex(bufferSampleBass[i], 0.0);
- }
- fftSampleBass = FFT.fft(dataBass);
- //FFT Sample Snare
- try{
- WavFile sampleSnare = WavFile.openWavFile(new File(path+"/RecordAudio2.wav"));
- bufferSampleSnare = read.ReadWav(sampleSnare);
- }catch(Exception ex){
- }
- Complex[] dataSnare = new Complex[2048];
- for (int i = 0; i < 2048; i++) {
- dataSnare[i] = new Complex(0.0, 0.0);
- }
- for (int i = 0; i < bufferSampleSnare.length; i++) {
- dataSnare[i] = new Complex(bufferSampleSnare[i], 0.0);
- }
- fftSampleSnare = FFT.fft(dataSnare);
- //FFT Sample Hihat
- try{
- WavFile sampleHihat = WavFile.openWavFile(new File(path+"/RecordAudio2.wav"));
- bufferSampleHihat = read.ReadWav(sampleHihat);
- }catch(Exception ex){
- }
- Complex[] dataHihat = new Complex[2048];
- for (int i = 0; i < 2048; i++) {
- dataHihat[i] = new Complex(0.0, 0.0);
- }
- for (int i = 0; i < bufferSampleHihat.length; i++) {
- dataHihat[i] = new Complex(bufferSampleHihat[i], 0.0);
- }
- fftSampleSnare = FFT.fft(dataHihat);
- //FFT Sample Tom
- try{
- WavFile sampleTom = WavFile.openWavFile(new File(path+"/RecordAudio2.wav"));
- bufferSampleTom = read.ReadWav(sampleTom);
- }catch(Exception ex){
- }
- Complex[] dataTom = new Complex[2048];
- for (int i = 0; i < 2048; i++) {
- dataTom[i] = new Complex(0.0, 0.0);
- }
- for (int i = 0; i < bufferSampleTom.length; i++) {
- dataTom[i] = new Complex(bufferSampleTom[i], 0.0);
- }
- fftSampleTom = FFT.fft(dataTom);
- //FFT Sample Floor Tom
- try{
- WavFile sampleFloorTom = WavFile.openWavFile(new File(path+"/RecordAudio2.wav"));
- bufferSampleFloorTom = read.ReadWav(sampleFloorTom);
- }catch(Exception ex){
- }
- Complex[] dataFloorTom = new Complex[2048];
- for (int i = 0; i < 2048; i++) {
- dataFloorTom[i] = new Complex(0.0, 0.0);
- }
- for (int i = 0; i < bufferSampleFloorTom.length; i++) {
- dataFloorTom[i] = new Complex(bufferSampleFloorTom[i], 0.0);
- }
- fftSampleFloorTom = FFT.fft(dataFloorTom);
- //FFT Sample Crash
- try{
- WavFile sampleCrash = WavFile.openWavFile(new File(path+"/RecordAudio2.wav"));
- bufferSampleCrash = read.ReadWav(sampleCrash);
- }catch(Exception ex){
- }
- Complex[] dataCrash = new Complex[2048];
- for (int i = 0; i < 2048; i++) {
- dataCrash[i] = new Complex(0.0, 0.0);
- }
- for (int i = 0; i < bufferSampleCrash.length; i++) {
- dataCrash[i] = new Complex(bufferSampleCrash[i], 0.0);
- }
- fftSampleCrash = FFT.fft(dataCrash);
- //=================================================================
- new Starter(); //GUI
- run();
- }
- public static void run(){
- Read read = new Read();
- final JavaSoundRecorder recorder = new JavaSoundRecorder();
- // creates a new thread that waits for a specified
- // of time before stopping
- //long startTime = System.currentTimeMillis();
- //do{
- Thread stopper = new Thread(new Runnable() {
- public void run() {
- try {
- Thread.sleep(300);
- } catch (InterruptedException ex) {
- ex.printStackTrace();
- }
- recorder.finish();
- }
- });
- stopper.start();
- // start recording
- recorder.start("input");
- try{
- WavFile wavFile2 = WavFile.openWavFile(new File(path+"/input.wav"));
- bufferRead2 = read.ReadWav(wavFile2);
- Complex[] data2 = new Complex[2048];
- for (int i = 0; i < 2048; i++) {
- data2[i] = new Complex(0.0, 0.0);
- }
- for (int i = 0; i < bufferRead2.length; i++) {
- data2[i] = new Complex(bufferRead2[i], 0.0);
- }
- Complex[] fftResult2 = FFT.fft(data2);
- boolean compareResult = Compare.compare(fftSampleBass, fftResult2);
- compareResult = Compare.compare(fftSampleSnare, fftResult2);
- compareResult = Compare.compare(fftSampleHihat, fftResult2);
- compareResult = Compare.compare(fftSampleTom, fftResult2);
- compareResult = Compare.compare(fftSampleFloorTom, fftResult2);
- compareResult = Compare.compare(fftSampleCrash, fftResult2);
- //boolean compareResult = Compare.compare2(bufferRead, bufferRead2);
- //AudioPlayerExample2 ape = new AudioPlayerExample2();
- if(compareResult) System.out.println("True"); //ape.play(path+"/bass.wav");
- else System.out.println("False");
- //FFT.show(fftResult, "Hasil FFT");
- }
- catch(Exception ex){
- System.err.println(ex);
- }
- //}while(!stop);
- }
- public void mousePressed(MouseEvent e)
- {
- // when the user clicks the Play button
- if( e.getSource() == btnStart )
- {
- if(stop==true){
- stop=false;
- }
- else
- stop=true;
- System.out.println(stop);
- //long endTime = System.currentTimeMillis();
- //long totalTime = endTime - startTime;
- //System.out.println(totalTime);
- /*wavIO wavFile = new wavIO(txtInputFile.getText());
- if( wavFile.read() == true )
- {
- lblOutput.setText(wavFile.getSummary());
- // now save the file
- wavFile.setPath("testout.wav");
- wavFile.save();
- }
- else
- {
- lblOutput.setText("Error!");
- }*/
- }
- }
- public void mouseReleased(MouseEvent e) {}
- public void mouseClicked(MouseEvent e) {}
- public void mouseEntered(MouseEvent e) {}
- public void mouseExited(MouseEvent e) {}
- public Starter()
- {
- setLayout(null); // tell java not to organize our controls automatically
- /*txtInputFile = new JTextField("test.wav");
- txtInputFile.setBounds(0, 0, 200,20);
- getContentPane().add(txtInputFile);*/
- lblTitle = new JLabel("Table Drum");
- lblTitle.setFont(new Font("Courier New", Font.BOLD, 32));
- lblTitle.setBounds(325, 10, 300, 100);
- getContentPane().add(lblTitle);
- btnStart = new JButton("Start");
- btnStart.setBounds(270, 100, 300, 100);
- btnStart.addMouseListener(this);
- getContentPane().add(btnStart);
- btnBass = new JButton("Bass");
- btnBass.setBounds(100, 250, 200, 200);
- btnBass.addMouseListener(this);
- getContentPane().add(btnBass);
- btnSnare = new JButton("Snare");
- btnSnare.setBounds(320, 250, 200, 200);
- btnSnare.addMouseListener(this);
- getContentPane().add(btnSnare);
- btnHihat = new JButton("Hi Hat");
- btnHihat.setBounds(540, 250, 200, 200);
- btnHihat.addMouseListener(this);
- getContentPane().add(btnHihat);
- btnTom = new JButton("Tom");
- btnTom.setBounds(100, 470, 200, 200);
- btnTom.addMouseListener(this);
- getContentPane().add(btnTom);
- btnFloorTom = new JButton("Floor Tom");
- btnFloorTom.setBounds(320, 470, 200, 200);
- btnFloorTom.addMouseListener(this);
- getContentPane().add(btnFloorTom);
- btnCrash = new JButton("Crash");
- btnCrash.setBounds(540, 470, 200, 200);
- btnCrash.addMouseListener(this);
- getContentPane().add(btnCrash);
- // show the application window
- setTitle("Table Drum");
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- setSize(840,750);
- setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement