<< Chapter < Page Chapter >> Page >

Map the sinusoidal function values into pulse frequencies

Listing 5 begins with a for loop that eventually deposits audio outputvalues in the melody array.

Listing 5 . Map the sinusoidal function values into pulse frequencies.
for(int cnt = 0; cnt<sampLength; cnt++){ //Compute the time in seconds for this sample.double time = cnt/audioParams.sampleRate;if(cnt%pulseLengthInSamples == 0){ //Time to create a new pulse at a different pitch. Compute the// frequency for the next pulse to represent a point on a sinusoidal // function of time. This section of code could easily be modified// to create audio graphs of many different functions.//Evaluate and scale the function double val = 0.35 * Math.sin(2*Math.PI*0.5*time);//Compute the frequency for the next pulse as a deviation from the// center frequency. For this scaled sinusoidal function, the Range // is from 0.65*centerFreq to 1.35*centerFreq or from 170.05 Hz// to 353.2 Hz. freq = (1+val)*centerFreq;}//end if

Compute the current time

The code inside the for loop in Listing 5 begins by computing the time in secondsfor the current sample. This value will be used later to evaluate the sinusoidal function that is being graphed using audio. It will also be used to compute thevalues of the higher-frequency sinusoids used to control the pitch of the pulses.

Compute the pitch of the pulse

An if statement is used with the modulus operator to cause the pitch to change from one pulse to the next. The code inside the if statement computes the amplitude of the sinusoidal function being graphed at thecurrent point in time. This value will range from -1.0 to +1.0 for a sinusoidal function, but the range may be different if you apply this approach to otherfunctions such as a parabola. It then uses that amplitude value to compute the required pitch of the pulse, at, above, or below the center frequency torepresent the amplitude of the sinusoidal function at, above, or below 0.0. The new pitch value is stored in the variable named freq .

Shape the pulse amplitude from beginning to end

When I first wrote this program, I noticed there were a lot of pops and clicks as the pulse frequency changed abruptly from one pulse to the next. Toeliminate that problem, I applied a shaping scale factor to the amplitude of each pulse to cause it to:

  • Start at zero at the beginning of the pulse.
  • Increase linearly to a maximum value at the center of the pulse.
  • Decrease linearly back to zero at the end of the pulse.

This is accomplished using the gain factor that is computed in Listing 6 . The gain factor ranges from 0.0 at the ends to 1.0 in the center of the pulse. I will leave it as an exercise for the student todecipher this code. (Hint: It would help to know the equation for a straight line.)

Listing 6 . Shape the pulse amplitude from beginning to end.
gain = (cnt%pulseLengthInSamples)/(double)pulseLengthInSamples;if(gain>0.5){ //Change to a negative slope.gain = (pulseLengthInSamples - cnt%pulseLengthInSamples)/(double)pulseLengthInSamples;}//end if //Set the gain to a value that is compatible with 16-bit audio data.gain = 8000*gain;

Questions & Answers

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
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
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.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Do you know which machine is used to that process?
how to fabricate graphene ink ?
for screen printed electrodes ?
What is lattice structure?
s. Reply
of graphene you mean?
or in general
in general
Graphene has a hexagonal structure
On having this app for quite a bit time, Haven't realised there's a chat room in it.
what is biological synthesis of nanoparticles
Sanket Reply
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?