Write a Guitar Hero program that uses a queue to simulate the creation of guitar notes. When
Question:
Write a Guitar Hero program that uses a queue to simulate the creation of guitar notes. When a guitar string is plucked, it vibrates to generate sound. The sound starts from the note’s initial note pitch or frequency, then it undergoes a wave-like oscillation and gradually fades in volume over time.
The oscillation and fading of notes can be computed using an algorithm called Karplus-Strong. The algorithm represents sound as time slices called samples (44,100 samples per second, in this case). You can compute samples that sound similar to the vibrations of a real guitar as displacements from the guitar string’s original frequency. First create a queue of random displacements between ½ and ½. The length of the queue should be the sampling rate, 44,100, divided by the note’s frequency. Then repeatedly remove the first queue element, average it with the next front element, slightly fade the volume by multiplying it by 0.996, then add the result back into the queue as shown in Figure 14.3.
This program requires support code to send output to your computer’s sound card. The code is provided on our web site at http://buildingjavaprograms.com/.
Step by Step Answer:
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp