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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| import java.awt.*;
import java.applet.*;
import java.io.File;
import java.net.URL;
import javax.sound.sampled.AudioInputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
public class go extends Applet
{
int largeurEcran = 800,hauteurEcran = 600;
Graphics2D g2;
Image Imagecachée;
int bytesPerFrame;
int numBytesRead = 0, nbFrames, numFramesRead = 0;
int numBytes;
byte[] audioBytes, audioBytes2;
AudioFileFormat audioFileFormat,audioFileFormat2;
AudioInputStream audioInputStream ;
public void son()//lecture et stockage des données dans audioBytes[]
{
int totalFramesRead = 0;
File fileIn = new File("tic.wav");
try {
audioFileFormat = AudioSystem.getAudioFileFormat(fileIn);
audioInputStream = AudioSystem.getAudioInputStream(fileIn);
nbFrames = audioFileFormat.getFrameLength();
bytesPerFrame = audioInputStream.getFormat().getFrameSize();
numBytes = nbFrames * bytesPerFrame;
audioBytes = new byte[numBytes];
audioBytes2 = new byte[numBytes*2];
try {
while ((numBytesRead = audioInputStream.read(audioBytes)) != -1)
{
numFramesRead = numBytesRead / bytesPerFrame;
totalFramesRead += numFramesRead;
}
} catch (Exception ex) { }
} catch (Exception e) { }
g2.drawString(""+ audioFileFormat.toString(),0,300);
}
public void modif()// modif à la con des données stockées dans audioBytes[]
{
for(int j=0;j<nbFrames;j++)
{
for(int i=0;i< bytesPerFrame;i++)
{
audioBytes2[i+(2*j+1)* bytesPerFrame]=audioBytes[i+j* bytesPerFrame];
audioBytes2[i+2*j* bytesPerFrame]=audioBytes[i+j* bytesPerFrame];
}
}
}
public void ons() // stockage des données stockées dans audioBytes[] vers le fichier 'test.wav'
{
try {
File out = new File("test.wav");
AudioFormat audioFormat =audioFileFormat.getFormat(),
audioFormat2 = new AudioFormat(audioFormat.getEncoding(),
audioFormat.getSampleRate(),
audioFormat.getSampleSizeInBits()*2, /* à modifier! */
audioFormat.getChannels(),
audioFormat.getFrameSize(),
audioFormat.getFrameRate(),
audioFormat.isBigEndian());
audioInputStream = new AudioInputStream(new ByteArrayInputStream(audioBytes2),
audioFileFormat.getFormat(),
nbFrames*2); /* à modifier! */
AudioSystem.write(audioInputStream,
AudioFileFormat.Type.WAVE,
out);
} catch (Exception e) {System.out.println(e);}
}
public void init()
{
Imagecachée = createImage(largeurEcran,hauteurEcran);
g2 = (Graphics2D)(Imagecachée.getGraphics());
g2.setColor(Color.black);
}
public void paint(Graphics g)
{
g2.clearRect(0,0,largeurEcran,hauteurEcran);
g2.setFont(new Font("Serif", Font.PLAIN, 13));
g2.setColor(Color.black);
son();
modif();
ons();
g.drawImage(Imagecachée,0,0,this);
}
} |