[英]convert an arraylist with audio into a .wav file (Java)
这是我的问题,有人给了我一个功能,如果我对它很了解的话,可以将一些声音样本放到arraylist中。
我想用此音轨创建一个.wav文件,但我真的不知道该怎么做。
这是代码,因为也许我根本不了解它。
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);
}
这是示例,在上面的代码中导入。
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();
}
}
在我看来,这不是一个好的Java源代码,原因仅仅是有很多无用的操作可以使用某些特定的Java工具自动进行处理。
显然,您有一个庞大的班级,代表特定专辑的独特曲目; 当然,专辑分为不同的样本。 在对方法进行详细说明后,并附有一些技巧,以改进您的代码:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.