У меня есть большой wav-файл, который я хотел бы разделить на более мелкие фрагменты. У меня также есть файл .cue с длиной частоты кадров, при которой должны быть меньшие фрагменты. Я понял, как разделить wav, но все созданные файлы wav имеют одинаковый звук. Кажется, что каждый раз, когда я создаю новый файл wav, большой файл wav начинается с самого начала и создает новую волну правильной длины, но с тем же звуком.
Я думаю, мне нужен способ прочитать wav в определенный кадр, затем записать в файл, затем продолжить чтение и записать в другой файл и т. д.
Я был в этом в течение нескольких часов и, кажется, не могу понять это. любая помощь будет принята с благодарностью. Вот мой код, все прокомментированные вещи - это мой неправильный код, который я пробовал.
int count2 = 0;
int totalFramesRead = 0;
//cap contains the how many wav's are to be made
//counter contains the vector position.
String wavFile1 = "C:\\Users\\DC3\\Desktop\\wav&text\\testwav.wav";
//String wavFile2 = "C:\\Users\\DC3\\Desktop\\waver\\Battlefield.wav";
while(count2 != counter){
try {
AudioInputStream clip1 = AudioSystem.getAudioInputStream(new File(wavFile1));
int bytesPerFrame = clip1.getFormat().getFrameSize();
//System.out.println(bytesPerFrame);
// int numBytes = safeLongToInt(clip1.getFrameLength()) * bytesPerFrame;
// byte[] audioBytes = new byte[numBytes];
// int numBytesRead = 0;
// int numFramesRead = 0;
// // Try to read numBytes bytes from the file.
// while ((numBytesRead =
// clip1.read(audioBytes)) != -1) {
// // Calculate the number of frames actually read.
// clip1.read(audioBytes)
// numFramesRead = numBytesRead / bytesPerFrame;
// totalFramesRead += numFramesRead;
// System.out.println(totalFramesRead);
// }
long lengthofclip = Integer.parseInt(time.get(count2))- silence;
globallength = clip1.getFrameLength();
AudioInputStream appendedFiles = new AudioInputStream(clip1, clip1.getFormat(), lengthofclip);
//long test = (appendedFiles.getFrameLength() *24 *2)/8;
//int aaaaa = safeLongToInt(test);
//appendedFiles.mark(aaaaa);
AudioSystem.write(appendedFiles,
AudioFileFormat.Type.WAVE,
new File("C:\\Users\\DC3\\Desktop\\wav&text\\" + name.get(count2)));
count2++;
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static int safeLongToInt(long l) {
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
throw new IllegalArgumentException
(l + " cannot be cast to int without changing its value.");
}
return (int) l;
}