

public class Piano implements Runnable
{
                double dt = 1.0/(double)sr;
     protected ScheduledExecutorService schedExecService;  
  
     private int geschrieben = buffsize;
     public Piano()     
     {
        schedExecService = Executors.newSingleThreadScheduledExecutor();
        long period = (buffsize*1000)/sr; //Seconds per Beat==60/BPM, die Hälfte weil 8tel, mal 1000 weil Millisekunden.
        schedExecService.scheduleAtFixedRate(this, 0, period, TimeUnit.MILLISECONDS);                
     }
    
     public void run()
     {
                for(int i=0;i<buffsize;i++)
                {
                      puffer[i*2+0] = (short)(32000.0*Math.sin(2.0*Math.PI*440.0*t));
                      puffer[i*2+1] = (short)(32000.0*Math.sin(2.0*Math.PI*770.0*t));
                      t+=dt;
                }
          
                int geschrieben = audioTrack.write(puffer, 0,buffsize*2);
                GESCHRIEBEN = geschrieben;
     }
}
