[英]convert an arraylist with audio into a .wav file (Java)
here is my problem, someone gave me a function, which, if I understand it well, put some sound samples into an arraylist. 这是我的问题,有人给了我一个功能,如果我对它很了解的话,可以将一些声音样本放到arraylist中。
I'd like to create a .wav file with this audio track, and I really don't know how to do so. 我想用此音轨创建一个.wav文件,但我真的不知道该怎么做。
Here is the code, because maybe I just don't understand it at all... 这是代码,因为也许我根本不了解它。
public class Track {
private ArrayList<Sample> sounds;
private AudioFormat audioFormat;
TargetDataLine targetDataLine;
public Track()
{
this.sounds = new ArrayList <Sample>();
}
/*** Sort the sample on the track by ascending start time ***/
public void sortTrack() {
Collections.sort(sounds);
}
/**
* Add a sample to the track.
* @param fic location to the audio file.
* @param sT set the start time in ms of the sound on the track.
*/
public void addSound(String fic, long sT) {
sounds.add(new Sample(fic, sT));
}
/**
* Delete a sample to the track.
* @param fic location to the audio file.
* @param sT set the start time in ms of the sound on the track.
*/
public void deleteSound(String fic, long sT) {
int i;
for ( i = 0; i < sounds.size() &&(
sounds.get(i).getAudioFile().getName() == fic &&
sounds.get(i).getStartTime() == sT); ++i) {}
if (i < sounds.size()) sounds.remove(i);
}
Here is sample, imported in the code above. 这是示例,在上面的代码中导入。
public Sample (String fileLocation, long sT) {
try{
audioFile = new File(fileLocation);
istream = AudioSystem.getAudioInputStream(audioFile);
format = istream.getFormat();
startTime = sT;
timeLenght = (audioFile.length() / (format.getFrameSize() * format.getFrameRate() )) * 1000;
}
catch (UnsupportedAudioFileException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
In my opinion, this is not a good Java source code simply because there are a lot of useless operation that could be automatized using some specific java tools. 在我看来,这不是一个好的Java源代码,原因仅仅是有很多无用的操作可以使用某些特定的Java工具自动进行处理。
Apparently, you have a huge class which represents a unique track of a specific album; 显然,您有一个庞大的班级,代表特定专辑的独特曲目; the album is, off course, subdivided in distinct samples. 当然,专辑分为不同的样本。 Follows a detailed description of the methods with some tips in order to improve your code: 在对方法进行详细说明后,并附有一些技巧,以改进您的代码:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.