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

In case you have forgotten, a Hashtable object is a data structure that ties keys to values . (Items in a Hashtable are called keys but this is unrelated to the keys on a piano keyboard.) In this case, the keys in the Hashtable are the note names andthe values are the frequency values that are tied to those not names. The program can ask the Hashtable object to provide the frequency for a given note name. Forexample, the piano key commonly known as middle-C is named C4 . The program can ask the Hashtable for the frequency value for the key C4 and the Hashtable will return 261.63 Hz.

Musical instruments must be tuned

I mentioned earlier that I am not a musician and I am clearly not a musical theoretician. What I about to report to you is what I have learned during thepast few weeks while working on this program.

In order for multiple instruments to play and sound well together, they must be tuned using compatible frequencies regardless of the type of instrument.There is a set of six notes or keys, moving from left to right on the piano keyboard, where there is general agreement as to the frequency that should betuned for each piano key:

  • A2 = 110 Hz
  • A3 = 220 Hz
  • A4 = 440 Hz
  • A5 = 880 Hz
  • A6 = 1760 Hz
  • A7 = 3520 Hz

Note that each frequency is double the frequency above it in this list. This doubling in frequency is known as an octave. There is one octave between A2 andA3, one octave between A3 and A4, etc. As you move to the right on the piano keyboard, the frequency doubles between a particular piano key and the next keyto the right with the same name (A, B, C, etc.)

The in-between frequencies

While there appears to be general agreement as to the frequencies that should be assigned to the A keys, there appears to be something less thantotal agreement as to the frequencies for the keys in between. However, I believe that I understand the formula that is often usedto tune the keys on a piano. The frequency for any key is multiplied by a factor that is the twelfth root of two (1.05946309436) to obtain the frequency for the key immediately to its right.

The key sequence from any A-key to the next A-key to the right is as follows:

A, A#, B, C, C#, D, D#, E, F, F#, G, G#, A

If you count the number of keys, there are twelve steps from an A-key to the next A-key to the right. That is one octave, meaning that the frequency mustdouble from any A-key to the next A-key to the right. If you multiply the twelfth root of two by itself twelve times, the result will be two. If you multiply thefrequency of any key by the twelfth root of two to get the frequency for the key to the right, and you do that twelve times, the frequency after twelve stepswill have doubled.

Now that we know what we need to do, let's look at the code that will do it.

Beginning of the getPiano method

The getPiano method begins in Listing 16 . This method creates and returns a reference to a Hashtable object containing the name (key) and frequency (value) of every note from A2 (110 Hz) at the low end to A7 (3520 Hz) at the high end. This 61-note, five-octave range is close to the limits of the frequency range that I can hear on my computer. In fact, I canonly barely hear A2. (Click AllNotes to hear each of the 61 notes played from lowest to highest.)

Questions & Answers

discuss how the following factors such as predation risk, competition and habitat structure influence animal's foraging behavior in essay form
Burnet Reply
location of cervical vertebra
KENNEDY Reply
What are acid
Sheriff Reply
define biology infour way
Happiness Reply
What are types of cell
Nansoh Reply
how can I get this book
Gatyin Reply
what is lump
Chineye Reply
what is cell
Maluak Reply
what is biology
Maluak
what's cornea?
Majak Reply
what are cell
Achol
Explain the following terms . (1) Abiotic factors in an ecosystem
Nomai Reply
Abiotic factors are non living components of ecosystem.These include physical and chemical elements like temperature,light,water,soil,air quality and oxygen etc
Qasim
Define the term Abiotic
Marial
what is biology
daniel Reply
what is diffusion
Emmanuel Reply
passive process of transport of low-molecular weight material according to its concentration gradient
AI-Robot
what is production?
Catherine
hello
Marial
Pathogens and diseases
how did the oxygen help a human being
Achol Reply
how did the nutrition help the plants
Achol Reply
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