<< Chapter < Page | Chapter >> Page > |
I encourage you to copy the code from Listing 9 and Listing 10 . Retrieve the necessary source code for the other three classes from the module titled Jbs2010-Your First Sound Program . Compile the code and execute it. Experiment with the code,making changes, and observing the results of your changes. Make certain that you can explain why your changes behave as they do.
This section contains a variety of miscellaneous information.
Financial : Although the OpenStax CNX site makes it possible for you to download a PDF file for the collection thatcontains this module at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, youshould be aware that some of the HTML elements in this module may not translate well into PDF.
You also need to know that Prof. Baldwin receives no financial compensation from OpenStax CNX even if you purchase the PDF version of the collection.
In the past, unknown individuals have copied Prof. Baldwin's modules from cnx.org, converted them to Kindle books, and placedthem for sale on Amazon.com showing Prof. Baldwin as the author. Prof. Baldwin neither receives compensation for those sales nordoes he know who does receive compensation. If you purchase such a book, please be aware that it is a copy of a collection thatis freely available on OpenStax CNX and that it was made and published without the prior knowledge of Prof.Baldwin.
Affiliation :: Prof. Baldwin is a professor of Computer Information Technology at Austin Community College inAustin, TX.
Complete listings of two of the classes discussed in this module are provided below. Source code for the remaining three classes can be obtained from themodule titled Jbs2010-Your First Sound Program .
Listing 9 . The class named MusicComposer07. |
---|
/*File MusicComposer07.java
Copyright 2014, R.G.BaldwinRevised 08/23/14
This program creates and plays an audio graph of a sinusoid. It works inconjunction with the following classes:
AudioGraphSinusoidalAudioSignalGenerator02
AudioPlayOrFile01AudioFormatParameters01
The sound can be played immediately or can be saved in an audio file oftype AU for playback later. You should be able to play the audio file with any
standard media player that can handle the AU file typeTested using JDK 1.8 under Win 7.
******************************************************************************/public class MusicComposer07{
//Instantiate an object containing audio format parameters with predefined// values. They may be modified by the signal generator at runtime. Values
// allowed by Java SDK 1.4.1 are shown in comments in the class definition.
AudioFormatParameters01 audioParams = new AudioFormatParameters01();//A buffer to hold the audio data that will be played or filed.byte[] melody;//A place to store the incoming args array.String[] args;//-------------------------------------------------------------------------//
//Command-line parameter (only one parameter is needed)//If "play", the sound will be played immediately. Otherwise, the string will
// be used as a filename for an audio file of type AU. In the latter case,// it must be a string that would be valid as a file name for the operating
// system in use.public static void main(String[] args){//Instantiate a new object of this class.
new MusicComposer07(args);}//end main
//-------------------------------------------------------------------------//public MusicComposer07(String[]args){//constructor
//Save the args array.this.args = args;//Create default args data if no args data is provided on the command line.
if(args.length == 0){this.args = new String[1];this.args[0] = "play";//Play the melody immediately}//end if
//Get a populated array containing audio data for white or pink noise.AudioGraphSinusoidal audioGraphSinusoidal =
new AudioGraphSinusoidal(audioParams,this.args,melody);melody = audioGraphSinusoidal.getMelody();
//Play or file the audio datanew AudioPlayOrFile01(audioParams,melody,this.args[0]).playOrFileData();}//end constructor
//-------------------------------------------------------------------------//}//end class MusicComposer07.java |
Notification Switch
Would you like to follow the 'Accessible objected-oriented programming concepts for blind students using java' conversation and receive update notifications?