Lab 13: Guitar Hero

In this lab, you will implement a simple fixed-length queue structure and use it to simulate a guitar string, then build an application that lets you play a simulated guitar on your keyboard.

Instructions

We encourage you to work with a partner.

First, download guitar-hero.zip, which contains the starter files for this assignment.

Next, visit https://www.cs.princeton.edu/courses/archive/spring18/cos126/assignments/guitar-hero/ and keep a tab for that page around for later use. This is the original GuitarHero assignment description. Be sure that you do not use the zip file from this site - it’s quite old and won’t work correctly.

Next, develop a RingBuffer class with the following methods:

public class RingBuffer {
    public RingBuffer(int capacity)  //  creates an empty ring buffer with the specified capacity
    public int capacity()    //  returns the capacity of this ring buffer
    public int size()        //  returns the number of items currently in this ring buffer
    public boolean isEmpty()  //  is this ring buffer empty (size equals zero)?
    public boolean isFull()   //  is this ring buffer full (size equals capacity)?
    public void enqueue(double x) //  adds item x to the end of this ring buffer
    public double dequeue()       //  deletes and returns the item at the front of this ring buffer
    public double peek()          //  returns the item at the front of this ring buffer

    public static void main(String[] args)   //  tests this class by directly calling all instance method
}

Next, develop a GuitarString class with the following methods:

public class GuitarString {
   public GuitarString(double frequency)  //  creates a guitar string of the specified frequency, using a sampling rate of 44,100
   public GuitarString(double[] init)     //  creates a guitar string whose length and initial values are given by the specified array
   public int length()                        //  returns the number of samples in the ring buffer
   public void pluck()                         //  plucks this guitar string (by replacing the ring buffer with white noise)
   public void tic()                           //  advances the Karplus-Strong simulation one time step
   public double sample()                        //  returns the current sample

   public static void main(String[] args)         //  tests this class by directly calling both constructors and all instance methods
}

At this point, you should be able to compile and run the provided GuitarHeroLite application, which will let you play two simulated strings. We’ll look at this code in class and you’ll want to understand how it’s working.

Finally, implement the GuitarHero application as described at https://www.cs.princeton.edu/courses/archive/spring18/cos126/assignments/guitar-hero/.

Hint: This page at Princeton has a good test of the RingBuffer class already written. https://www.cs.princeton.edu/courses/archive/spring18/cos126/assignments/guitar-hero/checklist.html

Hint: That same page has a bunch of other useful checks you can implement or which have already been implemented.

Submit

Upload the following files to Gradescope:

Also, be sure to indicate your group member on Gradescope.

Learning Goals