1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
   | public class Fa {
 
    /**
     * @param args the command line arguments
     */
        public static void play(InputStream source,AudioFormat format){
 
    // 100 ms = 1s/ 10  buffer for real time change to the sound stream
        int bufferSize = format.getFrameSize() * Math.round(format.getSampleRate() / 10);
        byte[] buffer = new byte[bufferSize];
        SourceDataLine line;
        try{
            DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
            line = (SourceDataLine)AudioSystem.getLine(info);
            line.open(format, bufferSize);
        }
        catch (LineUnavailableException e){
            e.printStackTrace();
            return;
        }
        line.start();
        try{
            int numBytesRead = 0;
            while (numBytesRead != -1){
                numBytesRead = source.read(buffer, 0, buffer.length);
                if (numBytesRead != -1)
                    line.write(buffer, 0, numBytesRead);
            }
        }
        catch (IOException e){
            e.printStackTrace();
        }
        line.drain();
        line.close();
    }
 
      // A PARTIR D'ICI JE SAIS COMMENT CA MARCHE :mouarf: ( tout ca en faite me permet de faire joué la note "fa")
 
        public static void playNote(double frequence,double temps){ 
 
        byte son[]=new byte[(int)(22050*temps)];
        AudioFormat form;
        for(int i=0;i<son.length;i++){
            son[i]=(byte)(Math.sin(frequence*2.0*3.14*i/22050.0)*100);
        }
        form=new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,22050,8,1,1,22050,false);
        InputStream stream = new ByteArrayInputStream(son);
    play(stream,form);
 
... | 
Partager