<< Chapter < Page Chapter >> Page >

Then Listing 4 calls the getMelody method and saves the reference that is returned by the method in the instance variable named melody discussed earlier .

Finally, Listing 4 instantiates an object of the AudioPlayOrFile01 class, passing audioParams , melody , and args[0] as parameters, and then calls the method named playOrFileData on that object's reference. Depending on the value of args[0] , this method will either play the sound contained in melody immediately, or write it into an output audio file.

The class named AudioSignalGenerator02

The class named AudioSignalGenerator02 is shown in Listing 15 . This is another class that will probably be used throughout this series of modules on Java sound and which probably won't change, at least for the earlymodules in the series. Therefore, we will only need to discuss it this one time.

Beginning of the class named AudioSignalGenerator02

This is an abstract class that serves as the base class or superclass for several other classes that can be used to create sounds or melodies of different types.

Listing 5 . Beginning of the class named AudioSignalGenerator02.
import java.io.*; import java.nio.*;import java.util.*; public abstract class AudioSignalGenerator02{//Note: This class can only be used to generate signed 16-bit data.ByteBuffer byteBuffer; String[]args; byte[]melody; AudioFormatParameters01 audioParams;//-------------------------------------------------------------------------//

The code in Listing 5 declares four instance variables. You are already familiar with the purpose of three of them. The variable named byteBuffer isn't actually used in the program in this module, but will be used in later modules. I will explain it in the firstmodule in which it is actually used.

The constructor for AudioSignalGenerator02

The constructor is shown in Listing 6 . The constructor simply receives three input parameters and saves them in the instance variables shown in Listing 5 .

Listing 6 . The constructor for AudioSignalGenerator02.
public AudioSignalGenerator02(AudioFormatParameters01 audioParams, String[]args, byte[]melody){ this.audioParams = audioParams;this.args = args; this.melody = melody;}//end constructor //-------------------------------------------------------------------------//

The abstract method named getMelody

Listing 7 shows an abstract method named getMelody . In case you don't remember what an abstract method is, see Ap0100 : Self-assessment, The this keyword, static final variables, and initialization of instance variables .

Briefly, an abstract method is a method that is designed to be overridden. The method named getMelody in Listing 7 must be overridden in a subclass to be of any use. You will see the overridden version of the method named getMelody shortly in the class named WhiteNoise .

Recall that the method was called on a reference to a WhiteNoise object in Listing 4 . (You will get a better idea of the purpose of this abstract method when we discuss runtime polymorphism in a future module.)

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Accessible objected-oriented programming concepts for blind students using java. OpenStax CNX. Sep 01, 2014 Download for free at https://legacy.cnx.org/content/col11349/1.17
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Accessible objected-oriented programming concepts for blind students using java' conversation and receive update notifications?

Ask