<< Chapter < Page | Chapter >> Page > |
..
Listing 13 . The class named AudioFormatParameters01. |
---|
/*File AudioFormatParameters01.java
Copyright 2014, R.G.BaldwinRevised 08/16/14
******************************************************************************/public class AudioFormatParameters01{
//The following are audio format parameters used by the Java audio system.// They may be modified by the signal generator at runtime. Values allowed
// by Java SDK 1.4.1 are shown in comments.public float sampleRate = 16000.0F;
//Allowable 8000,11025,16000,22050,44100 samples per secondpublic int sampleSizeInBits = 16;
//Allowable 8,16public int channels = 1;
//Allowable 1 for mono and 2 for stereopublic boolean signed = true;
//Allowable true,falsepublic boolean bigEndian = true;//Allowable true,false
}//end class AudioFormatParameters01//===========================================================================// |
..
Listing 14 . The class named MusicComposer04. |
---|
/*File MusicComposer04.java
Copyright 2014, R.G.BaldwinRevised 08/20/14
This program creates and plays three seconds of monaural white or pink noise.It works in conjunction with the following classes:
WhiteNoiseAudioSignalGenerator02
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 MusicComposer04{
//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 MusicComposer04(args);
}//end main//-------------------------------------------------------------------------//public MusicComposer04(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.
WhiteNoise whiteNoise = new WhiteNoise(audioParams,this.args,melody);melody = whiteNoise.getMelody();
//Play or file the audio datanew AudioPlayOrFile01(audioParams,melody,this.args[0]).playOrFileData();}//end constructor
//-------------------------------------------------------------------------//}//end class MusicComposer04.java
//===========================================================================// |
Notification Switch
Would you like to follow the 'Accessible objected-oriented programming concepts for blind students using java' conversation and receive update notifications?