<< Chapter < Page
  Accessible objected-oriented     Page 13 / 17
Chapter >> Page >

Listing 22 shows a for loop that is used to compute the amplitude at the current time in the current sample including the possibility oftwo or more keys being pressed. When two or more keys are pressed simultaneously, the amplitude of the output is computed as the sum of theamplitudes of the individual keys. This code shouldn't require an explanation beyond that provided by the embedded comments. Note that the name of the key isused to extract the frequency for that key from the Hashtable object that was created by the method named getPiano that was called in Listing 19 .

Listing 22 . Process each piano key that is pressed.
for(int element = 1;element<array.length;element++){ //Iterate on the piano keys defined in the array.//Get the name of the next key and make sure that it is upper-case. String noteName = array[element].toUpperCase(); try{//Use the noteName and get the corresponding frequency from the // hashtable. Note that results are retrieved from the list as// type Object and must be cast to the correct type. freq = (double)piano.get(noteName);}catch(java.lang.NullPointerException ex){ ex.printStackTrace();System.out.println("noteName: " + noteName); }//end catch//Compute the amplitude for this note at this time and add it to// the sum unless it is a musical rest. if(!noteName.equals("X")){//This is not a musical rest. sum += Math.cos(2*Math.PI*(freq)*time);}//end if //Go back to the top of the loop and get the next key from the// array, if any. }//end for loop

Use a scale factor to shape the note

If you press a key on some electronic keyboards and hold the key down, the sound intensity will remain constant with time. However, if you press a pianokey and hold it down, the sound intensity decreases over time. The code in Listing 23 attempts to achieve that same effect.

Listing 23 . Use a scale factor to shape the note.
scaleFactor = gain*((beats*audioParams.sampleRate/beatsPerSec) - cnt) /(beats*audioParams.sampleRate/beatsPerSec);//Scale the amplitude value and put it into the output array. byteBuffer.putShort((short)(scaleFactor*sum));//Go back and compute the next sample values for this set of keys // until the note duration is satisfied.}//end for loop //Go back, retrieve, and process the next set of keys for a given// duration value. }//end while}//end makeMusic method

At this point in the creation of the audio sample, the amplitude values for all the keys that were pressed simultaneously have been added together.The resulting amplitude value is scaled so that each note has a maximum amplitude at the beginning and a zero amplitude when the duration has expired. Alinear scale factor is used to accomplish this.

The remaining code in Listing 23 shouldn't require an explanation.

Listing 23 ends the for loop that began in Listing 21 , ends the while loop that began in Listing 20 , and signals the end of the makeMusic method.

Questions & Answers

what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
how nano science is used for hydrophobicity
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
what is differents between GO and RGO?
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
How can I make nanorobot?
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
how can I make nanorobot?
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

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?