Hi
please help me or I going to kill myself or my supervisor will kill me:eek::eek:
the story is:
I need to read sound file change the data slightly then save this new data either in the same sound file or in other one...
please help me
what I did is:
I read the file and made changes in the data but I am stuck in save these changes:confused::confused::confused:
Code:int totalFramesRead = 0;
File fileIn = new File("/Applications/tada22.wav");
// somePathName is a pre-existing string whose value was
// based on a user selection.
try {
AudioInputStream audioInputStream =
AudioSystem.getAudioInputStream(fileIn);
AudioFileFormat audioFileFormat =
AudioSystem.getAudioFileFormat(fileIn);
int bytesPerFrame =
audioInputStream.getFormat().getFrameSize();
// Set an arbitrary buffer size of 1024 frames.
int numBytes = 1024 * bytesPerFrame;
byte[] audioBytes = new byte[numBytes];
try {
int numBytesRead = 0;
int numFramesRead = 0;
int count=0;
// Try to read numBytes bytes from the file.
while ((numBytesRead =
audioInputStream.read(audioBytes)) != -1) {
// Calculate the number of frames actually read.
numFramesRead = numBytesRead / bytesPerFrame;
totalFramesRead += numFramesRead;
// Here, do something useful with the audio data that's
// now in the audioBytes array...
[COLOR="Red"]for(int x=1;x<numBytes;x+=2)
{
String audio=Byte.toString(audioBytes[x]);
int m=Integer.parseInt(audio);
String audio2=Integer.toBinaryString(m);
if (audio2.charAt(0) == '0') {
String change="0111111111111111";
int q = 0;
int r = 0;
for (int o = change.length(); o >= 1; o--) {
System.out.println("\nq=" + q+"r= "+r);
q += (Integer.parseInt(change.substring(o - 1, o))) * Math.pow(2, r++);
}
audioBytes[x]=(byte)q;
}
}
}[/COLOR]
} catch (Exception ex) {
// Handle the error...
System.out.println("inner try");
}
} catch (Exception e) {
// Handle the error...
System.out.println("outer try");
}
This code I found it in sun webpage ... it store part of the data from the sound file in byte[] audioBytes and then read another part...etc
The read area is the changes to bytes that I did is to make the positive bytes=-1

