/* * Projecte Fressa a JAVA * EntradaDeSo.java * Created on 26 / desembre / 2008, 11:10 * * @author Jordi Lagares Roset "jlagares@xtec.cat - www.lagares.org" * amb el suport del Departament d'Educacio de la Generalitat de Catalunya * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details (see the LICENSE file). */ import javax.sound.sampled.*; import java.awt.*; import java.awt.event.*; public class EntradaDeSo { AudioFormat audioFormat; TargetDataLine targetDataLine; AudioInputStream audioInputStream; SourceDataLine sourceDataLine; public boolean stopCapture = false; public int TamanyBuffer=512; public int channels = 1; //1,2 public byte tempBuffer[] = new byte[TamanyBuffer*2]; public int MimimSo = 32; public boolean SHaPassatElMinim=false; public EntradaDeSo() { IniciarDades(); } public void IniciarDades() { int i=0; while (i 0){ if (channels==1) { i=1; while (imaximL) { maximL=tempBuffer[i]; } i=i+1; } if (maximL>MimimSo) { if (SHaPassatElMinim==false) { try { Robot r = new Robot(); r.mousePress(InputEvent.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); } catch (AWTException e) { e.printStackTrace(); } } SHaPassatElMinim=true; } else { SHaPassatElMinim=false; } } else { i=1; while (imaximL) { maximL=tempBuffer[i]; } i=i+2; } i=2; while (imaximR) { maximR=tempBuffer[i]; } i=i+2; } if ((maximL>MimimSo) || (maximR>MimimSo)) { if (SHaPassatElMinim==false) { if (maximL>MimimSo) { try { Robot r = new Robot(); r.mousePress(InputEvent.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); } catch (AWTException e) { e.printStackTrace(); } } else if (maximR>MimimSo) { Llengua.plaphoons.CanviLlocEscaneig(); } } SHaPassatElMinim=true; } else { SHaPassatElMinim=false; } } String s=String.valueOf(maximL)+" | "+String.valueOf(maximR); //Llengua.plaphoons.setTitle(s); } } }catch (Exception e) { System.out.println(e); //System.exit(0); } } } }