hrmm I’ll look into it, but right now I’ve got this working:
import java.io.*;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
public class JMFTest {
public static void main(String[] args) throws Exception {
FileInputStream in = new FileInputStream("test.mp3");
AudioInputStream source = AudioSystem.getAudioInputStream(new BufferedInputStream(in, 1024));
AudioInputStream pcm = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED, source);
File newFile = new File("test.wav");
AudioSystem.write(pcm, AudioFileFormat.Type.WAVE, newFile);
FileInputStream fis = new FileInputStream(newFile);
ByteArrayOutputStream boas = new ByteArrayOutputStream(new Long(newFile.length()).intValue());
byte[] buf = new byte[8 * 1024];
for(int len=0; (len = fis.read(buf)) != -1;)
{
boas.write(buf,0,len);
}
byte[] ba = boas.toByteArray();
for(int i = 44; i < ba.length; i+=2)
{
float value = ((ba[i] & 0xFF) | (ba[i + 1] << 8))/ 32768.0F;
value /= 2.0;
ba[i + 1] = (byte)((int)(value * 32768) >> 8);
ba[i] = (byte)((int)(value * 32768) & 0xFF);
}
System.out.println(ba.length - 44);
File newerFile = new File("test1.wav");
FileOutputStream fos = new FileOutputStream(newerFile);
fos.write(ba);
}
}
right now it halves the volume of the sound file, but only seems to work in the format I want if the mp3 used is in the same format, so I’m looking for a simpler and more consistent way to do this, I’ll look into JLayer, and see if I can find what I’m looking for.