Methods which return 'abstract'

C

ChrisW

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
 
L

Lew

A method doesn't "return 'abstract'". "abstract" is Java's way of saying that
the method is declared but not defined in the given class (the "abstract
class"), and therefore must be defined in the actual subclass that is
instantiated. You cannot instantiate an abstract class (the only kind of
class that can have abstract methods).

This is a fundamental Java concept. You should keep studying the tutorials.

Hunter said:

Read the rest of the tutorials, too.
 
R

Roedy Green

I don't quite understand how to use this method since I don't
understand what the 'abstract' keyword means.

It returns an int, not abstract. You can't use this method directly,
just some the method of the same name and signature that overrides it
and implements it. See http://mindprod.com/jgloss/abstract.html


Quite often only the abstract method is documented and some factory
gives you a class with that method, but that class itself is never
documented, just that it is as subclass of the abstract class
containing the method.
u
 
C

ChrisW

Thanks for the replies. I'll go and try and understand the links
(hopefully they'll make more sense than some of the books I've been
reading). I did do Java at uni, but it got taught so badly (to the
extent that official complaints were made to the head of department)
that not only did I not understand anything that was taught, but since
then, in the last 2 years, I've had to un-teach and re-teach myself
from scratch. I can cope with procedural programming, but without
having anyone to advise me on the OO stuff, I've keep coming to dead-
ends. It's just that this little problem (and Swing, which I think
I'm going to have to try and conquer in the near future) seem to
implicitly require an understanding of OO, in the way that everything
I've done procedurally doesn't.
 
P

Patricia Shanahan

ChrisW said:
Thanks for the replies. I'll go and try and understand the links
(hopefully they'll make more sense than some of the books I've been
reading). I did do Java at uni, but it got taught so badly (to the
extent that official complaints were made to the head of department)
that not only did I not understand anything that was taught, but since
then, in the last 2 years, I've had to un-teach and re-teach myself
from scratch. I can cope with procedural programming, but without
having anyone to advise me on the OO stuff, I've keep coming to dead-
ends. It's just that this little problem (and Swing, which I think
I'm going to have to try and conquer in the near future) seem to
implicitly require an understanding of OO, in the way that everything
I've done procedurally doesn't.

Given your stated background, it may be better to pick one Java book you
like reasonably well, and read it from cover to cover doing the
exercises. Some sections will go fast, because you already have the
procedural aspects. You should still read them, because the author may
be planting ideas and terminology that will help you understand the OO
aspects.

Patricia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top