现在我试图将示例wav文件放入byte [],然后再将byte []导回到wav文件。
我成功了但是当我尝试连接byte []以使wav文件更长时,结果与concat之前的结果相同。
我尝试过1次打鼓输入(2秒),我试图获得2次打鼓但结果仍然是1次打鼓,2秒。
这里主要是混合&将byte []转换为wav
xmlns:app2="http://schemas.android.com/apk/res-auto"
这里是将wav转换为byte []
的类import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
import Samples.Percussion;
public class Main {
public static Percussion snareWet;
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Instrument Type");
String type = sc.nextLine();
try {
snareWet = new Percussion(type);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("BPM");
String bpm = sc.nextLine();
System.out.println("Instrument : "+type+" BPM : " + bpm);
byte[] song;
song = concat(snareWet.getAudioBytes(),snareWet.getAudioBytes());
AudioInputStream oAIS = null;
ByteArrayInputStream oInstream = new ByteArrayInputStream(song);
try {
oAIS = AudioSystem.getAudioInputStream(oInstream);
} catch (UnsupportedAudioFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
File out = new File("result/testDouble.wav");
AudioSystem.write(oAIS,AudioFileFormat.Type.WAVE,out);
}
public static byte[] concat(byte[] a, byte[] b) {
int aLen = a.length;
int bLen = b.length;
byte[] c= new byte[aLen+bLen];
System.arraycopy(a, 0, c, 0, aLen);
System.arraycopy(b, 0, c, aLen, bLen);
return c;
}
}