This is in java. I need to use the chord class within the music class. i collect
ID: 3758438 • Letter: T
Question
This is in java. I need to use the chord class within the music class. i collected the array in muisc and then need to play it. chord class is already written. I need to add on to image two
image 1: (already done)
image 2: this is where i need to add to make the array run through music class and play
Stdaudio here: http://introcs.cs.princeton.edu/java/stdlib/StdAudio.java.html
(stdIn here: http://introcs.cs.princeton.edu/java/stdlib/StdIn.java.html)
package music; import stdlib.StdAudio; public class Chord e public static void playChord (double duration, double. .. frequencies) final int sliceCount = (int) (StdAudio. SAMPLE RATE * duration); final double[l slices new double[sliceCount+1]: for (int i=0; iExplanation / Answer
use inner class concept
make Chord as inner class to PlayMusic class and make it static. call method playChord with the help of class name Chord..
Program
package music;
import stdlib.StdIn;
import stdlib.StdAudio;
public class PlayMusic{ //outer class
public static class Chord{ //inner class
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++){
for(double frequency:frequencies){
slices[i]+=Math.sin(2*Math.PI*i*frequency/StdAudio.SAMPLE_RATE);
}
slices[i]/=frequencies.length;
}
StsAudio.play(slices);
}
}
public static void main(String []ar)
{
StdIn.fromFile("data\painochords.txt");
while(StdIn.hasNextLine())
{
Strign line = StdIn.readLine();
double duration =Double.parseDouble(line);
line=StdIn.readLine();
String [] values=line.split("\s");
double[] frequencies = new double[values.length];
for(int i=0;i<values.length;i++)
{
frequencies[i]=Double.parseDouble(values[i]);
}
}
Chord.playChord(duration,frequencies);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.