1

Chords.txt 1.0 350.0 440.0 2.0 440 480 4.0 0 0 2.0 440 480 4.0 0 0...

Question

Chords.txt 1.0 350.0 440.0 2.0 440 480 4.0 0 0 2.0 440 480 4.0 0 0...

You are given a file chords.txt where each line contains three double values. The first value is a duration and the second and third values are frequencies. Place this file into the data folder on Eclipse. Once again you are to read values in from a file but you must be careful in doing this as different values mean different things. After you open the file, follow this pseudocode: While not at the end of file for StdIn declare an array of length 2 read the duration for i in the range 0 to 1 read the frequency into the ith frequencies array entry end play the chord end Note that we are now using nested loops. To play a chord, you will need a different method and thats included here: public static void playchord (double duration, double frequencies final int slicecount (int) (StdAudio. SAMPLE RATE duration final double slices new double sliceCount+1 for (int i 0; i slice Count i++) double chord 0.0 for (double frequency frequencies) chord Math.sin (2 Math.PI i frequency StdAudio. SAMPLE RATE) slices [i chord/ frequencies. length. Std Audio play(slices);

Chords.txt

1.0 350.0 440.0

2.0 440 480

4.0 0 0

2.0 440 480

4.0 0 0

2.0 440 480

4.0 0 0

0.5 480 620

0.5 0 0

0.5 480 620

0.5 0 0

0.5 480 620

0.5 0 0

You are given a file chords.txt where each line contains three double values. The first value is a duration and the second and third values are frequencies. Place this file into the data folder on Eclipse. Once again you are to read values in from a file but you must be careful in doing this as different values mean different things. After you open the file, follow this pseudocode: While not at the end of file for StdIn declare an array of length 2 read the duration for i in the range 0 to 1 read the frequency into the ith frequencies array entry end play the chord end Note that we are now using nested loops. To play a chord, you will need a different method and that's included here: public static void playchord (double duration, double frequencies final int slicecount (int) (StdAudio. SAMPLE RATE duration final double slices new double sliceCount+1 for (int i 0; i slice Count i++) double chord 0.0 for (double frequency frequencies) chord Math.sin (2 Math.PI i frequency StdAudio. SAMPLE RATE) slices [i chord/ frequencies. length. Std Audio play(slices);

Answers

// Play.java

package chord; //Please give name of your package

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class Play {

   private static final String FILENAME="D:\\WS17.2\\Sample\\src\\chord\\Chords.txt"; //give the absulate path of //file
  
   public static void playChord(double duration, double[] frequencies)
   {
       final int sliceCount = (int)(StdAudio.SAMPLE_RATE * duration);
       final double[] slices= new double[sliceCount + 1];
       for(int i=0;i<=sliceCount;i++)
       {
           double chord=0.0;
           for(double frequency:frequencies)
           {
               chord += Math.sin(2*Math.PI*i*frequency/StdAudio.SAMPLE_RATE);
           }
           slices[i] = chord/frequencies.length;
       }
       StdAudio.play(slices);
   }
  
   public static void main(String[] args)
   {
       BufferedReader br = null;
       FileReader fr = null;

       try {

           fr = new FileReader(FILENAME);
           br = new BufferedReader(fr);

           String sCurrentLine;

           br = new BufferedReader(new FileReader(FILENAME));
          
           while ((sCurrentLine = br.readLine()) != null) {
               System.out.println(sCurrentLine);
               StringTokenizer st = new StringTokenizer(sCurrentLine, " ");
               double []freq = new double[2];
               double duration = Double.parseDouble(st.nextToken());
               int i=0;
               while(st.hasMoreTokens())
               {
                   freq[i] = Double.parseDouble(st.nextToken());
                   i++;
               }
               playChord(duration,freq);
           }
          


       } catch (IOException e) {

           e.printStackTrace();

       } finally {

           try {

               if (br != null)
                   br.close();

               if (fr != null)
                   fr.close();

           } catch (IOException ex) {

               ex.printStackTrace();

           }

       }
   }
}

//I am assuing you have StdAudio class with you, If you do not have this class please let me know.

//output:

D Play,java Chors.bt StdAudio.java ー ロ| |BE Outline X |围Task List 1 package chord; chord 3e import java.io.BufferedReader: 4


Similar Solved Questions

1 answers
Car rental agency A will rent a compact car for $40 per day and an additional charge of $0.20 per mile
Car rental agency A will rent a compact car for $40 per day and an additional charge of $0.20 per mile. Car rental agency B will charge only $0.16 per mile but charges $51 per day. If Adam wanted to rent a car for four days, how many miles would Adam have to drive to make car rental agency B a bette...
1 answers
Why are vertical and horizontal motion considered independent?
Why are vertical and horizontal motion considered independent?...
1 answers
Gunnar Company gathered the following reconciling information in preparing its September bank reconciliation. Calculate the adjusted...
Gunnar Company gathered the following reconciling information in preparing its September bank reconciliation. Calculate the adjusted cash balance per books on September 30. Cash balance per books, 9/30 $ 2,993 Deposits in transit 408 Notes receivable and interest collected by bank 809 Bank ...
1 answers
QUESTION 7 Suppose the price of a good is €10 and the original spot rate is...
QUESTION 7 Suppose the price of a good is €10 and the original spot rate is $1/€. Suppose the euro strengthens by 5%. The cost of the good in the United States would: Decrease from $10 to $9.50. Increase from $10 to $11. Increase from $10 to $10.50 Decrease from $10 to $9. QUESTION 11 Ain)...
1 answers
I need help writing the matlab code for this! 2. The fourth order differential equation 2.(4)...
i need help writing the matlab code for this! 2. The fourth order differential equation 2.(4) + 3.0" – sin(t)..' + 8x = {2 can be rewritten as the following system of first order equations Ti = 12 = 13 24 = -8.01 + sin(t). 2- 3.03 + t (a) Write an m-file function for the system of dif...
1 answers
) are connected in a wye configuration. 4.. • • 3 impedances (Z = 8 +...
) are connected in a wye configuration. 4.. • • 3 impedances (Z = 8 + j6 Line voltage is 480v. Calculate: Phase current = Line current = 11 11 11 11...
1 answers
13. (11pt) Automobile manufacturers are very interested in improving the average gas mileage of their newer...
13. (11pt) Automobile manufacturers are very interested in improving the average gas mileage of their newer vehicles. One manufacturer knows that for their hybrid model car, the gas mileages are normally distributed with a mean of 32 mpg. The new model of this car is about to ship out, so the manufa...
1 answers
Using HTML and JavaScript. For this assignment you should submit a single zip file that contains...
Using HTML and JavaScript. For this assignment you should submit a single zip file that contains the following two files: index.html script.js index.html should be a skeleton HTML page. So it should have the following tags: doctype html head meta title body script If you were to open index.html with...
1 answers
Sunshine insurance ofers life insurance to men age 80
sunshine insurance ofers life insurance to men age 80...
1 answers
Essentials of Quality Chapter 1 - Exercise 2 (p22) Determine who are the customers for the...
Essentials of Quality Chapter 1 - Exercise 2 (p22) Determine who are the customers for the following and classify the customers internal or external. Manufactured goods that are sold to the wholesaler Higher education Financial statements prepared by the accounting department for use by company man...
1 answers
1. Explain what is meant by the term "free fall." 2. Explain the meaning of each...
1. Explain what is meant by the term "free fall." 2. Explain the meaning of each term in the kinematics equations below: Ax = Vot+at v = v. + at 3. If an object falls from rest, how do the equations in Question 2 simplify? Specify your choice for the positive-y direction....
1 answers
Assume you are the manager of an FI. how would you steucture your balance sheet using the reprici...
assume you are the manager of an FI. how would you steucture your balance sheet using the repricing gap model if you expected i terest rates to increase? why? negative gap or positive gap and why...
1 answers
4. -/8 points OSAtomsChem1 9.3.P.040. D My Notes When 140 mL of 0.206 M NaCl(aq) and...
4. -/8 points OSAtomsChem1 9.3.P.040. D My Notes When 140 mL of 0.206 M NaCl(aq) and 140 mL of 0.206 MAGNO (ag), both at 21.5°C, are mixed in a coffee cup calorimeter, the temperature of the mixture increases to 24.0°C a solid AG forms. NaCl(aq) + AgNO,(0) -- AgCl(s) + NaNO,(aq) This precipi...
1 answers
Answer ASAP with clear work 5) A heat pump that operates on the ideal vapar-compression cycle...
Answer ASAP with clear work 5) A heat pump that operates on the ideal vapar-compression cycle with refrigerant 134a is used to heat water from 15 C to 54 C. with the water mass flow rate of 0.24 kg's. The condenser and344 t evaporator pressures are 1.4 MPa and 0.32 MPa respectively Detcrmi...
1 answers
E. A solution that is 0.255 M in CH3NH2 and 0.135 M in CH3NH2Br (dissociates to...
e. A solution that is 0.255 M in CH3NH2 and 0.135 M in CH3NH2Br (dissociates to CH3NH;)...
1 answers
Electrophilic Addition Mechanisms of 30 > Formation of alcohol from one touch the hydration of the...
Electrophilic Addition Mechanisms of 30 > Formation of alcohol from one touch the hydration of the double bond is the important electrophilic addition on yrion can be accomplished using a variety of reagers Ther m odis hea catalyzed Hydration reaction Look for similares between reaction and the h...

-- 0.049982--