Methods which return 'abstract'
Hi,
I'm trying to use Java Sound to write a new .wav file, so am using
AudioFileWriter, for which the API contains the following information:
public abstract int write(AudioInputStream stream,
AudioFileFormat.Type fileType, OutputStream out)
throws IOException
I don't quite understand how to use this method since I don't
understand what the 'abstract' keyword means. I've looked at the
AudioConcat.java class (and associated SequenceAudioInputStream.java)
from jsresources.org, and tried to write my own class using this
example. The code I've got so far is:
public class makeSound {
private List m_audioInputStreamList;
private int m_nCurrentStream;
public void SequenceAudioInputStream(AudioFormat audioFormat, List
audioInputStreams)
{
super(new ByteArrayInputStream(new byte[0]), audioFormat,
AudioSystem.NOT_SPECIFIED);
m_audioInputStreamList = new ArrayList(audioInputStreams);
m_nCurrentStream = 0;
}
public static void main(String[] args) throws
UnsupportedAudioFileException, IOException {
try {
AudioInputStream ais1 = null;
AudioInputStream ais2 = null;
File file1 = new File("1.wav");
File file2 = new File("2.wav");
AudioFileFormat aff1 = AudioSystem.getAudioFileFormat(file1);
AudioFileFormat aff2 = AudioSystem.getAudioFileFormat(file2);
ais1 = AudioSystem.getAudioInputStream(file1);
ais2 = AudioSystem.getAudioInputStream(file2);
List <AudioInputStream> audioInputStreamList = new ArrayList
<AudioInputStream> ();
audioInputStreamList.add(ais1);
//I hope, that by this point, my List will
contain the Stream of the 1st file
//AudioInputStream audioInputStream =
SequenceAudioInputStream(AudioFileFormat.Type.WAVE,
audioInputStreamList);
//File outputFile = new File("Final.wav");
//AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE,
outputFile);
}
catch (UnsupportedAudioFileException e) {
System.out.println(e);
}
catch (IOException ioe) {
System.out.println(ioe);
}
}
/*
private static File newFile(AudioInputStream currentFileIS, File
completedFile) throws IOException {
File completedFile = new File("Final.wav");
AudioSystem.write(currentFileIS, AudioFileFormat.Type.WAVE,
completedFile);
return AudioSystem;
}
*/
}
I hope that what I am trying to do is relatively obvious. However,
once I've added elements to my List I'm completely lost as to what to
do next - my SequenceAudioInputStream doesn't work and I don't know
what to do to make it work! I know I need to convert my List into an
AudioInputStream. I can't use the program from jsresource as is, as I
need a blank, fixed length audio file onto which I need to put/mix at
fixed intervals the 2 audio files (file1 and file2) (- something I
still need to work out how to do!).
If anyone can point me in the right direction, I'd be most grateful.
Chris