Question

package harp; /** * A simulated harp string, built using the Karplus-Strong algorithm. Sounds like *...

package harp; /** * A simulated harp string, built using the Karplus-Strong algorithm. Sounds like * a synthesizer from the 80s, because that's what it is. * * You'll need to look at the assignment writeup to implement these methods * correctly. * * @author liberato * */ public class HarpString { private final int SAMPLING_RATE = 44100; private final double DECAY_FACTOR = -0.994; /** * Create a harp string of the given frequency, using a sampling rate of * 44,100 Hz; the string is created silent. */ public HarpString(double frequency) { } /** * Create a harp string whose size and initial values are given by the array. */ public HarpString(double[] init) { } /** * Pluck the string by filling the buffer with white noise. */ public void pluck() { } /** * Advance the string simulation one step by running the Karplus-Strong * algorithm. */ public void tic() { } /** * Return the current frequency sample from the string. */ public double sample() { return 0.0; } /** * Return the number of tics passed since this object was initialized. */ public int time() {

return 0; } }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package harp;

/**
* * A simulated harp string, built using the Karplus-Strong algorithm. Sounds
* like * a synthesizer from the 80s, because that's what it is. * * You'll need
* to look at the assignment writeup to implement these methods * correctly. *
* * @author liberato *
*/
public class HarpString {
   private final int SAMPLING_RATE = 44100;
   private final double DECAY_FACTOR = -0.994;
  
   private double[] harp;
   private int count;
   private int ticCount = 0;

   /**
   * * Create a harp string of the given frequency, using a sampling rate of *
   * 44,100 Hz; the string is created silent.
   */
   public HarpString(double frequency) {
      
       int len = (int)Math.round(SAMPLING_RATE/frequency);
      
   harp = new double[len];
  
   }

   /**
   * * Create a harp string whose size and initial values are given by the array.
   */
   public HarpString(double[] init) {
      
int len = (int)Math.round(SAMPLING_RATE/init.length);
      
   harp = new double[len];
  
   for(int i=0;i<init.length;i++)
       harp[i] = init[i];
   count = init.length;
   }
  

   /** * Pluck the string by filling the buffer with white noise. */

   public void pluck() {
      
       //White noise can be recognised by the value around zero.
      
       if(count>0) {
       for(int i=0;i<count;i++) {
          
           harp[i] = Math.random() - 0.5;
          
       }
       }
   }

   /**
   * * Advance the string simulation one step by running the Karplus-Strong *
   * algorithm.
   */
   public void tic() {
      
       if(count>1) {
       double last = this.harp[count-1];
       double lastButone = this.harp[count-2];
double result = ((last+lastButone)/2)*DECAY_FACTOR;
  
this.harp[count-1] = result;
this.ticCount++;
       }
       else
           System.out.println("Tic cannot be performed due to absence of minimum two elements");
  
   }

   /** * Return the current frequency sample from the string. */
   public double sample() {
       //Returning recently added frequency sample
       return this.harp[count-1];
   }

   /** * Return the number of tics passed since this object was initialized. */
   public int time() {

       return this.ticCount;
   }
}

Feel free to ask any doubts, if you face any difficulty in understanding.

Please upvote the answer if you find it helpful

Add a comment
Know the answer?
Add Answer to:
package harp; /** * A simulated harp string, built using the Karplus-Strong algorithm. Sounds like *...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB....

    Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB. This interface should specify this abstract method: public abstract Product get(String productCode); Modify the ProductDB class so it implements the IProductDB interface. Write the code for the new ‘get’ method. Then remove the getProductByCode method. In the Main class, modify the code so it works with the new ProductDB class. This code should create an instance of the IProductDB interface like this: IProductDB db...

  • //Vehicle.h #pragma once #include<iostream> #include"Warranty.h" #include<string> using namespace std; class Vehicle{ protected:    string make; int year;   ...

    //Vehicle.h #pragma once #include<iostream> #include"Warranty.h" #include<string> using namespace std; class Vehicle{ protected:    string make; int year;    double mpg;    Warranty warranty;    static int numOfVehicles; public:    Vehicle();    Vehicle(string s, int y, double m, Warranty warranty);    Vehicle(Vehicle& v);    ~Vehicle();    string getMake();    int getYear();    double getGasMileage();    void setMake(string s);    void setYear(int y);    void setYear(string y);    void setGasMileage(double m);    void setGasMileage(string m);    void displayVehicle();    static int getNumVehicles();    Warranty getWarranty();    void setWarranty(Warranty& ); }; //Vehicle.cpp #include "Vehicle.h" #include <string> Vehicle::Vehicle() {    make = "unknown";    year =...

  • Copy the program AmusementRide.java to your computer and add your own class that extends class AmusementRide....

    Copy the program AmusementRide.java to your computer and add your own class that extends class AmusementRide. Note: AmusementRide.java contains two classes (class FerrisWheel and class RollerCoaster) that provide examples for the class you must create. Your class must include the following. Implementations for all of the abstract methods defined in abstract class AmusementRide. At least one static class variable and at least one instance variable that are not defined in abstract class AmusementRide. Override the inherited repair() method following the...

  • 1. What is the output when you run printIn()? public static void main(String[] args) { if...

    1. What is the output when you run printIn()? public static void main(String[] args) { if (true) { int num = 1; if (num > 0) { num++; } } int num = 1; addOne(num); num = num - 1 System.out.println(num); } public void addOne(int num) { num = num + 1; } 2. When creating an array for primitive data types, the default values are: a. Numeric type b. Char type c. Boolean type d. String type e. Float...

  • Hi. Could you help me with the code below? I need to validate the code below, using expressions that can carry out the actions or that make appropriate changes to the program’s state, using conditiona...

    Hi. Could you help me with the code below? I need to validate the code below, using expressions that can carry out the actions or that make appropriate changes to the program’s state, using conditional and iterative control structures that repeat actions as needed. The unit measurement is missing from the final output and I need it to offer options to lbs, oz, grams, tbsp, tsp, qt, pt, and gal. & fl. oz. Can this be added? The final output...

  • Objectives Problem solving using arrays and ArrayLists. Abstraction. Overview The diagram below illustrates a banner constructed...

    Objectives Problem solving using arrays and ArrayLists. Abstraction. Overview The diagram below illustrates a banner constructed from block-letters of size 7. Each block-letter is composed of 7 horizontal line-segments of width 7 (spaces included): SOLID                        as in block-letters F, I, U, M, A, S and the blurb RThere are six distinct line-segment types: TRIPLE                      as in block-letter M DOUBLE                   as in block-letters U, M, A LEFT_DOT                as in block-letters F, S CENTER_DOT          as in block-letter...

  • using C++ language!! please help me out with this homework In this exercise, you will have...

    using C++ language!! please help me out with this homework In this exercise, you will have to create from scratch and utilize a class called Student1430. Student 1430 has 4 private member attributes: lastName (string) firstName (string) exams (an integer array of fixed size of 4) average (double) Student1430 also has the following member functions: 1. A default constructor, which sets firstName and lastName to empty strings, and all exams and average to 0. 2. A constructor with 3 parameters:...

  • pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the...

    pls help java ASAP!!!!!!! Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the last assignment by providing the following additional features: (The additional features are listed in bold below) Class Statistics In the class Statistics, create the following static methods (in addition to the instance methods already provided). • A public static method for computing sorted data. • A public static method for computing min value. • A public static method for computing max value. • A...

  • JAVA: Already completed: MyList.java, MyAbstractList.java, MyArrayList.java, MyLinkedLink.java, MyStack.java, MyQueue.java. Need to complete: ReversePoem.java. This program has...

    JAVA: Already completed: MyList.java, MyAbstractList.java, MyArrayList.java, MyLinkedLink.java, MyStack.java, MyQueue.java. Need to complete: ReversePoem.java. This program has you display a pessimistic poem from a list of phrases. Next, this program has you reverse the phrases to find another more optimistic poem. Use the following algorithm. 1.   You are given a list of phrases each ending with a pound sign: ‘#’. 2.   Create a single String object from this list. 3.   Then, split the String of phrases into an array of phrases...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT