<< Chapter < Page
  Accessible objected-oriented     Page 5 / 17
Chapter >> Page >
  • // This is a comment in the text file
  • 1,A3,C4#,E4
  • 4,X
  • 2,A3,C4#,E4
  • 4,X
  • 3,A3,C4#,E4
  • 4,X
  • 4,A3,C4#,E4

Normally, the first character on each line must be a number or a /. Comments must begin in the first column with a forward slash (/).The program will ignore:

  • Comment lines that begin with /
  • Blank lines that result in a string with a zero length
  • Lines that begin with a space

The frequency range extends from A2 (110 Hz) to A7 (3520 Hz). Note, however, that someaudio speakers cannot produce sound at the low or high end of that spectrum. Middle-C (261.63 Hz) is specified as C4.

Shaping the notes

The amplitude versus time of each note is shaped by a scale factor. The amplitude is maximum at the beginning and decays linearly to zero at the end.

Beginning of the PlayerPiano01 class

The class named PlayerPiano01 begins in Listing 5 . Assuming that you have studied the previous modules in this series, there isnothing in Listing 5 that should require an explanation beyond the embedded comments.

Listing 5 . Beginning of the PlayerPiano01 class.
import java.io.*; import java.nio.*;import java.util.*; public class PlayerPiano01 extends AudioSignalGenerator02{//Used to store treble clef notes as a list of arrays.ArrayList trebleClef = null; //Used to store bass clef notes as a list of arrays.ArrayList bassClef = null;//Names of input text files are stored here. String trebleFileName;String bassFileName; //Routine working variablesint trebleLengthInBeats; int bassLengthInBeats;

The constructor for the PlayerPiano01 class

The constructor is shown in Listing 6 . The code in the constructor checks the length of the args array. Depending on the length, it gets and saves the file names for neither, either, or both of the text files that define the melody.

Listing 6 . The constructor for the PlayerPiano01 class.
public PlayerPiano01(AudioFormatParameters01 audioParams, String[]args, byte[]melody){ super(audioParams,args,melody);//Get names of files containing the durations and notes.if(args.length>= 3){ //Required trebleFileNametrebleFileName = args[2];}else{ System.out.println("No trebleFileName provided");}//end elseif(args.length>= 4){ //Optional bassFileNamebassFileName = args[3];}//end if }//end constructor

Beginning of the getMelody method

This program uses the same structure as several programs in previous modules. By now, you should be familiar with that structure. Theoverridden getMelody method, which is inherited from the abstract class name AudioSignalGenerator02 and called from Listing 4 , begins in Listing 7 .

This method returns a melody array that will play piano-like sounds using input musical notation like

A, A#, B, C, C#, D, D# etc.

See Listing 29 for an example of a text file containing the treble clef notes for the Greensleeves melody.

Listing 7 . Beginning of the getMelody method.
byte[] getMelody(){if(bassFileName != null){ //Specify stereo output.audioParams.channels = 2; }else{//Specify mono output. audioParams.channels = 1;//superfluous - same as default}//end else System.out.println("audioParams.channels = " + audioParams.channels);//Controls how fast or slow the notes are played. int beatsPerSec = Integer.parseInt(args[1]);

Questions & Answers

what is mutation
Janga Reply
what is a cell
Sifune Reply
how is urine form
Sifune
what is antagonism?
mahase Reply
classification of plants, gymnosperm features.
Linsy Reply
what is the features of gymnosperm
Linsy
how many types of solid did we have
Samuel Reply
what is an ionic bond
Samuel
What is Atoms
Daprince Reply
what is fallopian tube
Merolyn
what is bladder
Merolyn
what's bulbourethral gland
Eduek Reply
urine is formed in the nephron of the renal medulla in the kidney. It starts from filtration, then selective reabsorption and finally secretion
onuoha Reply
State the evolution relation and relevance between endoplasmic reticulum and cytoskeleton as it relates to cell.
Jeremiah
what is heart
Konadu Reply
how is urine formed in human
Konadu
how is urine formed in human
Rahma
what is the diference between a cavity and a canal
Pelagie Reply
what is the causative agent of malaria
Diamond
malaria is caused by an insect called mosquito.
Naomi
Malaria is cause by female anopheles mosquito
Isaac
Malaria is caused by plasmodium Female anopheles mosquitoe is d carrier
Olalekan
a canal is more needed in a root but a cavity is a bad effect
Commander
what are pathogens
Don Reply
In biology, a pathogen (Greek: πάθος pathos "suffering", "passion" and -γενής -genēs "producer of") in the oldest and broadest sense, is anything that can produce disease. A pathogen may also be referred to as an infectious agent, or simply a germ. The term pathogen came into use in the 1880s.[1][2
Zainab
A virus
Commander
Definition of respiration
Muhsin Reply
respiration is the process in which we breath in oxygen and breath out carbon dioxide
Achor
how are lungs work
Commander
where does digestion begins
Achiri Reply
in the mouth
EZEKIEL
what are the functions of follicle stimulating harmones?
Rashima Reply
stimulates the follicle to release the mature ovum into the oviduct
Davonte
what are the functions of Endocrine and pituitary gland
Chinaza
endocrine secrete hormone and regulate body process
Achor
while pituitary gland is an example of endocrine system and it's found in the Brain
Achor
what's biology?
Egbodo Reply
Biology is the study of living organisms, divided into many specialized field that cover their morphology, physiology,anatomy, behaviour,origin and distribution.
Lisah
biology is the study of life.
Alfreda
Biology is the study of how living organisms live and survive in a specific environment
Sifune
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

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