<< 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

what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
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
Daniel
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
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
Do somebody tell me a best nano engineering book for beginners?
s. Reply
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
s.
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.
Tarell
what is the actual application of fullerenes nowadays?
Damian
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.
Tarell
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.
Virgil
is Bucky paper clear?
CYNTHIA
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.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
SUYASH Reply
for screen printed electrodes ?
SUYASH
What is lattice structure?
s. Reply
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
Sanket Reply
what's the easiest and fastest way to the synthesize AgNP?
Damian Reply
China
Cied
types of nano material
abeetha Reply
I start with an easy one. carbon nanotubes woven into a long filament like a string
Porter
many many of nanotubes
Porter
what is the k.e before it land
Yasmin
what is the function of carbon nanotubes?
Cesar
I'm interested in nanotube
Uday
what is nanomaterials​ and their applications of sensors.
Ramkumar Reply
what is nano technology
Sravani Reply
what is system testing?
AMJAD
preparation of nanomaterial
Victor Reply
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!
QuizOver.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?

Ask